From 2fc3a7100b38391c6ac03e4699b641ded0a6cb60 Mon Sep 17 00:00:00 2001 From: Hidde Beydals Date: Mon, 24 Jun 2019 14:03:42 +0200 Subject: [PATCH] Fetch tags with --force due to changes in Git 2.20 "Until Git version 2.20, and unlike when pushing with git-push[1], any updates to refs/tags/* would be accepted without + in the refspec (or --force). When fetching, we promiscuously considered all tag updates from a remote to be forced fetches. Since Git version 2.20, fetching to update refs/tags/* works the same way as when pushing. I.e. any updates will be rejected without + in the refspec (or --force)." https://git-scm.com/docs/git-fetch https://github.com/git/git/blob/master/Documentation/RelNotes/2.20.0.txt#L67-L71 --- git/operations.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/git/operations.go b/git/operations.go index ef25c8211..c952c5ce9 100644 --- a/git/operations.go +++ b/git/operations.go @@ -126,14 +126,14 @@ func push(ctx context.Context, workingDir, upstream string, refs []string) error // fetch updates refs from the upstream. func fetch(ctx context.Context, workingDir, upstream string, refspec ...string) error { - args := append([]string{"fetch", "--tags", upstream}, refspec...) + args := append([]string{"fetch", "--tags", "--force", upstream}, refspec...) // In git <=2.20 the error started with an uppercase, in 2.21 this // was changed to be consistent with all other die() and error() // messages, cast to lowercase to support both versions. // Ref: https://github.com/git/git/commit/0b9c3afdbfb62936337efc52b4007a446939b96b if err := execGitCmd(ctx, args, gitCmdConfig{dir: workingDir}); err != nil && !strings.Contains(strings.ToLower(err.Error()), "couldn't find remote ref") { - return errors.Wrap(err, fmt.Sprintf("git fetch --tags %s %s", upstream, refspec)) + return errors.Wrap(err, fmt.Sprintf("git fetch --tags --force %s %s", upstream, refspec)) } return nil }