All of lore.kernel.org
 help / color / mirror / Atom feed
From: Felipe Contreras <felipe.contreras@gmail.com>
To: git@vger.kernel.org
Cc: Andreas Krey <a.krey@gmx.de>, John Keeping <john@keeping.me.uk>,
	Felipe Contreras <felipe.contreras@gmail.com>
Subject: [PATCH 3/3] pull: reject non-ff pulls by default
Date: Sat, 31 Aug 2013 17:38:10 -0500	[thread overview]
Message-ID: <1377988690-23460-4-git-send-email-felipe.contreras@gmail.com> (raw)
In-Reply-To: <1377988690-23460-1-git-send-email-felipe.contreras@gmail.com>

For the full discussion:

http://thread.gmane.org/gmane.comp.version-control.git/225146/focus=225305

The user still can specify 'git pull --merge' to restore the old
behavior, or 'git config pull.rebase false'.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 Documentation/git-pull.txt    |  1 +
 builtin/merge.c               |  9 ++++++++-
 git-pull.sh                   |  9 ++++++++-
 t/t5500-fetch-pack.sh         |  2 +-
 t/t5520-pull.sh               | 33 +++++++++++++++++++++++++++++++++
 t/t5524-pull-msg.sh           |  2 +-
 t/t5700-clone-reference.sh    |  4 ++--
 t/t6022-merge-rename.sh       | 20 ++++++++++----------
 t/t6026-merge-attr.sh         |  2 +-
 t/t6029-merge-subtree.sh      |  4 ++--
 t/t6037-merge-ours-theirs.sh  | 10 +++++-----
 t/t7603-merge-reduce-heads.sh |  2 +-
 12 files changed, 73 insertions(+), 25 deletions(-)

diff --git a/Documentation/git-pull.txt b/Documentation/git-pull.txt
index 6ef8d59..1833779 100644
--- a/Documentation/git-pull.txt
+++ b/Documentation/git-pull.txt
@@ -119,6 +119,7 @@ It rewrites history, which does not bode well when you
 published that history already.  Do *not* use this option
 unless you have read linkgit:git-rebase[1] carefully.
 
+--merge::
 --no-rebase::
 	Override earlier --rebase.
 
diff --git a/builtin/merge.c b/builtin/merge.c
index da9fc08..97b4205 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -1437,8 +1437,15 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 		}
 	}
 
-	if (fast_forward == FF_ONLY)
+	if (fast_forward == FF_ONLY) {
+		const char *msg = getenv("GIT_MERGE_FF_ONLY_HELP");
+		if (msg) {
+			fprintf(stderr, "%s\n", msg);
+			ret = 1;
+			goto done;
+		}
 		die(_("Not possible to fast-forward, aborting."));
+	}
 
 	/* We are going to make a new commit. */
 	git_committer_info(IDENT_STRICT);
diff --git a/git-pull.sh b/git-pull.sh
index f0df41c..c6b576b 100755
--- a/git-pull.sh
+++ b/git-pull.sh
@@ -113,7 +113,8 @@ do
 	-r|--r|--re|--reb|--reba|--rebas|--rebase)
 		rebase=true
 		;;
-	--no-r|--no-re|--no-reb|--no-reba|--no-rebas|--no-rebase)
+	--no-r|--no-re|--no-reb|--no-reba|--no-rebas|--no-rebase|\
+	-m|--m|--me|--mer|--merg|--merge)
 		rebase=false
 		;;
 	--recurse-submodules)
@@ -289,6 +290,12 @@ then
 	fi
 fi
 
+if test -z "$rebase$no_ff$ff_only${squash#--no-squash}"
+then
+	ff_only=--ff-only
+	export GIT_MERGE_FF_ONLY_HELP="The pull was not fast-forward, please either merge or rebase."
+fi
+
 merge_name=$(git fmt-merge-msg $log_arg <"$GIT_DIR/FETCH_HEAD") || exit
 case "$rebase" in
 true)
