Skip to content

Commit 873fa13

Browse files
committed
Merge branch 'pd/mergetool-nvimdiff'
The existing backends for "git mergetool" based on variants of vim have been refactored and then support for "nvim" has been added. * pd/mergetool-nvimdiff: mergetools: add support for nvimdiff (neovim) family mergetool--lib: improve support for vimdiff-style tool variants
2 parents 95c687b + 1186897 commit 873fa13

File tree

9 files changed

+51
-18
lines changed

9 files changed

+51
-18
lines changed

contrib/completion/git-completion.bash

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,8 +1712,8 @@ _git_diff ()
17121712
}
17131713

17141714
__git_mergetools_common="diffuse diffmerge ecmerge emerge kdiff3 meld opendiff
1715-
tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc
1716-
codecompare smerge
1715+
tkdiff vimdiff nvimdiff gvimdiff xxdiff araxis p4merge
1716+
bc codecompare smerge
17171717
"
17181718

17191719
_git_difftool ()

git-mergetool--lib.sh

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,14 @@ show_tool_names () {
4343

4444
shown_any=
4545
( cd "$MERGE_TOOLS_DIR" && ls ) | {
46-
while read toolname
46+
while read scriptname
47+
do
48+
setup_tool "$scriptname" 2>/dev/null
49+
variants="$variants$(list_tool_variants)\n"
50+
done
51+
variants="$(echo "$variants" | sort | uniq)"
52+
53+
for toolname in $variants
4754
do
4855
if setup_tool "$toolname" 2>/dev/null &&
4956
(eval "$condition" "$toolname")
@@ -157,6 +164,10 @@ setup_tool () {
157164
echo "$1"
158165
}
159166

167+
list_tool_variants () {
168+
echo "$tool"
169+
}
170+
160171
# Most tools' exit codes cannot be trusted, so By default we ignore
161172
# their exit code and check the merged file's modification time in
162173
# check_unchanged() to determine whether or not the merge was
@@ -178,19 +189,26 @@ setup_tool () {
178189
false
179190
}
180191

181-
182-
if ! test -f "$MERGE_TOOLS_DIR/$tool"
192+
if test -f "$MERGE_TOOLS_DIR/$tool"
193+
then
194+
. "$MERGE_TOOLS_DIR/$tool"
195+
elif test -f "$MERGE_TOOLS_DIR/${tool%[0-9]}"
183196
then
197+
. "$MERGE_TOOLS_DIR/${tool%[0-9]}"
198+
else
184199
setup_user_tool
185200
return $?
186201
fi
187202

188-
# Load the redefined functions
189-
. "$MERGE_TOOLS_DIR/$tool"
190203
# Now let the user override the default command for the tool. If
191204
# they have not done so then this will return 1 which we ignore.
192205
setup_user_tool
193206

207+
if ! list_tool_variants | grep -q "^$tool$"
208+
then
209+
return 1
210+
fi
211+
194212
if merge_mode && ! can_merge
195213
then
196214
echo "error: '$tool' can not be used to resolve merges" >&2
@@ -286,11 +304,14 @@ list_merge_tool_candidates () {
286304
tools="$tools smerge"
287305
fi
288306
case "${VISUAL:-$EDITOR}" in
307+
*nvim*)
308+
tools="$tools nvimdiff vimdiff emerge"
309+
;;
289310
*vim*)
290-
tools="$tools vimdiff emerge"
311+
tools="$tools vimdiff nvimdiff emerge"
291312
;;
292313
*)
293-
tools="$tools emerge vimdiff"
314+
tools="$tools emerge vimdiff nvimdiff"
294315
;;
295316
esac
296317
}

mergetools/bc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,8 @@ translate_merge_tool_path() {
2121
echo bcompare
2222
fi
2323
}
24+
25+
list_tool_variants () {
26+
echo bc
27+
echo bc3
28+
}

mergetools/bc3

Lines changed: 0 additions & 1 deletion
This file was deleted.

mergetools/gvimdiff3

Lines changed: 0 additions & 1 deletion
This file was deleted.
File renamed without changes.

mergetools/vimdiff

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ diff_cmd () {
55

66
merge_cmd () {
77
case "$1" in
8-
gvimdiff|vimdiff)
8+
*vimdiff)
99
if $base_present
1010
then
1111
"$merge_tool_path" -f -d -c '4wincmd w | wincmd J' \
@@ -15,11 +15,11 @@ merge_cmd () {
1515
"$LOCAL" "$MERGED" "$REMOTE"
1616
fi
1717
;;
18-
gvimdiff2|vimdiff2)
18+
*vimdiff2)
1919
"$merge_tool_path" -f -d -c 'wincmd l' \
2020
"$LOCAL" "$MERGED" "$REMOTE"
2121
;;
22-
gvimdiff3|vimdiff3)
22+
*vimdiff3)
2323
if $base_present
2424
then
2525
"$merge_tool_path" -f -d -c 'hid | hid | hid' \
@@ -34,10 +34,13 @@ merge_cmd () {
3434

3535
translate_merge_tool_path() {
3636
case "$1" in
37-
gvimdiff|gvimdiff2|gvimdiff3)
37+
nvimdiff*)
38+
echo nvim
39+
;;
40+
gvimdiff*)
3841
echo gvim
3942
;;
40-
vimdiff|vimdiff2|vimdiff3)
43+
vimdiff*)
4144
echo vim
4245
;;
4346
esac
@@ -46,3 +49,11 @@ translate_merge_tool_path() {
4649
exit_code_trustable () {
4750
true
4851
}
52+
53+
list_tool_variants () {
54+
for prefix in '' g n; do
55+
for suffix in '' 2 3; do
56+
echo "${prefix}vimdiff${suffix}"
57+
done
58+
done
59+
}

mergetools/vimdiff2

Lines changed: 0 additions & 1 deletion
This file was deleted.

mergetools/vimdiff3

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)