summaryrefslogtreecommitdiff
path: root/rc/tools
diff options
context:
space:
mode:
authorJohannes Altmanninger <aclopte@gmail.com>2024-09-14 12:24:59 +0200
committerMaxime Coste <mawww@kakoune.org>2024-09-16 15:23:18 +1000
commited4729a265bad1569e377e39454be6c6436ba7e3 (patch)
tree8d181b881abca41baf67eca2b2d0754886866cef /rc/tools
parent314e69fc37d6dabcc9f57cb491153225e4d6f931 (diff)
rc git: show-diff to honor unsaved buffer modifications
If a file has unsaved modifications, then the show-diff flags below such modifications will be wrong. Fix this by using the current buffer contents, just like the git blame integration does. This might make it a bit slower, I haven't tested that.
Diffstat (limited to 'rc/tools')
-rw-r--r--rc/tools/git.kak14
1 files changed, 13 insertions, 1 deletions
diff --git a/rc/tools/git.kak b/rc/tools/git.kak
index 2fb3eeed..38fa2839 100644
--- a/rc/tools/git.kak
+++ b/rc/tools/git.kak
@@ -189,6 +189,18 @@ define-command -params 1.. \
"
}
+ diff_buffer_against_rev() {
+ rev=$1 # empty means index
+ shift
+ buffile_relative=${kak_buffile#"$PWD/"}
+ echo >${kak_command_fifo} "evaluate-commands -save-regs | %{
+ set-register | %{ cat >${kak_response_fifo} }
+ execute-keys -client ${kak_client} -draft %{%<a-|><ret>}
+ }"
+ git show "$rev:./${buffile_relative}" |
+ git diff --no-index - ${kak_response_fifo} "$@"
+ }
+
blame_toggle() {
echo >${kak_command_fifo} "try %{
add-highlighter window/git-blame flag-lines Information git_blame_flags
@@ -370,7 +382,7 @@ define-command -params 1.. \
update_diff() {
(
cd_bufdir
- git diff --no-ext-diff -U0 "$kak_buffile" | perl -e '
+ diff_buffer_against_rev "" -U0 | perl -e '
use utf8;
$flags = $ENV{"kak_timestamp"};
$add_char = $ENV{"kak_opt_git_diff_add_char"};