Skip to content

Commit

Permalink
Fix git fetch bug with tags on Azure devops (#14722)
Browse files Browse the repository at this point in the history
  • Loading branch information
moelsayed authored Jun 30, 2022
1 parent 889b20c commit da08390
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
6 changes: 5 additions & 1 deletion components/function-controller/internal/git/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ func (g *git2goFetcher) git2goFetch(url, outputPath string, remoteCallbacks git2
}
defer remote.Free()

err = remote.Fetch(nil, &git2go.FetchOptions{RemoteCallbacks: remoteCallbacks}, "")
err = remote.Fetch(nil,
&git2go.FetchOptions{
RemoteCallbacks: remoteCallbacks,
DownloadTags: git2go.DownloadTagsAll,
}, "")
if err != nil {
return nil, errors.Wrap(err, "while fetching remote")
}
Expand Down
19 changes: 19 additions & 0 deletions components/function-controller/internal/git/go2git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
git2go "github.com/libgit2/git2go/v31"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
)

const (
Expand All @@ -22,6 +23,10 @@ const (
trickyTagName = "tricky1"
tagCommit = "6eff122e8afb57a6f270285dc3bfcc9a4ef4b8ad"
secondCommitID = "8b27a9d6f148533773ae0666dc27c5b359b46553"

azureRepo = "https://[email protected]/kyma-wookiee/kyma-function/_git/kyma-function"
azureTag = "python-tag"
azureCommit = "6dac23dd3b697970cf351101ff5c3e9733c2bdfc"
)

func TestNewGit2Go_LastCommit(t *testing.T) {
Expand Down Expand Up @@ -83,6 +88,20 @@ func TestNewGit2Go_LastCommit(t *testing.T) {
}
}

func TestNewGit2Go_LastCommitWithAzureTag(t *testing.T) {
//GIVEN
client := NewGit2Go(zap.L().Sugar())

//WHEN
commitID, err := client.LastCommit(Options{
URL: azureRepo,
Reference: azureTag,
})
//THEN
require.NoError(t, err)
assert.Equal(t, azureCommit, commitID)
}

func TestGo2GitClient_Clone(t *testing.T) {
//GIVEN
repoPath := prepareRepo(t)
Expand Down

0 comments on commit da08390

Please sign in to comment.