Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

Commit 2b9f10f

Browse files
committed
gps: export content of git submodules
The "git checkout-index" command is unaware of git submodules, therefore their content was missed when exporting files. With "git submodule foreach" the same operation (read-tree + checkout-index) can also be done for all submodules, recursively. The downside is that "foreach" invokes a shell command with certain variables set. To achieve the desired functionality, we have to rely on POSIX shell support.
1 parent 1208520 commit 2b9f10f

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ IMPROVEMENTS:
1818
* Reduce network access by trusting local source information and only pulling from upstream when necessary ([#1250](https://github.com/golang/dep/pull/1250)).
1919
* Update our dependency on Masterminds/semver to follow upstream again now that [Masterminds/semver#67](https://github.com/Masterminds/semver/pull/67) is merged([#1792](https://github.com/golang/dep/pull/1792)).
2020
* Don't exclude `Godeps` folder ([#1822](https://github.com/golang/dep/issues/1822)).
21+
* Export the content of git submodules to the vendor directory ([#1909](https://github.com/golang/dep/pull/1909)).
2122

2223
WIP:
2324
* Enable importing external configuration from dependencies during init (#1277). This is feature flagged and disabled by default.

gps/vcs_source.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,18 @@ func (s *gitSource) exportRevisionTo(ctx context.Context, rev Revision, to strin
203203
}
204204
}
205205

206+
// Now do the same for any submodule, using a shell command that "git submodule"
207+
// iterates over.
208+
{
209+
cmd := commandContext(ctx, "git", "submodule", "foreach", "--recursive",
210+
"cd \"$toplevel/.git/modules/$name\" && mv index origindex && trap 'mv origindex index' EXIT && git read-tree \"$sha1\" && git checkout-index -a --prefix=\""+to+"/$path/\"",
211+
)
212+
cmd.SetDir(r.LocalPath())
213+
if out, err := cmd.CombinedOutput(); err != nil {
214+
return errors.Wrap(err, string(out))
215+
}
216+
}
217+
206218
return nil
207219
}
208220

0 commit comments

Comments
 (0)