Skip to content

Commit 7da5fd6

Browse files
committed
Merge branch 'da/pull-ff-configuration'
"git pull" learned to pay attention to pull.ff configuration variable. * da/pull-ff-configuration: pull: add --ff-only to the help text pull: add pull.ff configuration
2 parents d637d1b + ef93e3a commit 7da5fd6

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

Documentation/config.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1889,6 +1889,16 @@ pretty.<name>::
18891889
Note that an alias with the same name as a built-in format
18901890
will be silently ignored.
18911891

1892+
pull.ff::
1893+
By default, Git does not create an extra merge commit when merging
1894+
a commit that is a descendant of the current commit. Instead, the
1895+
tip of the current branch is fast-forwarded. When set to `false`,
1896+
this variable tells Git to create an extra merge commit in such
1897+
a case (equivalent to giving the `--no-ff` option from the command
1898+
line). When set to `only`, only such fast-forward merges are
1899+
allowed (equivalent to giving the `--ff-only` option from the
1900+
command line).
1901+
18921902
pull.rebase::
18931903
When true, rebase branches on top of the fetched branch, instead
18941904
of merging the default branch from the default remote when "git

git-pull.sh

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
# Fetch one or more remote refs and merge it/them into the current HEAD.
66

7-
USAGE='[-n | --no-stat] [--[no-]commit] [--[no-]squash] [--[no-]ff] [--[no-]rebase|--rebase=preserve] [-s strategy]... [<fetch-options>] <repo> <head>...'
7+
USAGE='[-n | --no-stat] [--[no-]commit] [--[no-]squash] [--[no-]ff|--ff-only] [--[no-]rebase|--rebase=preserve] [-s strategy]... [<fetch-options>] <repo> <head>...'
88
LONG_USAGE='Fetch one or more remote refs and integrate it/them with the current HEAD.'
99
SUBDIRECTORY_OK=Yes
1010
OPTIONS_SPEC=
@@ -52,6 +52,21 @@ if test -z "$rebase"
5252
then
5353
rebase=$(bool_or_string_config pull.rebase)
5454
fi
55+
56+
# Setup default fast-forward options via `pull.ff`
57+
pull_ff=$(git config pull.ff)
58+
case "$pull_ff" in
59+
false)
60+
no_ff=--no-ff
61+
break
62+
;;
63+
only)
64+
ff_only=--ff-only
65+
break
66+
;;
67+
esac
68+
69+
5570
dry_run=
5671
while :
5772
do

t/t7601-merge-pull-config.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,27 @@ test_expect_success 'merge c1 with c2' '
3838
test -f c2.c
3939
'
4040

41+
test_expect_success 'fast-forward pull succeeds with "true" in pull.ff' '
42+
git reset --hard c0 &&
43+
test_config pull.ff true &&
44+
git pull . c1 &&
45+
test "$(git rev-parse HEAD)" = "$(git rev-parse c1)"
46+
'
47+
48+
test_expect_success 'fast-forward pull creates merge with "false" in pull.ff' '
49+
git reset --hard c0 &&
50+
test_config pull.ff false &&
51+
git pull . c1 &&
52+
test "$(git rev-parse HEAD^1)" = "$(git rev-parse c0)" &&
53+
test "$(git rev-parse HEAD^2)" = "$(git rev-parse c1)"
54+
'
55+
56+
test_expect_success 'pull prevents non-fast-forward with "only" in pull.ff' '
57+
git reset --hard c1 &&
58+
test_config pull.ff only &&
59+
test_must_fail git pull . c3
60+
'
61+
4162
test_expect_success 'merge c1 with c2 (ours in pull.twohead)' '
4263
git reset --hard c1 &&
4364
git config pull.twohead ours &&

0 commit comments

Comments
 (0)