Skip to content

Commit

Permalink
Use tags only in case of perfect match
Browse files Browse the repository at this point in the history
  • Loading branch information
dgageot committed Jun 27, 2018
1 parent 1f3c906 commit 03b8889
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
6 changes: 2 additions & 4 deletions pkg/skaffold/build/tag/git_commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
14 changes: 14 additions & 0 deletions pkg/skaffold/build/tag/git_commit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 03b8889

Please sign in to comment.