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

go-git: transform revision for last observed tag #463

Merged
merged 1 commit into from
Feb 10, 2023
Merged
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
9 changes: 4 additions & 5 deletions git/gogit/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,12 @@ func (g *Client) cloneTag(ctx context.Context, url, tag string, opts repository.

ref := plumbing.NewTagReferenceName(tag)
// check if previous revision has changed before attempting to clone
if opts.LastObservedCommit != "" {
if lastObserved := git.TransformRevision(opts.LastObservedCommit); lastObserved != "" {
head, err := getRemoteHEAD(ctx, url, ref, g.authOpts, authMethod)
if err != nil {
return nil, err
}

if head != "" && head == opts.LastObservedCommit {
if head != "" && head == lastObserved {
c := &git.Commit{
Hash: git.ExtractHashFromRevision(head),
Reference: ref.String(),
Expand Down Expand Up @@ -364,11 +363,11 @@ func recurseSubmodules(recurse bool) extgogit.SubmoduleRescursivity {

func getRemoteHEAD(ctx context.Context, url string, ref plumbing.ReferenceName,
authOpts *git.AuthOptions, authMethod transport.AuthMethod) (string, error) {
config := &config.RemoteConfig{
remoteCfg := &config.RemoteConfig{
Name: git.DefaultRemote,
URLs: []string{url},
}
remote := extgogit.NewRemote(memory.NewStorage(), config)
remote := extgogit.NewRemote(memory.NewStorage(), remoteCfg)
listOpts := &extgogit.ListOptions{
Auth: authMethod,
CABundle: authOpts.CAFile,
Expand Down