diff --git a/t/t5500-fetch-pack.sh b/t/t5500-fetch-pack.sh
index fd2598e..f1a068f 100755
--- a/t/t5500-fetch-pack.sh
+++ b/t/t5500-fetch-pack.sh
@@ -259,7 +259,7 @@ test_expect_success 'clone shallow object count' '
 test_expect_success 'pull in shallow repo with missing merge base' '
 	(
 		cd shallow &&
-		test_must_fail git pull --depth 4 .. A
+		test_must_fail git pull --merge --depth 4 .. A
 	)
 '
 
diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index ed4d9c8..c0c50a2 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -284,4 +284,37 @@ test_expect_success 'git pull --rebase against local branch' '
 	test file = "$(cat file2)"
 '
 
+test_expect_success 'git pull fast-forward' '
+	test_when_finished "git checkout master && git branch -D other test" &&
+	git checkout -b other master &&
+	>new &&
+	git add new &&
+	git commit -m new &&
+	git checkout -b test -t other &&
+	git reset --hard master &&
+	git pull
+'
+
+test_expect_success 'git pull non-fast-forward' '
+	test_when_finished "git checkout master && git branch -D other test" &&
+	git checkout -b other master^ &&
+	>new &&
+	git add new &&
+	git commit -m new &&
+	git checkout -b test -t other &&
+	git reset --hard master &&
+	test_must_fail git pull
+'
+
+test_expect_success 'git pull non-fast-forward (merge)' '
+	test_when_finished "git checkout master && git branch -D other test" &&
+	git checkout -b other master^ &&
+	>new &&
+	git add new &&
+	git commit -m new &&
+	git checkout -b test -t other &&
+	git reset --hard master &&
+	git pull --merge
+'
+
 test_done
