diff --git a/modules/git/repo_compare.go b/modules/git/repo_compare.go index e706275856856..e6e9b9ced03dc 100644 --- a/modules/git/repo_compare.go +++ b/modules/git/repo_compare.go @@ -39,10 +39,17 @@ func (repo *Repository) GetMergeBase(tmpRemote, base, head string) (string, stri if tmpRemote != "origin" { tmpBaseName := RemotePrefix + tmpRemote + "/tmp_" + base // Fetch commit into a temporary branch in order to be able to handle commits and tags - _, _, err := NewCommand(repo.Ctx, "fetch", "--no-tags").AddDynamicArguments(tmpRemote).AddDashesAndList(base + ":" + tmpBaseName).RunStdString(&RunOpts{Dir: repo.Path}) - if err == nil { - base = tmpBaseName + // --no-write-commit-graph: fetch will try to generate commit graph by default + // this process require a lock-file (objects/info/commit-graphs/commit-graph-chain.lock) + // and will make fetch return an error code if the file already exists + _, _, err := NewCommand(repo.Ctx, "fetch", "--no-write-commit-graph", "--no-tags"). + AddDynamicArguments(tmpRemote).AddDashesAndList(base + ":" + tmpBaseName). + RunStdString(&RunOpts{Dir: repo.Path}) + if err != nil { + logger.Error("Failed to fetch new remote for GetMergeBase %v", err) + return "", "", err } + base = tmpBaseName } stdout, _, err := NewCommand(repo.Ctx, "merge-base").AddDashesAndList(base, head).RunStdString(&RunOpts{Dir: repo.Path})