git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Aguilar <davvid@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: [PATCH 1/2] pull: add pull.ff configuration
Date: Wed, 15 Jan 2014 15:18:38 -0800	[thread overview]
Message-ID: <1389827919-13608-1-git-send-email-davvid@gmail.com> (raw)

Add a `pull.ff` configuration option that is analogous
to the `merge.ff` option.

This allows us to control the fast-forward behavior for
pull-initiated merges only.

Signed-off-by: David Aguilar <davvid@gmail.com>
---
 Documentation/config.txt     | 10 ++++++++++
 git-pull.sh                  | 15 +++++++++++++++
 t/t7601-merge-pull-config.sh | 21 +++++++++++++++++++++
 3 files changed, 46 insertions(+)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index ed59853..23b0016 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1881,6 +1881,16 @@ pretty.<name>::
 	Note that an alias with the same name as a built-in format
 	will be silently ignored.
 
+pull.ff::
+	By default, Git does not create an extra merge commit when merging
+	a commit that is a descendant of the current commit. Instead, the
+	tip of the current branch is fast-forwarded. When set to `false`,
+	this variable tells Git to create an extra merge commit in such
+	a case (equivalent to giving the `--no-ff` option from the command
+	line). When set to `only`, only such fast-forward merges are
+	allowed (equivalent to giving the `--ff-only` option from the
+	command line).
+
 pull.rebase::
 	When true, rebase branches on top of the fetched branch, instead
 	of merging the default branch from the default remote when "git
diff --git a/git-pull.sh b/git-pull.sh
index f210d0a..7dbf6b1 100755
--- a/git-pull.sh
+++ b/git-pull.sh
@@ -52,6 +52,21 @@ if test -z "$rebase"
 then
 	rebase=$(bool_or_string_config pull.rebase)
 fi
+
+# Setup default fast-forward options via `pull.ff`
+pull_ff=$(git config pull.ff)
+case "$pull_ff" in
+false)
+	no_ff=--no-ff
+	break
+	;;
+only)
+	ff_only=--ff-only
+	break
+	;;
+esac
+
+
 dry_run=
 while :
 do
diff --git a/t/t7601-merge-pull-config.sh b/t/t7601-merge-pull-config.sh
index 830a4c3..f768c90 100755
--- a/t/t7601-merge-pull-config.sh
+++ b/t/t7601-merge-pull-config.sh
@@ -38,6 +38,27 @@ test_expect_success 'merge c1 with c2' '
 	test -f c2.c
 '
 
+test_expect_success 'fast-forward pull succeeds with "true" in pull.ff' '
+	git reset --hard c0 &&
+	test_config pull.ff true &&
+	git pull . c1 &&
+	test "$(git rev-parse HEAD)" = "$(git rev-parse c1)"
+'
+
+test_expect_success 'fast-forward pull creates merge with "false" in pull.ff' '
+	git reset --hard c0 &&
+	test_config pull.ff false &&
+	git pull . c1 &&
+	test "$(git rev-parse HEAD^1)" = "$(git rev-parse c0)" &&
+	test "$(git rev-parse HEAD^2)" = "$(git rev-parse c1)"
+'
+
+test_expect_success 'pull prevents non-fast-forward with "only" in pull.ff' '
+	git reset --hard c1 &&
+	test_config pull.ff only &&
+	test_must_fail git pull . c3
+'
+
 test_expect_success 'merge c1 with c2 (ours in pull.twohead)' '
 	git reset --hard c1 &&
 	git config pull.twohead ours &&
-- 
1.8.5.3.322.g71d2a99

             reply	other threads:[~2014-01-15 23:18 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-15 23:18 David Aguilar [this message]
2014-01-15 23:18 ` [PATCH 2/2] pull: add --ff-only to the help text David Aguilar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1389827919-13608-1-git-send-email-davvid@gmail.com \
    --to=davvid@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).