diff --git a/t/t5524-pull-msg.sh b/t/t5524-pull-msg.sh
index 8cccecc..ec9f413 100755
--- a/t/t5524-pull-msg.sh
+++ b/t/t5524-pull-msg.sh
@@ -25,7 +25,7 @@ test_expect_success setup '
 test_expect_success pull '
 (
 	cd cloned &&
-	git pull --log &&
+	git pull --merge --log &&
 	git log -2 &&
 	git cat-file commit HEAD >result &&
 	grep Dollar result
diff --git a/t/t5700-clone-reference.sh b/t/t5700-clone-reference.sh
index 6537911..306badf 100755
--- a/t/t5700-clone-reference.sh
+++ b/t/t5700-clone-reference.sh
@@ -94,7 +94,7 @@ cd "$base_dir"
 
 test_expect_success 'pulling changes from origin' \
 'cd C &&
-git pull origin'
+git pull --merge origin'
 
 cd "$base_dir"
 
@@ -109,7 +109,7 @@ cd "$base_dir"
 
 test_expect_success 'pulling changes from origin' \
 'cd D &&
-git pull origin'
+git pull --merge origin'
 
 cd "$base_dir"
 
diff --git a/t/t6022-merge-rename.sh b/t/t6022-merge-rename.sh
index c680f78..6c7fdc1 100755
--- a/t/t6022-merge-rename.sh
+++ b/t/t6022-merge-rename.sh
@@ -100,7 +100,7 @@ git checkout master'
 test_expect_success 'pull renaming branch into unrenaming one' \
 '
 	git show-branch &&
-	test_expect_code 1 git pull . white &&
+	test_expect_code 1 git pull --merge . white &&
 	git ls-files -s &&
 	git ls-files -u B >b.stages &&
 	test_line_count = 3 b.stages &&
@@ -118,7 +118,7 @@ test_expect_success 'pull renaming branch into another renaming one' \
 	rm -f B &&
 	git reset --hard &&
 	git checkout red &&
-	test_expect_code 1 git pull . white &&
+	test_expect_code 1 git pull --merge . white &&
 	git ls-files -u B >b.stages &&
 	test_line_count = 3 b.stages &&
 	git ls-files -s N >n.stages &&
@@ -134,7 +134,7 @@ test_expect_success 'pull unrenaming branch into renaming one' \
 '
 	git reset --hard &&
 	git show-branch &&
-	test_expect_code 1 git pull . master &&
+	test_expect_code 1 git pull --merge . master &&
 	git ls-files -u B >b.stages &&
 	test_line_count = 3 b.stages &&
 	git ls-files -s N >n.stages &&
@@ -150,7 +150,7 @@ test_expect_success 'pull conflicting renames' \
 '
 	git reset --hard &&
 	git show-branch &&
-	test_expect_code 1 git pull . blue &&
+	test_expect_code 1 git pull --merge . blue &&
 	git ls-files -u A >a.stages &&
 	test_line_count = 1 a.stages &&
 	git ls-files -u B >b.stages &&
@@ -170,7 +170,7 @@ test_expect_success 'interference with untracked working tree file' '
 	git reset --hard &&
 	git show-branch &&
 	echo >A this file should not matter &&
-	test_expect_code 1 git pull . white &&
+	test_expect_code 1 git pull --merge . white &&
 	test_path_is_file A
 '
 
@@ -180,7 +180,7 @@ test_expect_success 'interference with untracked working tree file' '
 	git show-branch &&
 	rm -f A &&
 	echo >A this file should not matter &&
-	test_expect_code 1 git pull . red &&
+	test_expect_code 1 git pull --merge . red &&
 	test_path_is_file A
 '
 
@@ -190,7 +190,7 @@ test_expect_success 'interference with untracked working tree file' '
 	git checkout -f master &&
 	git tag -f anchor &&
 	git show-branch &&
-	git pull . yellow &&
+	git pull --merge . yellow &&
 	test_path_is_missing M &&
 	git reset --hard anchor
 '
@@ -203,7 +203,7 @@ test_expect_success 'updated working tree file should prevent the merge' '
 	git show-branch &&
 	echo >>M one line addition &&
 	cat M >M.saved &&
-	test_expect_code 128 git pull . yellow &&
+	test_expect_code 128 git pull --merge . yellow &&
 	test_cmp M M.saved &&
 	rm -f M.saved
 '
@@ -217,7 +217,7 @@ test_expect_success 'updated working tree file should prevent the merge' '
 	echo >>M one line addition &&
 	cat M >M.saved &&
 	git update-index M &&
-	test_expect_code 128 git pull . yellow &&
+	test_expect_code 128 git pull --merge . yellow &&
 	test_cmp M M.saved &&
 	rm -f M.saved
 '
@@ -229,7 +229,7 @@ test_expect_success 'interference with untracked working tree file' '
 	git tag -f anchor &&
 	git show-branch &&
 	echo >M this file should not matter &&
-	git pull . master &&
+	git pull --merge . master &&
 	test_path_is_file M &&
 	! {
 		git ls-files -s |
diff --git a/t/t6026-merge-attr.sh b/t/t6026-merge-attr.sh
index 5e43997..5428f19 100755
--- a/t/t6026-merge-attr.sh
+++ b/t/t6026-merge-attr.sh
@@ -172,7 +172,7 @@ test_expect_success 'up-to-date merge without common ancestor' '
 	test_tick &&
 	(
 		cd repo1 &&
-		git pull ../repo2 master
+		git pull --merge ../repo2 master
 	)
 '
 
diff --git a/t/t6029-merge-subtree.sh b/t/t6029-merge-subtree.sh
index 73fc240..0eeec04 100755
--- a/t/t6029-merge-subtree.sh
+++ b/t/t6029-merge-subtree.sh
@@ -98,7 +98,7 @@ test_expect_success 'initial ambiguous subtree' '
 test_expect_success 'merge using explicit' '
 	cd ../git &&
 	git reset --hard master2 &&
-	git pull -Xsubtree=git-gui gui master2 &&
+	git pull --merge -Xsubtree=git-gui gui master2 &&
 	git ls-files -s >actual &&
 	(
 		echo "100644 $o3 0	git-gui/git-gui.sh"
@@ -111,7 +111,7 @@ test_expect_success 'merge using explicit' '
 test_expect_success 'merge2 using explicit' '
 	cd ../git &&
 	git reset --hard master2 &&
-	git pull -Xsubtree=git-gui2 gui master2 &&
+	git pull --merge -Xsubtree=git-gui2 gui master2 &&
 	git ls-files -s >actual &&
 	(
 		echo "100644 $o1 0	git-gui/git-gui.sh"
diff --git a/t/t6037-merge-ours-theirs.sh b/t/t6037-merge-ours-theirs.sh
index 3889eca..927e67c 100755
--- a/t/t6037-merge-ours-theirs.sh
+++ b/t/t6037-merge-ours-theirs.sh
@@ -66,11 +66,11 @@ test_expect_success 'binary file with -Xours/-Xtheirs' '
 '
 
 test_expect_success 'pull passes -X to underlying merge' '
-	git reset --hard master && git pull -s recursive -Xours . side &&
-	git reset --hard master && git pull -s recursive -X ours . side &&
-	git reset --hard master && git pull -s recursive -Xtheirs . side &&
-	git reset --hard master && git pull -s recursive -X theirs . side &&
-	git reset --hard master && test_must_fail git pull -s recursive -X bork . side
+	git reset --hard master && git pull --merge -s recursive -Xours . side &&
+	git reset --hard master && git pull --merge -s recursive -X ours . side &&
+	git reset --hard master && git pull --merge -s recursive -Xtheirs . side &&
+	git reset --hard master && git pull --merge -s recursive -X theirs . side &&
+	git reset --hard master && test_must_fail git pull --merge -s recursive -X bork . side
 '
 
 test_done
diff --git a/t/t7603-merge-reduce-heads.sh b/t/t7603-merge-reduce-heads.sh
index 9894895..566b1c1 100755
--- a/t/t7603-merge-reduce-heads.sh
+++ b/t/t7603-merge-reduce-heads.sh
@@ -68,7 +68,7 @@ test_expect_success 'merge c1 with c2, c3, c4, c5' '
 
 test_expect_success 'pull c2, c3, c4, c5 into c1' '
 	git reset --hard c1 &&
-	git pull . c2 c3 c4 c5 &&
+	git pull --merge . c2 c3 c4 c5 &&
 	test "$(git rev-parse c1)" != "$(git rev-parse HEAD)" &&
 	test "$(git rev-parse c1)" = "$(git rev-parse HEAD^1)" &&
 	test "$(git rev-parse c2)" = "$(git rev-parse HEAD^2)" &&
-- 
1.8.4-337-g7358a66-dirty

  parent reply	other threads:[~2013-08-31 22:43 UTC|newest]

Thread overview: 84+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-31 22:38 [PATCH 0/3] Reject non-ff pulls by default Felipe Contreras
2013-08-31 22:38 ` [PATCH 1/3] merge: simplify ff-only option Felipe Contreras
2013-08-31 22:38 ` [PATCH 2/3] t: replace pulls with merges Felipe Contreras
2013-08-31 22:38 ` Felipe Contreras [this message]
2013-09-03 17:21 ` [PATCH 0/3] Reject non-ff pulls by default Junio C Hamano
2013-09-03 21:50   ` Felipe Contreras
2013-09-03 22:38     ` Junio C Hamano
2013-09-03 22:59       ` Felipe Contreras
2013-09-04  8:10       ` John Keeping
2013-09-04  9:25         ` Jeff King
2013-09-04 10:16           ` John Keeping
2013-09-08  2:52           ` Felipe Contreras
2013-09-08  4:18             ` Jeff King
2013-09-08  4:37               ` Felipe Contreras
2013-09-08  4:43                 ` Jeff King
2013-09-08  5:09                   ` Felipe Contreras
2013-09-08  5:21                     ` Jeff King
2013-09-08  6:17                       ` Felipe Contreras
2013-09-08  6:54                         ` Jeff King
2013-09-08  7:15                           ` Felipe Contreras
2013-09-08  7:50                             ` Jeff King
2013-09-08  8:43                               ` Felipe Contreras
2013-09-09 20:17                               ` Jeff King
2013-09-09 22:59                                 ` Felipe Contreras
2013-09-08 10:03                           ` John Keeping
2013-09-09 20:04                             ` Jeff King
2013-09-08 17:26                 ` brian m. carlson
2013-09-08 22:38                   ` Felipe Contreras
2013-09-09  0:01                     ` brian m. carlson
2013-09-09  0:29                       ` Felipe Contreras
2013-09-09  0:36                         ` Felipe Contreras
2013-09-09  0:38                           ` brian m. carlson
2013-09-09  7:18                         ` Matthieu Moy
2013-09-09 18:47                           ` Junio C Hamano
2013-09-09 19:52                             ` Jeff King
2013-09-09 20:24                               ` John Keeping
2013-09-09 20:44                                 ` Jeff King
2013-09-09 21:10                                   ` John Keeping
2013-09-09 21:48                                   ` Richard Hansen
2013-09-09 20:50                                 ` Matthieu Moy
2013-09-09 20:53                                   ` Jeff King
2013-09-09 21:34                                     ` Philip Oakley
2013-09-09 23:02                                 ` Felipe Contreras
2013-09-10  8:08                                   ` John Keeping
2013-09-09 20:47                             ` Matthieu Moy
2013-09-10 21:56                               ` Junio C Hamano
2013-09-09 23:17                           ` Felipe Contreras
2013-09-10  8:26                             ` Matthieu Moy
2013-09-11 10:53                               ` Felipe Contreras
2013-09-11 11:38                                 ` Matthieu Moy
2013-09-13  0:55                                   ` Felipe Contreras
2013-09-04 16:59         ` Junio C Hamano
2013-09-04 17:17         ` Junio C Hamano
2013-09-04 22:08           ` Philip Oakley
2013-09-04 22:59             ` Junio C Hamano
2013-09-05  8:06               ` John Keeping
2013-09-05 19:18                 ` Junio C Hamano
2013-09-05 19:26                   ` John Keeping
2013-09-06 21:41                     ` Jonathan Nieder
2013-09-06 22:14                       ` Junio C Hamano
2013-09-07 11:07                         ` John Keeping
2013-09-08  2:36                         ` Felipe Contreras
2013-09-08  2:34                 ` Felipe Contreras
2013-09-08  8:01                   ` Philip Oakley
2013-09-08  8:16                     ` Felipe Contreras
2013-09-08  8:42                       ` Philip Oakley
2013-09-08  8:49                         ` Felipe Contreras
2013-09-08 10:02                           ` Philip Oakley
2013-09-08 10:39                             ` Philip Oakley
2013-09-05 11:01               ` John Szakmeister
2013-09-05 11:38                 ` John Keeping
2013-09-05 12:37                   ` John Szakmeister
2013-09-05 15:20               ` Richard Hansen
2013-09-05 21:30               ` Philip Oakley
2013-09-05 23:45                 ` Junio C Hamano
2013-09-05 23:38               ` Junio C Hamano
2013-09-08  2:41               ` Felipe Contreras
2013-09-08  6:17                 ` Richard Hansen
2013-09-08 18:10                   ` Junio C Hamano
2013-09-08 20:05                     ` Richard Hansen
2013-09-08 22:46                     ` Philip Oakley
2013-09-08 22:46                     ` Felipe Contreras
2013-09-08 23:11                       ` Ramkumar Ramachandra
2013-09-05 13:31           ` Greg Troxel

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=1377988690-23460-4-git-send-email-felipe.contreras@gmail.com \
    --to=felipe.contreras@gmail.com \
    --cc=a.krey@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=john@keeping.me.uk \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.