rc tools git: fix initial position of blame of deleted line
When running git blame in a "git show" buffer, we annotate the youngest version of the file that has the line referenced by the diff line at cursor. In case the cursor is on an added or context line, we simply show the version from the surrounding commit. When the cursor is on a deleted line, we show the parent commit, which still has the deleted line. However there is a bug: we use the line number in the new version of the file. Fix that.
This commit is contained in:
parent
22b1d4ec4a
commit
5f0729f155
|
@ -225,9 +225,14 @@ define-command -params 1.. \
|
||||||
require-module diff
|
require-module diff
|
||||||
try %{
|
try %{
|
||||||
diff-parse END %{
|
diff-parse END %{
|
||||||
$commit = "$commit~" if $diff_line_text =~ m{^[-]};
|
my $line = $file_line;
|
||||||
|
if ($diff_line_text =~ m{^[-]}) {
|
||||||
|
$commit = "$commit~";
|
||||||
|
$line = $other_file_line;
|
||||||
|
}
|
||||||
|
$line = $line or 1;
|
||||||
printf "echo -to-file '${kak_response_fifo}' -quoting shell %s %s %d %d",
|
printf "echo -to-file '${kak_response_fifo}' -quoting shell %s %s %d %d",
|
||||||
$commit, quote($file), ($file_line or 1), ('${kak_cursor_column}' - 1);
|
$commit, quote($file), $line, ('${kak_cursor_column}' - 1);
|
||||||
}
|
}
|
||||||
} catch %{
|
} catch %{
|
||||||
echo -to-file '${kak_response_fifo}' -quoting shell -- %val{error}
|
echo -to-file '${kak_response_fifo}' -quoting shell -- %val{error}
|
||||||
|
|
1
test/tools/git/blame-in-diff/cmd
Normal file
1
test/tools/git/blame-in-diff/cmd
Normal file
|
@ -0,0 +1 @@
|
||||||
|
:run<ret>
|
2
test/tools/git/blame-in-diff/enabled
Executable file
2
test/tools/git/blame-in-diff/enabled
Executable file
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
command -v git >/dev/null
|
1
test/tools/git/blame-in-diff/env
Symbolic link
1
test/tools/git/blame-in-diff/env
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
../env
|
3
test/tools/git/blame-in-diff/in
Normal file
3
test/tools/git/blame-in-diff/in
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
line 1
|
||||||
|
line 2
|
||||||
|
line 3
|
2
test/tools/git/blame-in-diff/kak_selection
Normal file
2
test/tools/git/blame-in-diff/kak_selection
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
line 2
|
||||||
|
|
14
test/tools/git/blame-in-diff/rc
Normal file
14
test/tools/git/blame-in-diff/rc
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
declare-option str jumpclient
|
||||||
|
source "%val{runtime}/rc/filetype/diff.kak"
|
||||||
|
source "%val{runtime}/rc/tools/git.kak"
|
||||||
|
|
||||||
|
define-command run %{
|
||||||
|
git init
|
||||||
|
git add
|
||||||
|
git commit --message 'initial commit'
|
||||||
|
execute-keys %{2gIchanged <esc>}
|
||||||
|
write
|
||||||
|
git commit --all --message 'changed line 2'
|
||||||
|
# Show the commit, jumping to the new version of line 2.
|
||||||
|
git blame-jump
|
||||||
|
}
|
11
test/tools/git/blame-in-diff/script
Normal file
11
test/tools/git/blame-in-diff/script
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
ui_out -ignore 7
|
||||||
|
ui_out -ignore 11
|
||||||
|
|
||||||
|
# We've jumped to the new version of line 2. Move to the old version so we
|
||||||
|
# can annotate the old file.
|
||||||
|
ui_in '{ "jsonrpc": "2.0", "method": "keys", "params": [ "k:git blame<ret>" ] }'
|
||||||
|
ui_out -ignore 11
|
||||||
|
|
||||||
|
# We should have jumped to the old version of line 2, assert on kak_selection.
|
||||||
|
ui_in '{ "jsonrpc": "2.0", "method": "keys", "params": [ "x" ] }'
|
||||||
|
ui_out -ignore 5
|
Loading…
Reference in New Issue
Block a user