summaryrefslogtreecommitdiff
path: root/rc/tools/git.kak
diff options
context:
space:
mode:
authorJohannes Altmanninger <aclopte@gmail.com>2025-02-18 09:00:14 +0100
committerMaxime Coste <mawww@kakoune.org>2025-02-18 21:07:06 +1100
commit9eda509282ebc881207c2d8278085cb53835641c (patch)
tree3fba0aecbd669a681031b4e24bd3ed850806de0f /rc/tools/git.kak
parent72bfe0153b47196b335c51553a1707beddab69aa (diff)
rc git: fix blame in diff of deleted/renamed files
The code paths around "Missing commit line, assume it is an uncommitted change" in both blame and blame-jump code look suspiciously similar. It's possible that we can extract at least something, but there is a fundamental difference: blame-jump only jumps to another diff, while blame jumps from diff to blob, which may be a good reason for keeping them separate. More specifically, blame-jump passes « $version = "-" » because it's only interested in the parent commit/file/line, whereas blame wants to default to using the child commit/file/line (for added and context lines) and only uses the parent commit/file/line when run on deleted lines or on uncommitted changes (where HEAD is assumed to be parent commit even if there is no child). Unfortunately the blame path forgot to change to use the parent file for these; fix that and get rid of some code duplication.
Diffstat (limited to 'rc/tools/git.kak')
-rw-r--r--rc/tools/git.kak10
1 files changed, 6 insertions, 4 deletions
diff --git a/rc/tools/git.kak b/rc/tools/git.kak
index 2846af66..d7d53d5f 100644
--- a/rc/tools/git.kak
+++ b/rc/tools/git.kak
@@ -230,10 +230,10 @@ define-command -params 1.. \
require-module diff
try %{
diff-parse END %{
- my $line = $file_line;
+ my $filename = $other_file;
+ my $line = $other_file_line;
if (not defined $commit) {
$commit = "HEAD";
- $line = $other_file_line;
if ($diff_line_text =~ m{^\+}) {
print "echo -to-file '${kak_response_fifo}' -quoting shell "
. "%{git blame: blame from HEAD does not work on added lines}";
@@ -241,11 +241,13 @@ define-command -params 1.. \
}
} elsif ($diff_line_text =~ m{^[-]}) {
$commit = "$commit~";
- $line = $other_file_line;
+ } else {
+ $filename = $file;
+ $line = $file_line;
}
$line = $line or 1;
printf "echo -to-file '${kak_response_fifo}' -quoting shell %s %s %d %d",
- $commit, quote($file), $line, ('${kak_cursor_column}' - 1);
+ $commit, quote($filename), $line, ('${kak_cursor_column}' - 1);
}
} catch %{
echo -to-file '${kak_response_fifo}' -quoting shell -- %val{error}