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

Commit 7c0d5d6

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 1550da3 commit 7c0d5d6

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

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)