Skip to content

Commit f23e8de

Browse files
committed
merge: introduce merge.ff configuration variable
This variable gives the default setting for --ff, --no-ff or --ff-only options of "git merge" command. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 541d1fa commit f23e8de

File tree

3 files changed

+60
-2
lines changed

3 files changed

+60
-2
lines changed

Documentation/merge-config.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ merge.defaultToUpstream::
1616
to their corresponding remote tracking branches, and the tips of
1717
these tracking branches are merged.
1818

19+
merge.ff::
20+
By default, git does not create an extra merge commit when merging
21+
a commit that is a descendant of the current commit. Instead, the
22+
tip of the current branch is fast-forwarded. When set to `false`,
23+
this variable tells git to create an extra merge commit in such
24+
a case (equivalent to giving the `--no-ff` option from the command
25+
line). When set to `only`, only such fast-forward merges are
26+
allowed (equivalent to giving the `--ff-only` option from the
27+
command line).
28+
1929
merge.log::
2030
In addition to branch names, populate the log message with at
2131
most the specified number of one-line descriptions from the

builtin/merge.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,15 @@ static int git_merge_config(const char *k, const char *v, void *cb)
550550
if (is_bool && shortlog_len)
551551
shortlog_len = DEFAULT_MERGE_LOG_LEN;
552552
return 0;
553+
} else if (!strcmp(k, "merge.ff")) {
554+
int boolval = git_config_maybe_bool(k, v);
555+
if (0 <= boolval) {
556+
allow_fast_forward = boolval;
557+
} else if (v && !strcmp(v, "only")) {
558+
allow_fast_forward = 1;
559+
fast_forward_only = 1;
560+
} /* do not barf on values from future versions of git */
561+
return 0;
553562
} else if (!strcmp(k, "merge.defaulttoupstream")) {
554563
default_to_upstream = git_config_bool(k, v);
555564
return 0;

t/t7600-merge.sh

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,28 @@ test_expect_success 'merge c1 with c2 and c3' '
225225

226226
test_debug 'git log --graph --decorate --oneline --all'
227227

228-
test_expect_success 'failing merges with --ff-only' '
228+
test_expect_success 'merges with --ff-only' '
229229
git reset --hard c1 &&
230230
test_tick &&
231231
test_must_fail git merge --ff-only c2 &&
232232
test_must_fail git merge --ff-only c3 &&
233-
test_must_fail git merge --ff-only c2 c3
233+
test_must_fail git merge --ff-only c2 c3 &&
234+
git reset --hard c0 &&
235+
git merge c3 &&
236+
verify_head $c3
237+
'
238+
239+
test_expect_success 'merges with merge.ff=only' '
240+
git reset --hard c1 &&
241+
test_tick &&
242+
test_when_finished "git config --unset merge.ff" &&
243+
git config merge.ff only &&
244+
test_must_fail git merge c2 &&
245+
test_must_fail git merge c3 &&
246+
test_must_fail git merge c2 c3 &&
247+
git reset --hard c0 &&
248+
git merge c3 &&
249+
verify_head $c3
234250
'
235251

236252
test_expect_success 'merge c0 with c1 (no-commit)' '
@@ -448,6 +464,29 @@ test_expect_success 'merge c0 with c1 (no-ff)' '
448464

449465
test_debug 'git log --graph --decorate --oneline --all'
450466

467+
test_expect_success 'merge c0 with c1 (merge.ff=false)' '
468+
git reset --hard c0 &&
469+
git config merge.ff false &&
470+
test_tick &&
471+
git merge c1 &&
472+
git config --remove-section merge &&
473+
verify_merge file result.1 &&
474+
verify_parents $c0 $c1
475+
'
476+
test_debug 'git log --graph --decorate --oneline --all'
477+
478+
test_expect_success 'combine branch.master.mergeoptions with merge.ff' '
479+
git reset --hard c0 &&
480+
git config branch.master.mergeoptions --ff
481+
git config merge.ff false
482+
test_tick &&
483+
git merge c1 &&
484+
git config --remove-section "branch.master" &&
485+
git config --remove-section "merge" &&
486+
verify_merge file result.1 &&
487+
verify_parents "$c0"
488+
'
489+
451490
test_expect_success 'combining --squash and --no-ff is refused' '
452491
test_must_fail git merge --squash --no-ff c1 &&
453492
test_must_fail git merge --no-ff --squash c1

0 commit comments

Comments
 (0)