From 528e3e6850eae3d98da09fff6be751aa96bd8da8 Mon Sep 17 00:00:00 2001 From: Roman Shaposhnik Date: Tue, 30 Jan 2018 18:58:51 -0800 Subject: [PATCH] Make it possible to key the package tags off of top level tree hash Closes #2887 Signed-off-by: Roman Shaposhnik --- src/cmd/linuxkit/pkglib/git.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/cmd/linuxkit/pkglib/git.go b/src/cmd/linuxkit/pkglib/git.go index 7341132a6..6286c8a1b 100644 --- a/src/cmd/linuxkit/pkglib/git.go +++ b/src/cmd/linuxkit/pkglib/git.go @@ -84,7 +84,21 @@ func (g git) isWorkTree(pkg string) (bool, error) { } func (g git) treeHash(pkg, commit string) (string, error) { - out, err := g.commandStdout(os.Stderr, "ls-tree", "--full-tree", commit, "--", pkg) + // we have to check if pkg is at the top level of the git tree, + // if that's the case we need to use tree hash from the commit itself + out, err := g.commandStdout(nil, "rev-parse", "--prefix", pkg, "--show-toplevel") + if err != nil { + return "", err + } + if strings.TrimSpace(out) == pkg { + out, err = g.commandStdout(nil, "show", "--format=%T", "-s", commit) + if err != nil { + return "", err + } + return strings.TrimSpace(out), nil + } + + out, err = g.commandStdout(os.Stderr, "ls-tree", "--full-tree", commit, "--", pkg) if err != nil { return "", err }