Skip to content

Commit 05fb872

Browse files
Denton-Lgitster
authored andcommitted
mergetool: use get_merge_tool function
In git-mergetool, the logic for getting which merge tool to use is duplicated in git-mergetool--lib, except for the fact that it needs to know whether the tool was guessed or not. Rewrite `get_merge_tool` to return whether or not the tool was guessed through the return code and make git-mergetool call this function instead of duplicating the logic. Note that 1 was chosen to be the return code of when a tool is guessed because it seems like a slightly more abnormal condition than getting a tool that's explicitly specified but this is completely arbitrary. Also, let `$GIT_MERGETOOL_GUI` be set to determine whether or not the guitool will be selected. This change is not completely backwards compatible as there may be external users of git-mergetool--lib. However, only one user, git-diffall[1], was found from searching GitHub and Google, and this tool is superseded by `git difftool --dir-diff` anyway. It seems very unlikely that there exists an external caller that would take into account the return code of `get_merge_tool` as it would always return 0 before this change so this change probably does not affect any external users. [1]: https://github.com/thenigan/git-diffall Signed-off-by: Denton Liu <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 57d93c1 commit 05fb872

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

Documentation/git-mergetool--lib.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ to define the operation mode for the functions listed below.
2828
FUNCTIONS
2929
---------
3030
get_merge_tool::
31-
returns a merge tool.
31+
returns a merge tool. the return code is 1 if we returned a guessed
32+
merge tool, else 0. '$GIT_MERGETOOL_GUI' may be set to 'true' to
33+
search for the appropriate guitool.
3234

3335
get_merge_tool_cmd::
3436
returns the custom command for a merge tool.

git-difftool--helper.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ then
7171
then
7272
merge_tool="$GIT_DIFF_TOOL"
7373
else
74-
merge_tool="$(get_merge_tool)" || exit
74+
merge_tool="$(get_merge_tool)"
7575
fi
7676
fi
7777

git-mergetool--lib.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,14 +403,17 @@ get_merge_tool_path () {
403403
}
404404

405405
get_merge_tool () {
406+
is_guessed=false
406407
# Check if a merge tool has been configured
407-
merge_tool=$(get_configured_merge_tool)
408+
merge_tool=$(get_configured_merge_tool $GIT_MERGETOOL_GUI)
408409
# Try to guess an appropriate merge tool if no tool has been set.
409410
if test -z "$merge_tool"
410411
then
411412
merge_tool=$(guess_merge_tool) || exit
413+
is_guessed=true
412414
fi
413415
echo "$merge_tool"
416+
test "$is_guessed" = false
414417
}
415418

416419
mergetool_find_win32_cmd () {

git-mergetool.sh

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ print_noop_and_exit () {
389389

390390
main () {
391391
prompt=$(git config --bool mergetool.prompt)
392-
gui_tool=false
392+
GIT_MERGETOOL_GUI=false
393393
guessed_merge_tool=false
394394
orderfile=
395395

@@ -416,10 +416,10 @@ main () {
416416
esac
417417
;;
418418
--no-gui)
419-
gui_tool=false
419+
GIT_MERGETOOL_GUI=false
420420
;;
421421
-g|--gui)
422-
gui_tool=true
422+
GIT_MERGETOOL_GUI=true
423423
;;
424424
-y|--no-prompt)
425425
prompt=false
@@ -449,12 +449,8 @@ main () {
449449

450450
if test -z "$merge_tool"
451451
then
452-
# Check if a merge tool has been configured
453-
merge_tool=$(get_configured_merge_tool $gui_tool)
454-
# Try to guess an appropriate merge tool if no tool has been set.
455-
if test -z "$merge_tool"
452+
if ! merge_tool=$(get_merge_tool)
456453
then
457-
merge_tool=$(guess_merge_tool) || exit
458454
guessed_merge_tool=true
459455
fi
460456
fi

0 commit comments

Comments
 (0)