mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-19 00:10:15 +00:00
[FEAT] Check if commit is already present in target branch
- Check if someone is (accidentally) trying to create a pull request via AGit with changes already in the target branch and fail if that is the case. - Added integration test.
This commit is contained in:
parent
6531d765a0
commit
f0ed6de89d
2 changed files with 34 additions and 4 deletions
|
@ -101,6 +101,21 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git.
|
|||
return nil, fmt.Errorf("failed to get unmerged AGit flow pull request in repository %q: %w", repo.FullName(), err)
|
||||
}
|
||||
|
||||
// Check if the changes are already in the target branch.
|
||||
stdout, _, gitErr := git.NewCommand(ctx, "branch", "--contains").AddDynamicArguments(opts.NewCommitIDs[i], baseBranchName).RunStdString(&git.RunOpts{Dir: repo.RepoPath()})
|
||||
if gitErr != nil {
|
||||
return nil, fmt.Errorf("failed to check if the target branch already contains the new commit in repository %q: %w", repo.FullName(), err)
|
||||
}
|
||||
if len(stdout) > 0 {
|
||||
results = append(results, private.HookProcReceiveRefResult{
|
||||
OriginalRef: opts.RefFullNames[i],
|
||||
OldOID: opts.OldCommitIDs[i],
|
||||
NewOID: opts.NewCommitIDs[i],
|
||||
Err: "The target branch already contains this commit",
|
||||
})
|
||||
continue
|
||||
}
|
||||
|
||||
// Automatically fill out the title and the description from the first commit.
|
||||
shouldGetCommit := len(title) == 0 || len(description) == 0
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue