mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-29 12:46:16 +01:00
[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:
parent
9941131920
commit
9c220bf23e
1 changed files with 16 additions and 0 deletions
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue