Skip to content
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
5 changes: 3 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ func sync() error {
fullDefaultBranch := fmt.Sprintf("refs/remotes/%s/%s", remote, defaultBranch)
currentBranch := gitw.CurrentBranch()

// git fetch --prune --progress <remote>
out, err := git.Fetch(fetch.Prune, fetch.Progress, fetch.Remote(remote))
// git fetch --prune --progress --no-tags --no-prune-tags <remote>
noPruneTags := func(g *types.Cmd) { g.AddOptions("--no-prune-tags") }
out, err := git.Fetch(fetch.Prune, fetch.Progress, fetch.NoTags, noPruneTags, fetch.Remote(remote))
if err != nil {
return errors.New(out)
}
Expand Down
31 changes: 31 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,37 @@ func TestSync_UntrackedBranchWithoutMatchingRemoteIsUntouched(t *testing.T) {
}
}

func TestSync_ForceMovedTagIsIgnored(t *testing.T) {
remote := gittest.NewBare(t)
peer := remote.Clone(t)
local := remote.Clone(t)

// Reproduces the failure: fetch.pruneTags hard-fails on a moved tag.
local.Git(t, "config", "fetch.pruneTags", "true")

peer.Git(t, "tag", "nightly")
peer.Push(t, "origin", "nightly")

// Cache the tag locally at its original commit.
local.Git(t, "fetch", "origin", "tag", "nightly")

// Force-move the tag upstream, as a rolling release tag would.
newSHA := peer.Commit(t, "new nightly commit")
peer.Push(t, "origin", "main")
peer.Git(t, "tag", "-f", "nightly")
peer.Push(t, "origin", "nightly", "--force")

local.Chdir(t)

if err := sync(); err != nil {
t.Fatalf("sync() error: %v, want nil (force-moved tags should not fail sync)", err)
}

if got := local.Git(t, "rev-parse", "refs/remotes/origin/main"); got != newSHA {
t.Fatalf("local refs/remotes/origin/main = %q, want %q", got, newSHA)
}
}

func TestSync_UnpushedCommitsWarnsAndKeeps(t *testing.T) {
remote := gittest.NewBare(t)
local := remote.Clone(t)
Expand Down