mergetool--lib: Make style consistent with git
Use the predominant conditional style where "then" appears alone on the line after the test expression. Remove spaces after ">" output redirections. Remove unnecessary parentheses around the kdiff3 commands. Signed-off-by: David Aguilar <davvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
David Aguilar committed
Aug 18, 2011 at 00:23 UTC
240dc3e8edb3ae4ee968febc006fa761811c60e6
1 file changed
+100
-53
git-mergetool--lib.sh
+100
-53
@@ -32,10 +32,12 @@ translate_merge_tool_path () {
32
}
33
34
check_unchanged () {
35
- if test "$MERGED" -nt "$BACKUP"; then
35
+ if test "$MERGED" -nt "$BACKUP"
36
+ then
37
status=0
38
else
38
- while true; do
39
+ while true
40
+ do
41
echo "$MERGED seems unchanged."
42
printf "Was the merge successful? [y/n] "
43
read answer
@@ -53,17 +55,20 @@ valid_tool () {
55
kdiff3 | meld | opendiff | p4merge | tkdiff | vimdiff | vimdiff2 | xxdiff)
56
;; # happy
57
kompare)
56
- if ! diff_mode; then
58
+ if ! diff_mode
59
+ then
60
return 1
61
fi
62
;;
63
tortoisemerge)
61
- if ! merge_mode; then
64
+ if ! merge_mode
65
+ then
66
return 1
67
fi
68
;;
69
*)
66
- if test -z "$(get_merge_tool_cmd "$1")"; then
70
+ if test -z "$(get_merge_tool_cmd "$1")"
71
+ then
72
return 1
73
fi
74
;;
@@ -72,12 +77,14 @@ valid_tool () {
77
78
get_merge_tool_cmd () {
79
# Prints the custom command for a merge tool
75
- if test -n "$1"; then
80
+ if test -n "$1"
81
+ then
82
merge_tool="$1"
83
else
84
merge_tool="$(get_merge_tool)"
85
fi
80
- if diff_mode; then
86
+ if diff_mode
87
+ then
88
echo "$(git config difftool.$merge_tool.cmd ||
89
git config mergetool.$merge_tool.cmd)"
90
else
@@ -97,9 +104,11 @@ run_merge_tool () {
104
105
case "$1" in
106
araxis)
100
- if merge_mode; then
107
+ if merge_mode
108
+ then
109
touch "$BACKUP"
102
- if $base_present; then
110
+ if $base_present
111
+ then
112
"$merge_tool_path" -wait -merge -3 -a1 \
113
"$BASE" "$LOCAL" "$REMOTE" "$MERGED" \
114
>/dev/null 2>&1
@@ -115,9 +124,11 @@ run_merge_tool () {
124
fi
125
;;
126
bc3)
118
- if merge_mode; then
127
+ if merge_mode
128
+ then
129
touch "$BACKUP"
120
- if $base_present; then
130
+ if $base_present
131
+ then
132
"$merge_tool_path" "$LOCAL" "$REMOTE" "$BASE" \
133
-mergeoutput="$MERGED"
134
else
@@ -130,9 +141,11 @@ run_merge_tool () {
141
fi
142
;;
143
diffuse)
133
- if merge_mode; then
144
+ if merge_mode
145
+ then
146
touch "$BACKUP"
135
- if $base_present; then
147
+ if $base_present
148
+ then
149
"$merge_tool_path" \
150
"$LOCAL" "$MERGED" "$REMOTE" \
151
"$BASE" | cat
@@ -146,9 +159,11 @@ run_merge_tool () {
159
fi
160
;;
161
ecmerge)
149
- if merge_mode; then
162
+ if merge_mode
163
+ then
164
touch "$BACKUP"
151
- if $base_present; then
165
+ if $base_present
166
+ then
167
"$merge_tool_path" "$BASE" "$LOCAL" "$REMOTE" \
168
--default --mode=merge3 --to="$MERGED"
169
else
@@ -162,8 +177,10 @@ run_merge_tool () {
177
fi
178
;;
179
emerge)
165
- if merge_mode; then
166
- if $base_present; then
180
+ if merge_mode
181
+ then
182
+ if $base_present
183
+ then
184
"$merge_tool_path" \
185
-f emerge-files-with-ancestor-command \
186
"$LOCAL" "$REMOTE" "$BASE" \
@@ -181,9 +198,11 @@ run_merge_tool () {
198
fi
199
;;
200
gvimdiff|vimdiff)
184
- if merge_mode; then
201
+ if merge_mode
202
+ then
203
touch "$BACKUP"
186
- if $base_present; then
204
+ if $base_present
205
+ then
206
"$merge_tool_path" -f -d -c "wincmd J" \
207
"$MERGED" "$LOCAL" "$BASE" "$REMOTE"
208
else
@@ -198,7 +217,8 @@ run_merge_tool () {
217
fi
218
;;
219
gvimdiff2|vimdiff2)
201
- if merge_mode; then
220
+ if merge_mode
221
+ then
222
touch "$BACKUP"
223
"$merge_tool_path" -f -d -c "wincmd l" \
224
"$LOCAL" "$MERGED" "$REMOTE"
@@ -210,36 +230,39 @@ run_merge_tool () {
230
fi
231
;;
232
kdiff3)
213
- if merge_mode; then
214
- if $base_present; then
215
- ("$merge_tool_path" --auto \
233
+ if merge_mode
234
+ then
235
+ if $base_present
236
+ then
237
+ "$merge_tool_path" --auto \
238
--L1 "$MERGED (Base)" \
239
--L2 "$MERGED (Local)" \
240
--L3 "$MERGED (Remote)" \
241
-o "$MERGED" \
242
"$BASE" "$LOCAL" "$REMOTE" \
221
- > /dev/null 2>&1)
243
+ >/dev/null 2>&1
244
else
223
- ("$merge_tool_path" --auto \
245
+ "$merge_tool_path" --auto \
246
--L1 "$MERGED (Local)" \
247
--L2 "$MERGED (Remote)" \
248
-o "$MERGED" \
249
"$LOCAL" "$REMOTE" \
228
- > /dev/null 2>&1)
250
+ >/dev/null 2>&1
251
fi
252
status=$?
253
else
232
- ("$merge_tool_path" --auto \
254
+ "$merge_tool_path" --auto \
255
--L1 "$MERGED (A)" \
256
--L2 "$MERGED (B)" "$LOCAL" "$REMOTE" \
235
- > /dev/null 2>&1)
257
+ >/dev/null 2>&1
258
fi
259
;;
260
kompare)
261
"$merge_tool_path" "$LOCAL" "$REMOTE"
262
;;
263
meld)
242
- if merge_mode; then
264
+ if merge_mode
265
+ then
266
touch "$BACKUP"
267
"$merge_tool_path" "$LOCAL" "$MERGED" "$REMOTE"
268
check_unchanged
@@ -248,9 +271,11 @@ run_merge_tool () {
271
fi
272
;;
273
opendiff)
251
- if merge_mode; then
274
+ if merge_mode
275
+ then
276
touch "$BACKUP"
253
- if $base_present; then
277
+ if $base_present
278
+ then
279
"$merge_tool_path" "$LOCAL" "$REMOTE" \
280
-ancestor "$BASE" \
281
-merge "$MERGED" | cat
@@ -264,7 +289,8 @@ run_merge_tool () {
289
fi
290
;;
291
p4merge)
267
- if merge_mode; then
292
+ if merge_mode
293
+ then
294
touch "$BACKUP"
295
$base_present || >"$BASE"
296
"$merge_tool_path" "$BASE" "$LOCAL" "$REMOTE" "$MERGED"
@@ -274,8 +300,10 @@ run_merge_tool () {
300
fi
301
;;
302
tkdiff)
277
- if merge_mode; then
278
- if $base_present; then
303
+ if merge_mode
304
+ then
305
+ if $base_present
306
+ then
307
"$merge_tool_path" -a "$BASE" \
308
-o "$MERGED" "$LOCAL" "$REMOTE"
309
else
@@ -288,7 +316,8 @@ run_merge_tool () {
316
fi
317
;;
318
tortoisemerge)
291
- if $base_present; then
319
+ if $base_present
320
+ then
321
touch "$BACKUP"
322
"$merge_tool_path" \
323
-base:"$BASE" -mine:"$LOCAL" \
@@ -300,9 +329,11 @@ run_merge_tool () {
329
fi
330
;;
331
xxdiff)
303
- if merge_mode; then
332
+ if merge_mode
333
+ then
334
touch "$BACKUP"
305
- if $base_present; then
335
+ if $base_present
336
+ then
337
"$merge_tool_path" -X --show-merged-pane \
338
-R 'Accel.SaveAsMerged: "Ctrl-S"' \
339
-R 'Accel.Search: "Ctrl+F"' \
@@ -327,16 +358,20 @@ run_merge_tool () {
358
;;
359
*)
360
merge_tool_cmd="$(get_merge_tool_cmd "$1")"
330
- if test -z "$merge_tool_cmd"; then
331
- if merge_mode; then
361
+ if test -z "$merge_tool_cmd"
362
+ then
363
+ if merge_mode
364
+ then
365
status=1
366
fi
367
break
368
fi
336
- if merge_mode; then
369
+ if merge_mode
370
+ then
371
trust_exit_code="$(git config --bool \
372
mergetool."$1".trustExitCode || echo false)"
339
- if test "$trust_exit_code" = "false"; then
373
+ if test "$trust_exit_code" = "false"
374
+ then
375
touch "$BACKUP"
376
( eval $merge_tool_cmd )
377
check_unchanged
@@ -353,13 +388,16 @@ run_merge_tool () {
388
}
389
390
guess_merge_tool () {
356
- if merge_mode; then
391
+ if merge_mode
392
+ then
393
tools="tortoisemerge"
394
else
395
tools="kompare"
396
fi
361
- if test -n "$DISPLAY"; then
362
- if test -n "$GNOME_DESKTOP_SESSION_ID" ; then
397
+ if test -n "$DISPLAY"
398
+ then
399
+ if test -n "$GNOME_DESKTOP_SESSION_ID"
400
+ then
401
tools="meld opendiff kdiff3 tkdiff xxdiff $tools"
402
else
403
tools="opendiff kdiff3 tkdiff xxdiff meld $tools"
@@ -380,7 +418,8 @@ guess_merge_tool () {
418
for i in $tools
419
do
420
merge_tool_path="$(translate_merge_tool_path "$i")"
383
- if type "$merge_tool_path" > /dev/null 2>&1; then
421
+ if type "$merge_tool_path" >/dev/null 2>&1
422
+ then
423
echo "$i"
424
return 0
425
fi
@@ -393,12 +432,14 @@ guess_merge_tool () {
432
get_configured_merge_tool () {
433
# Diff mode first tries diff.tool and falls back to merge.tool.
434
# Merge mode only checks merge.tool
396
- if diff_mode; then
435
+ if diff_mode
436
+ then
437
merge_tool=$(git config diff.tool || git config merge.tool)
438
else
439
merge_tool=$(git config merge.tool)
440
fi
401
- if test -n "$merge_tool" && ! valid_tool "$merge_tool"; then
441
+ if test -n "$merge_tool" && ! valid_tool "$merge_tool"
442
+ then
443
echo >&2 "git config option $TOOL_MODE.tool set to unknown tool: $merge_tool"
444
echo >&2 "Resetting to default..."
445
return 1
@@ -408,26 +449,31 @@ get_configured_merge_tool () {
449
450
get_merge_tool_path () {
451
# A merge tool has been set, so verify that it's valid.
411
- if test -n "$1"; then
452
+ if test -n "$1"
453
+ then
454
merge_tool="$1"
455
else
456
merge_tool="$(get_merge_tool)"
457
fi
416
- if ! valid_tool "$merge_tool"; then
458
+ if ! valid_tool "$merge_tool"
459
+ then
460
echo >&2 "Unknown merge tool $merge_tool"
461
exit 1
462
fi
420
- if diff_mode; then
463
+ if diff_mode
464
+ then
465
merge_tool_path=$(git config difftool."$merge_tool".path ||
466
git config mergetool."$merge_tool".path)
467
else
468
merge_tool_path=$(git config mergetool."$merge_tool".path)
469
fi
426
- if test -z "$merge_tool_path"; then
470
+ if test -z "$merge_tool_path"
471
+ then
472
merge_tool_path="$(translate_merge_tool_path "$merge_tool")"
473
fi
474
if test -z "$(get_merge_tool_cmd "$merge_tool")" &&
430
- ! type "$merge_tool_path" > /dev/null 2>&1; then
475
+ ! type "$merge_tool_path" >/dev/null 2>&1
476
+ then
477
echo >&2 "The $TOOL_MODE tool $merge_tool is not available as"\
478
"'$merge_tool_path'"
479
exit 1
@@ -439,7 +485,8 @@ get_merge_tool () {
485
# Check if a merge tool has been configured
486
merge_tool=$(get_configured_merge_tool)
487
# Try to guess an appropriate merge tool if no tool has been set.
442
- if test -z "$merge_tool"; then
488
+ if test -z "$merge_tool"
489
+ then
490
merge_tool="$(guess_merge_tool)" || exit
491
fi
492
echo "$merge_tool"