From 03b88899752446077800bdb2fc7584cd74288d2e Mon Sep 17 00:00:00 2001 From: David Gageot Date: Wed, 27 Jun 2018 08:23:36 +0200 Subject: [PATCH] Use tags only in case of perfect match Fix #754 --- pkg/skaffold/build/tag/git_commit.go | 6 ++---- pkg/skaffold/build/tag/git_commit_test.go | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/pkg/skaffold/build/tag/git_commit.go b/pkg/skaffold/build/tag/git_commit.go index c76e57f5bbc..64cdc04ef51 100644 --- a/pkg/skaffold/build/tag/git_commit.go +++ b/pkg/skaffold/build/tag/git_commit.go @@ -78,10 +78,8 @@ func generateNameGitShellOut(workingDir string, opts *Options) (string, error) { return dirtyTag(currentTag, opts), nil } - tags, err := runGitLines(root, "describe", "--tags", "--always") - if err != nil { - return "", errors.Wrap(err, "getting tags") - } + // Ignore error. It means there's no tag. + tags, _ := runGitLines(root, "describe", "--tags", "--exact-match") return commitOrTag(currentTag, tags, opts), nil } diff --git a/pkg/skaffold/build/tag/git_commit_test.go b/pkg/skaffold/build/tag/git_commit_test.go index 6b067337f50..5011411e98d 100644 --- a/pkg/skaffold/build/tag/git_commit_test.go +++ b/pkg/skaffold/build/tag/git_commit_test.go @@ -100,6 +100,20 @@ func TestGitCommit_GenerateFullyQualifiedImageName(t *testing.T) { write("new.go", []byte("new code")) }, }, + { + description: "don't use tag if not exact match", + expectedName: "test:3cec6b9", + createGitRepo: func(dir string) { + gitInit(t, dir). + write("source.go", []byte("code")). + add("source.go"). + commit("initial"). + tag("v1"). + write("source.go", []byte("updated code")). + add("source.go"). + commit("changes") + }, + }, { description: "deleted file", expectedName: "test:279d53f-dirty-abababa",