Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitTagger generates an invalid tag if there are uncommitted changes #5034

Merged
merged 1 commit into from
Nov 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pkg/skaffold/build/tag/git_commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,13 @@ func (t *GitCommit) GenerateTag(workingDir, _ string) (string, error) {
return "", fmt.Errorf("getting git status: %w", err)
}

ref = sanitizeTag(ref)

if len(changes) > 0 {
return fmt.Sprintf("%s%s-dirty", t.prefix, ref), nil
}

return t.prefix + sanitizeTag(ref), nil
return t.prefix + ref, nil
}

// sanitizeTag takes a git tag and converts it to a docker tag by removing
Expand Down
20 changes: 20 additions & 0 deletions pkg/skaffold/build/tag/git_commit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,26 @@ func TestGitCommit_GenerateTag(t *testing.T) {
tag("v/2")
},
},
{
description: "dirty worktree with tag containing a slash",
variantTags: "v_2-dirty",
variantCommitSha: "aea33bcc86b5af8c8570ff45d8a643202d63c808-dirty",
variantAbbrevCommitSha: "aea33bc-dirty",
variantTreeSha: "bc69d50cda6897a6f2054e64b9059f038dc6fb0e-dirty",
variantAbbrevTreeSha: "bc69d50-dirty",
createGitRepo: func(dir string) {
gitInit(t, dir).
write("source.go", "code").
add("source.go").
commit("initial").
tag("v/1").
write("other.go", "other").
add("other.go").
commit("second commit").
tag("v/2").
write("other.go", "updated code")
},
},
{
description: "clean worktree with tags",
variantTags: "v2",
Expand Down