diff options
| author | Johannes Altmanninger <aclopte@gmail.com> | 2024-09-14 12:25:02 +0200 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2024-09-16 15:23:18 +1000 |
| commit | 54992c08aecb2fc91aecacccc15d3a17ae7390dc (patch) | |
| tree | fb8cc822bb2105111b93bb1f1ad96759ac22262f /rc/filetype | |
| parent | aac32e0f5ad3332775a4f3e3092a4fd8a6c0db62 (diff) | |
rc git: teach "git apply" to work on content, not just diffs
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
Diffstat (limited to 'rc/filetype')
| -rwxr-xr-x | rc/filetype/diff-parse.pl | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/rc/filetype/diff-parse.pl b/rc/filetype/diff-parse.pl index 7453b2b3..5da4e349 100755 --- a/rc/filetype/diff-parse.pl +++ b/rc/filetype/diff-parse.pl @@ -45,13 +45,15 @@ our $version = "+"; eval $begin if defined $begin; -$in_file = "$directory/$in_file" if defined $in_file; +$in_file = "$directory/$in_file" if defined $in_file && $in_file ne ""; # Outputs our $diff_line = 0; our $commit; our $file; our $file_line; +our $other_file; +our $other_file_line; our $diff_line_text; my $other_version; @@ -63,8 +65,6 @@ if ($version eq "+") { my $is_recursive_diff = 0; my $state = "header"; my $fallback_file; -my $other_file; -my $other_file_line; sub strip { my $is_recursive_diff = shift; @@ -127,7 +127,7 @@ while (<STDIN>) { $other_file_line++ if defined $other_file_line; } } - if (defined $in_file and defined $file and $file eq $in_file) { + if (defined $in_file and defined $file and ($in_file eq "" or $file eq $in_file)) { if (defined $in_file_line and defined $file_line and $file_line >= $in_file_line) { last; } |
