Merge branch 'ab/grep-pcre2-allocfix'
[git] / mergetools / meld
1 diff_cmd () {
2         "$merge_tool_path" "$LOCAL" "$REMOTE"
3 }
4
5 merge_cmd () {
6         check_meld_for_features
7
8         option_auto_merge=
9         if test "$meld_use_auto_merge_option" = true
10         then
11                 option_auto_merge="--auto-merge"
12         fi
13
14         if test "$meld_has_output_option" = true
15         then
16                 "$merge_tool_path" $option_auto_merge --output="$MERGED" \
17                         "$LOCAL" "$BASE" "$REMOTE"
18         else
19                 "$merge_tool_path" $option_auto_merge "$LOCAL" "$MERGED" "$REMOTE"
20         fi
21 }
22
23 # Get meld help message
24 init_meld_help_msg () {
25         if test -z "$meld_help_msg"
26         then
27                 meld_path="$(git config mergetool.meld.path || echo meld)"
28                 meld_help_msg=$("$meld_path" --help 2>&1)
29         fi
30 }
31
32 # Check the features and set flags
33 check_meld_for_features () {
34         # Check whether we should use 'meld --output <file>'
35         if test -z "$meld_has_output_option"
36         then
37                 meld_has_output_option=$(git config --bool mergetool.meld.hasOutput)
38                 case "$meld_has_output_option" in
39                 true | false)
40                         : use configured value
41                         ;;
42                 *)
43                         : empty or invalid configured value, detecting "--output" automatically
44                         init_meld_help_msg
45
46                         case "$meld_help_msg" in
47                         *"--output="* | *'[OPTION...]'*)
48                                 # All version that has [OPTION...] supports --output
49                                 meld_has_output_option=true
50                                 ;;
51                         *)
52                                 meld_has_output_option=false
53                                 ;;
54                         esac
55                         ;;
56                 esac
57         fi
58         # Check whether we should use 'meld --auto-merge ...'
59         if test -z "$meld_use_auto_merge_option"
60         then
61                 meld_use_auto_merge_option=$(
62                         git config --bool-or-str mergetool.meld.useAutoMerge
63                 )
64                 case "$meld_use_auto_merge_option" in
65                 true | false)
66                         : use well formatted boolean value
67                         ;;
68                 auto)
69                         # testing the "--auto-merge" option only if config is "auto"
70                         init_meld_help_msg
71
72                         case "$meld_help_msg" in
73                         *"--auto-merge"* | *'[OPTION...]'*)
74                                 meld_use_auto_merge_option=true
75                                 ;;
76                         *)
77                                 meld_use_auto_merge_option=false
78                                 ;;
79                         esac
80                         ;;
81                 "")
82                         meld_use_auto_merge_option=false
83                         ;;
84                 *)
85                         die "unknown mergetool.meld.useAutoMerge: $meld_use_auto_merge_option"
86                         ;;
87                 esac
88         fi
89 }