1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-11-25 21:16:38 +03:00

rc git: support uncommitted lines in git blame too

I frequently run ":git diff" followed by ":git blame-jump" to find
the commit that added the lines I deleted.  I wasn't sure whether
":git blame" should allow this use case too. I think it should,
I don't think this is too confusing.
This commit is contained in:
Johannes Altmanninger 2024-02-25 17:56:39 +01:00 committed by Maxime Coste
parent efaf9ab4e2
commit 07d58cab9e

View File

@ -222,25 +222,32 @@ define-command -params 1.. \
evaluate-commands -client '${kak_client}' -draft %{
try %{
execute-keys <a-l><semicolon><a-?>^commit<ret><a-semicolon>
require-module diff
try %{
diff-parse END %{
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",
$commit, quote($file), $line, ('${kak_cursor_column}' - 1);
}
} catch %{
echo -to-file '${kak_response_fifo}' -quoting shell -- %val{error}
}
} catch %{
# Missing commit line, assume it is an uncommitted change.
echo -to-file '${kak_response_fifo}' -quoting shell -- \
"git blame: blaming without commit line is not yet supported"
execute-keys <a-l><semicolon><a-?>\A<ret><a-semicolon>
}
require-module diff
try %{
diff-parse END %{
my $line = $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}";
exit;
}
} elsif ($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",
$commit, quote($file), $line, ('${kak_cursor_column}' - 1);
}
} catch %{
echo -to-file '${kak_response_fifo}' -quoting shell -- %val{error}
}
}
'