summaryrefslogtreecommitdiff
path: root/rc/tools/patch-range.pl
AgeCommit message (Collapse)Author
2024-09-16rc git: teach "git apply" to work on content, not just diffsJohannes Altmanninger
Staging/unstaging/reverting (parts of) the current buffer's file can be a common use case. Today "git apply" can do that based on a selection within a diff. When the selection is on uncommitted content, we can probably assume that the intent is to use the part of the selection that overlaps with the +-side of "git diff" (or "git diff --cached" for "git apply --cached"). Make "git apply" treat selections as content if the buffile is tracked by Git. This differentiator is not perfect but I don't know why anyone would want to use the existing "git apply" semantics on a tracked file. Maybe we should pick a different name. This feature couples well with "git show-diff", which shows all lines with unstaged changes (in future it should probably show staged changes as well). Whereas on diffs, "git apply" stages the entire hunk if the selection contains no newline, this does not happen when operating on content. I didn't yet try implementing that. I guess the hunks are not as explicit here. Closes #5225
2024-09-16patch-range.pl: extract peculiaritiesJohannes Altmanninger
We pipe the output of the patch program to stderr (to have it show up in *debug*) and print to stdout the remaining diff (the part of the diff that was not passed to patch). The next patch wants to use this script in a different way, so move these decisions up.
2024-01-26rc tools patch: skip patch message signature, fixing diff applicationJohannes Altmanninger
Patches as produced by "git format-patch" have a trailing signature that is separated from the body by a line with "-- " on it. By default it contains the Git version. We erroneously include this signature in the diff we pipe to patch, which fails to apply as a result. Add a targeted fix to suppress these signatures.
2024-01-22rc tools patch: skip spurious diff header for files with no changesJohannes Altmanninger
Since :patch transforms its inputs into context-only lines, we can easily get into a state where a file diff has only context lines. git apply does not accept a "diff" without any hunk, so let's skip that.
2023-11-04rc tools patch: "patch" command to apply selections in diffs to fileJohannes Altmanninger
One of the features I miss most from Magit/Fugitive/Tig is to apply/revert/stage/unstage individual hunks or even exactly the selected line(s). This provides a much more convenient way of splitting changes than "git add/restore -p". Implement a "patch" command that applies the selected lines within a diff by piping them to the "patch" program. It can also feed other programs like "git apply" (see the next commit). Original discussion: https://discuss.kakoune.com/t/atomic-commits-in-kakoune/1446 Interestingly, :patch is defined outside the "patch" module. This is to make it readily available for interactive use. Putting it into the module does not save any work. I tentatively added a patch module anyway so we can explicitly declare this dependency.. although there is the argument that this is not really needed?