summaryrefslogtreecommitdiffstats
path: root/pkg/commands/patch
AgeCommit message (Collapse)Author
2024-06-23Fix custom patch operations on added filesStefan Haller
Several custom patch commands on parts of an added file would fail with the confusing error message "error: new file XXX depends on old contents". These were dropping the custom patch from the original commit, moving the patch to a new commit, moving it to a later commit, or moving it to the index. We fix this by converting the patch header from an added file to a diff against an empty file. We do this not just for the purpose of applying the patch, but also for rendering it and copying it to the clip board. I'm not sure it matters much in these cases, but it does feel more correct for a filtered patch to be presented this way.
2024-06-23Introduce options struct for RenderPatchForFileStefan Haller
We're going to add another argument in the next commit, and that's getting a bit much, especially when most of the arguments are bool and you only see true and false at the call sites without knowing what they mean.
2024-05-19Remove redundant variable dedeclarationsJesse Duffield
In go 1.22, loop variables are redeclared with each iteration of the loop, rather than simple updated on each iteration. This means that we no longer need to manually redeclare variables when they're closed over by a function.
2024-04-12standardize 'Commit Sha' to 'Commit Hash'pikomonde
2024-01-28Support selecting file range in patch builderAaron Hoffman
test: add move_range_to_index test: add toggle_range
2024-01-19Standardise display of range selection across viewsJesse Duffield
We're not fully standardising here: different contexts can store their range state however they like. What we are standardising on is that now the view is always responsible for highlighting the selected lines, meaning the context/controller needs to tell the view where the range start is. Two convenient benefits from this change: 1) we no longer need bespoke code in integration tests for asserting on selected lines because we can just ask the view 2) line selection in staging/patch-building/merge-conflicts views now look the same as in list views i.e. the highlight applies to the whole line (including trailing space) I also noticed a bug with merge conflicts not rendering the selection on focus though I suspect it wasn't a bug with any real consequences when the view wasn't displaying the selection. I'm going to scrap the selectedRangeBgColor config and just let it use the single line background color. Hopefully nobody cares, but there's really no need for an extra config.
2023-08-15Stop cycling hunks when reaching the endStefan Haller
Previously, when pressing right-arrow when the cursor is already in the last hunk, it would jump back to the beginning of that hunk. This can be confusing if the hunk is long, maybe the start of the hunk is already scrolled off the top of the window, and then pressing right-arrow actually scrolls *backwards*, which is counter-intuitive. It's better to do nothing in this case. Same for left-arrow when the cursor is already in the first hunk, although here the problem is not so severe (unless diff context was increased by a huge amount, and the start of the first hunk is scrolled off the bottom of the window).
2023-08-10Fix bug in LineNumberOfLineStefan Haller
This fixes a regression that was introduced in 73c7dc9c5d00.
2023-08-10Add test case for LineNumberOfLine()Stefan Haller
There's a bug in LineNumberOfLine, but the existing test coverage doesn't catch it, as the only test case for this was one where oldStart and newStart were the same for all hunks. Add a test case where newStart is different for one of the hunks; this demonstrates a bug, where all expected results from index 12 on are off by one.
2023-07-30Standardise on using lo for slice functionsJesse Duffield
We've been sometimes using lo and sometimes using my slices package, and we need to pick one for consistency. Lo is more extensive and better maintained so we're going with that. My slices package was a superset of go's own slices package so in some places I've just used the official one (the methods were just wrappers anyway). I've also moved the remaining methods into the utils package.
2023-05-20Refactor interface for ApplyPatchJesse Duffield
2023-03-19rename patch manager to patch builderJesse Duffield
2023-03-19refactor patch codeJesse Duffield
2023-03-18Fix "move patch into new commit" for partial hunk (#2507)Stefan Haller
2023-03-08Add more unit testsJesse Duffield
2023-03-07Rename WillBeAppliedReverse to ReverseStefan Haller
This is the only "reverse"-related option that is left, so use a less clumsy name for it.
2023-03-07Remove the PatchOptions.Reverse optionStefan Haller
All callers pass false now (except for the tests, which we simply remove), so we don't need the option any more.
2023-03-07Concatenate patches to apply them all at onceStefan Haller
This fixes the problem that patching would stop at the first file that has a conflict. We always want to patch all files. Also, it's faster for large patches, and the code is a little bit simpler too.
2023-03-07Remove parameters that are no longer neededStefan Haller
All callers in this file now use reverseOnGenerate=false and keepOriginalHeader=true, so hard-code that in the call to ModifiedPatchForLines and get rid of the parameters.
2023-03-07Remove the keepOriginalHeader retry loopStefan Haller
The loop is pointless for two reasons: - git apply --3way has this fallback built in already. If it can't do a three-way merge, it will fall back to applying the patch normally. - However, the only situation where it does this is when it can't do a 3-way merge at all because it can't find the necessary ancestor blob. This can only happen if you transfer a patch between different repos that don't have the same blobs available; we are applying the patch to the same repo that is was just generated from, so a 3-way merge is always possible. (Now that we fixed the bug in the previous commit, that is.) But the retry loop is not only pointless, it was actually harmful, because when a 3-way patch fails with a conflict, git will put conflict markers in the patched file and then exit with a non-zero exit status. So the retry loop would try to patch the already patched file again, and this almost certainly fails, but with a cryptic error message such as "error: main.go: does not exist in index".
2023-03-07Use forward patches and --reverse flag for partial patches tooStefan Haller
There's no reason to have two different ways of applying patches for whole-file patches and partial patches; use --reverse for both. Not only does this simplify the code a bit, but it fixes an actual problem: when reverseOnGenerate and keepOriginalHeader are both true, the generated patch header is broken (the two blobs in the line `index 6d1959b..6dc5f84 100644` are swapped). Git fails to do a proper three-way merge in that case, as it expects the first of the two blobs to be the common ancestor. It would be possible to fix this by extending ModifiedPatchForLines to swap the two blobs in this case; but this would prevent us from concatenating all patches and apply them in one go, which we are going to do later in the branch.
2023-03-07Add patch option WillBeAppliedReverseStefan Haller
It's not used yet, but covered with tests already.
2023-03-07Bundle the reverse and keepOriginalHeader flags into a PatchOptions structStefan Haller
We are going to add one more flag in the next commit. Note that we are not using the struct inside patch_manager.go; we keep passing the individual flags there. The reason for this will become more obvious later in this branch.
2023-02-25Improve staging panel integration testsJesse Duffield
2023-01-26Don't omit final line feed when copying diff lines to clipboardstk
2023-01-26Cleanup: remove unused function RenderPlainstk
2022-08-06refactor to only have one context per viewJesse Duffield
2022-03-24would you believe that I'm adding even more genericsJesse Duffield
2022-03-24more genericsJesse Duffield
2022-03-24make more use of genericsJesse Duffield
2022-03-19update lintersJesse Duffield
2022-01-09add some more lintersJesse Duffield
2022-01-07privatise some fieldsJesse Duffield
2021-10-16minor changesJesse Duffield
2021-10-16copy selected text to clipboardHrishikesh Hiraskar
2021-08-04fix backward compatibilityRyooooooga
2021-08-03fix out of range errorRyooooooga
2021-08-01color fixupsJesse Duffield
2021-07-31simplify code a bitJesse Duffield
2021-07-30Switch to github.com/gookit/color for terminal colorsmjarkk
2021-04-18refactor line by line panelJesse Duffield
2021-04-02big refactor to give our enums actual typesJesse Duffield
2021-04-02do not show commit files of another parent as added to the patchJesse Duffield
2021-04-02refactorJesse Duffield
2020-08-23cleanupJesse Duffield
2020-08-23remove todo commentJesse Duffield
2020-08-23support creating patches from files in diff modeJesse Duffield
2020-08-23don't needlessly load every fileJesse Duffield
2020-08-23faster patch managerJesse Duffield
2020-08-23refactorJesse Duffield