summaryrefslogtreecommitdiff
path: root/mergetools
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2020-09-22 19:36:29 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-09-22 19:36:29 (GMT)
commit4aff18a3f02fece0d758427294907e7a80aa6bff (patch)
treede8be4d77f8537e8b1d745e8bf97891feec42359 /mergetools
parent458205ff0f43f8f0ffe70aa7f06d314fcce25809 (diff)
parentdbd8c09bfe9d783ae01121bafb26a2dd108c0c3f (diff)
downloadgit-4aff18a3f02fece0d758427294907e7a80aa6bff.zip
git-4aff18a3f02fece0d758427294907e7a80aa6bff.tar.gz
git-4aff18a3f02fece0d758427294907e7a80aa6bff.tar.bz2
Merge branch 'ls/mergetool-meld-auto-merge'
The 'meld' backend of the "git mergetool" learned to give the underlying 'meld' the '--auto-merge' option, which would help reduce the amount of text that requires manual merging. * ls/mergetool-meld-auto-merge: mergetool: allow auto-merge for meld to follow the vim-diff behavior
Diffstat (limited to 'mergetools')
-rw-r--r--mergetools/meld85
1 files changed, 69 insertions, 16 deletions
diff --git a/mergetools/meld b/mergetools/meld
index 7a08470..aab4ebb 100644
--- a/mergetools/meld
+++ b/mergetools/meld
@@ -3,34 +3,87 @@ diff_cmd () {
}
merge_cmd () {
- if test -z "${meld_has_output_option:+set}"
+ check_meld_for_features
+
+ option_auto_merge=
+ if test "$meld_use_auto_merge_option" = true
then
- check_meld_for_output_version
+ option_auto_merge="--auto-merge"
fi
if test "$meld_has_output_option" = true
then
- "$merge_tool_path" --output="$MERGED" \
+ "$merge_tool_path" $option_auto_merge --output="$MERGED" \
"$LOCAL" "$BASE" "$REMOTE"
else
- "$merge_tool_path" "$LOCAL" "$MERGED" "$REMOTE"
+ "$merge_tool_path" $option_auto_merge "$LOCAL" "$MERGED" "$REMOTE"
fi
}
-# Check whether we should use 'meld --output <file>'
-check_meld_for_output_version () {
- meld_path="$(git config mergetool.meld.path)"
- meld_path="${meld_path:-meld}"
+# Get meld help message
+init_meld_help_msg () {
+ if test -z "$meld_help_msg"
+ then
+ meld_path="$(git config mergetool.meld.path || echo meld)"
+ meld_help_msg=$("$meld_path" --help 2>&1)
+ fi
+}
- if meld_has_output_option=$(git config --bool mergetool.meld.hasOutput)
+# Check the features and set flags
+check_meld_for_features () {
+ # Check whether we should use 'meld --output <file>'
+ if test -z "$meld_has_output_option"
then
- : use configured value
- elif "$meld_path" --help 2>&1 |
- grep -e '--output=' -e '\[OPTION\.\.\.\]' >/dev/null
+ meld_has_output_option=$(git config --bool mergetool.meld.hasOutput)
+ case "$meld_has_output_option" in
+ true | false)
+ : use configured value
+ ;;
+ *)
+ : empty or invalid configured value, detecting "--output" automatically
+ init_meld_help_msg
+
+ case "$meld_help_msg" in
+ *"--output="* | *'[OPTION...]'*)
+ # All version that has [OPTION...] supports --output
+ meld_has_output_option=true
+ ;;
+ *)
+ meld_has_output_option=false
+ ;;
+ esac
+ ;;
+ esac
+ fi
+ # Check whether we should use 'meld --auto-merge ...'
+ if test -z "$meld_use_auto_merge_option"
then
- : old ones mention --output and new ones just say OPTION...
- meld_has_output_option=true
- else
- meld_has_output_option=false
+ meld_use_auto_merge_option=$(
+ git config --bool-or-str mergetool.meld.useAutoMerge
+ )
+ case "$meld_use_auto_merge_option" in
+ true | false)
+ : use well formatted boolean value
+ ;;
+ auto)
+ # testing the "--auto-merge" option only if config is "auto"
+ init_meld_help_msg
+
+ case "$meld_help_msg" in
+ *"--auto-merge"* | *'[OPTION...]'*)
+ meld_use_auto_merge_option=true
+ ;;
+ *)
+ meld_use_auto_merge_option=false
+ ;;
+ esac
+ ;;
+ "")
+ meld_use_auto_merge_option=false
+ ;;
+ *)
+ die "unknown mergetool.meld.useAutoMerge: $meld_use_auto_merge_option"
+ ;;
+ esac
fi
}