@matheusbsbs / matheus-bagliano / commits / aec7b362ad
Fork 0

git-merge: add support for branch.<name>.mergeoptions

This enables per branch configuration of merge options. Currently, the most useful options to specify per branch are --squash, --summary/--no-summary and possibly --strategy, but all options are supported. Note: Options containing whitespace will _not_ be handled correctly. Luckily, the only option which can include whitespace is --message and it doesn't make much sense to give that option a default value. Signed-off-by: Lars Hjemli <hjemli@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Lars Hjemli committed Sep 24, 2007 at 00:51 UTC aec7b362ad07e1a2c58051c8db653dabffee8960
4 files changed +85
Documentation/config.txt
+6
@@ -337,6 +337,12 @@ branch.<name>.merge::
337 branch.<name>.merge to the desired branch, and use the special setting
338 `.` (a period) for branch.<name>.remote.
339
340 +branch.<name>.mergeoptions::
341 + Sets default options for merging into branch <name>. The syntax and
342 + supported options are equal to that of gitlink:git-merge[1], but
343 + option values containing whitespace characters are currently not
344 + supported.
345 +
346 clean.requireForce::
347 A boolean to make git-clean do nothing unless given -f or -n. Defaults
348 to false.
Documentation/git-merge.txt
+4
@@ -58,6 +58,10 @@ merge.verbosity::
58 above outputs debugging information. The default is level 2.
59 Can be overriden by 'GIT_MERGE_VERBOSITY' environment variable.
60
61 +branch.<name>.mergeoptions::
62 + Sets default options for merging into branch <name>. The syntax and
63 + supported options are equal to that of git-merge, but option values
64 + containing whitespace characters are currently not supported.
65
66 HOW MERGE WORKS
67 ---------------
git-merge.sh
+21
@@ -168,9 +168,30 @@ parse_option () {
168 args_left=$#
169 }
170
171 +parse_config () {
172 + while test $# -gt 0
173 + do
174 + parse_option "$@" || usage
175 + while test $args_left -lt $#
176 + do
177 + shift
178 + done
179 + done
180 +}
181 +
182 test $# != 0 || usage
183
184 have_message=
185 +
186 +if branch=$(git-symbolic-ref -q HEAD)
187 +then
188 + mergeopts=$(git config "branch.${branch#refs/heads/}.mergeoptions")
189 + if test -n "$mergeopts"
190 + then
191 + parse_config $mergeopts
192 + fi
193 +fi
194 +
195 while parse_option "$@"
196 do
197 while test $args_left -lt $#
t/t7600-merge.sh
+54
@@ -341,4 +341,58 @@ test_expect_success 'merge c1 with c2 and c3 (squash)' '
341
342 test_debug 'gitk --all'
343
344 +test_expect_success 'merge c1 with c2 (no-commit in config)' '
345 + git reset --hard c1 &&
346 + git config branch.master.mergeoptions "--no-commit" &&
347 + git merge c2 &&
348 + verify_merge file result.1-5 &&
349 + verify_head $c1 &&
350 + verify_mergeheads $c2
351 +'
352 +
353 +test_debug 'gitk --all'
354 +
355 +test_expect_success 'merge c1 with c2 (squash in config)' '
356 + git reset --hard c1 &&
357 + git config branch.master.mergeoptions "--squash" &&
358 + git merge c2 &&
359 + verify_merge file result.1-5 &&
360 + verify_head $c1 &&
361 + verify_no_mergehead &&
362 + verify_diff squash.1-5 .git/SQUASH_MSG "[OOPS] bad squash message"
363 +'
364 +
365 +test_debug 'gitk --all'
366 +
367 +test_expect_success 'override config option -n' '
368 + git reset --hard c1 &&
369 + git config branch.master.mergeoptions "-n" &&
370 + test_tick &&
371 + git merge --summary c2 >diffstat.txt &&
372 + verify_merge file result.1-5 msg.1-5 &&
373 + verify_parents $c1 $c2 &&
374 + if ! grep -e "^ file | \+2 +-$" diffstat.txt
375 + then
376 + echo "[OOPS] diffstat was not generated"
377 + fi
378 +'
379 +
380 +test_debug 'gitk --all'
381 +
382 +test_expect_success 'override config option --summary' '
383 + git reset --hard c1 &&
384 + git config branch.master.mergeoptions "--summary" &&
385 + test_tick &&
386 + git merge -n c2 >diffstat.txt &&
387 + verify_merge file result.1-5 msg.1-5 &&
388 + verify_parents $c1 $c2 &&
389 + if grep -e "^ file | \+2 +-$" diffstat.txt
390 + then
391 + echo "[OOPS] diffstat was generated"
392 + false
393 + fi
394 +'
395 +
396 +test_debug 'gitk --all'
397 +
398 test_done