Add patch option WillBeAppliedReverse

It's not used yet, but covered with tests already.
This commit is contained in:
Stefan Haller 2023-02-26 13:48:10 +01:00
parent f76cc27956
commit c79e360584
3 changed files with 86 additions and 15 deletions

View file

@ -18,6 +18,15 @@ type PatchOptions struct {
// generating the patch.
Reverse bool
// If true, we're building a patch that we are going to apply using
// "git apply --reverse". In other words, we are not flipping the '+' and
// '-' ourselves while creating the patch, but git is going to do that when
// applying. This has consequences for which lines we need to keep or
// discard when filtering lines from partial hunks.
//
// Currently incompatible with Reverse.
WillBeAppliedReverse bool
// Whether to keep or discard the original diff header including the
// "index deadbeef..fa1afe1 100644" line.
KeepOriginalHeader bool
@ -105,7 +114,8 @@ outer:
formattedHunks := ""
var formattedHunk string
for _, hunk := range hunksInRange {
startOffset, formattedHunk = hunk.formatWithChanges(lineIndices, opts.Reverse, startOffset)
startOffset, formattedHunk = hunk.formatWithChanges(
lineIndices, opts.Reverse, opts.WillBeAppliedReverse, startOffset)
formattedHunks += formattedHunk
}