Skip to content

Commit

Permalink
Fix git checkout for annotated tags (#3198)
Browse files Browse the repository at this point in the history
Remove refspec annotation for tags. Annotated tags cannot be mapped to a
local ref.

Fixes #3197
  • Loading branch information
emcfarlane authored Jul 31, 2024
1 parent 9d58407 commit 429c3ac
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## [Unreleased]

- No changes yet.
- Fix git input handling of annotated tags.

## [v1.35.1] - 2024-07-24

Expand Down
4 changes: 2 additions & 2 deletions private/pkg/git/cloner.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,11 @@ func getRefspecsForName(gitName Name) (fetchRef string, fallbackRef string, chec
return createFetchRefSpec(cloneBranch), "", checkout
} else if cloneBranch != "" {
// If a branch is specified, we fetch the branch directly.
return createFetchRefSpec(cloneBranch), "", cloneBranch
return cloneBranch, "", ""
} else if checkout != "" && checkout != "HEAD" {
// If a checkout ref is specified, we fetch the ref directly.
// We fallback to fetching the HEAD to resolve partial refs.
return createFetchRefSpec(checkout), "HEAD", checkout
return checkout, "HEAD", ""
}
return "HEAD", "", ""
}
Expand Down
21 changes: 21 additions & 0 deletions private/pkg/git/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,26 @@ func TestGitCloner(t *testing.T) {
_, err = readBucket.Stat(ctx, "nonexistent")
assert.True(t, errors.Is(err, fs.ErrNotExist))
})
t.Run("tag=remote-annotated-tag", func(t *testing.T) {
t.Parallel()
readBucket := readBucketForName(ctx, t, runner, workDir, 1, NewTagName("remote-annotated-tag"), false)

content, err := storage.ReadPath(ctx, readBucket, "test.proto")
require.NoError(t, err)
assert.Equal(t, "// commit 4", string(content))
_, err = readBucket.Stat(ctx, "nonexistent")
assert.True(t, errors.Is(err, fs.ErrNotExist))
})
t.Run("ref=remote-annotated-tag", func(t *testing.T) {
t.Parallel()
readBucket := readBucketForName(ctx, t, runner, workDir, 1, NewRefName("remote-annotated-tag"), false)

content, err := storage.ReadPath(ctx, readBucket, "test.proto")
require.NoError(t, err)
assert.Equal(t, "// commit 4", string(content))
_, err = readBucket.Stat(ctx, "nonexistent")
assert.True(t, errors.Is(err, fs.ErrNotExist))
})

t.Run("branch_and_main_ref", func(t *testing.T) {
t.Parallel()
Expand Down Expand Up @@ -308,6 +328,7 @@ func createGitDirs(
runCommand(ctx, t, container, runner, "git", "-C", originPath, "add", "test.proto")
runCommand(ctx, t, container, runner, "git", "-C", originPath, "commit", "-m", "commit 4")
runCommand(ctx, t, container, runner, "git", "-C", originPath, "tag", "remote-tag")
runCommand(ctx, t, container, runner, "git", "-C", originPath, "tag", "-a", "remote-annotated-tag", "-m", "annotated tag")

runCommand(ctx, t, container, runner, "git", "-C", workPath, "fetch", "origin")
return originPath, workPath
Expand Down

0 comments on commit 429c3ac

Please sign in to comment.