[F3] PR create the pull/N/head from the original PR head

It is incorrect to assume they are identical because:

* the IDs of a PR may be remapped and pull/N/head will become
  pull/M/head
* the head of a remote fork is a branch named after the fork
This commit is contained in:
Earl Warren 2023-09-16 10:54:39 +02:00
parent 9941131920
commit 9c220bf23e
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00

View file

@ -220,6 +220,7 @@ func (o *PullRequest) FromFormat(pullRequest *format.PullRequest) {
*o = PullRequest{
PullRequest: pr,
FetchFunc: pullRequest.FetchFunc,
}
}
@ -336,6 +337,21 @@ func (o *PullRequestProvider) Put(ctx context.Context, user *User, project *Proj
}
}
if pullRequest.FetchFunc != nil {
repoPath := repo_model.RepoPath(user.Name, project.Name)
fromHead := pullRequest.FetchFunc(repoPath)
gitRepo, err := git.OpenRepository(ctx, repoPath)
if err != nil {
panic(err)
}
defer gitRepo.Close()
toHead := fmt.Sprintf("%s%d/head", git.PullPrefix, pullRequest.GetID())
if err := git.NewCommand(ctx, "update-ref").AddDynamicArguments(toHead, fromHead).Run(&git.RunOpts{Dir: repoPath}); err != nil {
panic(err)
}
}
return o.Get(ctx, user, project, pullRequest)
}