1
0
Fork 0
forked from forgejo/forgejo

Add merge style fast-forward-only (#28954)

With this option, it is possible to require a linear commit history with
the following benefits over the next best option `Rebase+fast-forward`:
The original commits continue existing, with the original signatures
continuing to stay valid instead of being rewritten, there is no merge
commit, and reverting commits becomes easier.

Closes #24906
This commit is contained in:
Chris Copeland 2024-02-12 14:37:23 -08:00 committed by Gergely Nagy
parent 05eaf1cf3e
commit 83123b493f
No known key found for this signature in database
25 changed files with 204 additions and 11 deletions

View file

@ -273,6 +273,10 @@ func doMergeAndPush(ctx context.Context, pr *issues_model.PullRequest, doer *use
if err := doMergeStyleSquash(mergeCtx, message); err != nil {
return "", err
}
case repo_model.MergeStyleFastForwardOnly:
if err := doMergeStyleFastForwardOnly(mergeCtx); err != nil {
return "", err
}
default:
return "", models.ErrInvalidMergeStyle{ID: pr.BaseRepo.ID, Style: mergeStyle}
}
@ -383,6 +387,13 @@ func runMergeCommand(ctx *mergeContext, mergeStyle repo_model.MergeStyle, cmd *g
StdErr: ctx.errbuf.String(),
Err: err,
}
} else if mergeStyle == repo_model.MergeStyleFastForwardOnly && strings.Contains(ctx.errbuf.String(), "Not possible to fast-forward, aborting") {
log.Debug("MergeDivergingFastForwardOnly %-v: %v\n%s\n%s", ctx.pr, err, ctx.outbuf.String(), ctx.errbuf.String())
return models.ErrMergeDivergingFastForwardOnly{
StdOut: ctx.outbuf.String(),
StdErr: ctx.errbuf.String(),
Err: err,
}
}
log.Error("git merge %-v: %v\n%s\n%s", ctx.pr, err, ctx.outbuf.String(), ctx.errbuf.String())
return fmt.Errorf("git merge %v: %w\n%s\n%s", ctx.pr, err, ctx.outbuf.String(), ctx.errbuf.String())