From 07d58cab9ee25a80c33cd01a89f79429076c58f6 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sun, 25 Feb 2024 17:56:39 +0100 Subject: [PATCH] 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. --- rc/tools/git.kak | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/rc/tools/git.kak b/rc/tools/git.kak index c80dc702d..2c29ee176 100644 --- a/rc/tools/git.kak +++ b/rc/tools/git.kak @@ -222,25 +222,32 @@ define-command -params 1.. \ evaluate-commands -client '${kak_client}' -draft %{ try %{ execute-keys ^commit - 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 + } + 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} } } '