From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
John Keeping <john@keeping.me.uk>, Andreas Krey <a.krey@gmx.de>,
John Szakmeister <john@szakmeister.net>
Subject: [PATCH] pull: require choice between rebase/merge on non-fast-forward pull
Date: Thu, 27 Jun 2013 12:48:52 -0700 [thread overview]
Message-ID: <7v4ncjs5az.fsf_-_@alter.siamese.dyndns.org> (raw)
In-Reply-To: <CA+55aFz2Uvq4vmyjJPao5tS-uuVvKm6mbP7Uz8sdq1VMxMGJCw@mail.gmail.com> (Linus Torvalds's message of "Thu, 23 May 2013 17:03:38 -0700")
Because letting a trivial merge automatically handled by Git is so
easy with "git pull", a person who is new to Git may not realize
that the project s/he is interacting with may prefer "rebase"
workflow. Add a safety valve to fail "git pull" that is not a
fast-forward until/unless the user expressed her preference between
the two.
Those who want the existing behaviour could just do
git config --global pull.rebase false
once, and they'd not even notice.
http://thread.gmane.org/gmane.comp.version-control.git/225146/focus=225326
for a full discussion.
The fallout from this change to test suite is not very pretty, though.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
* This is not a serious inclusion proposal yet, but to see if
people are still interested in possibly helping new users.
git-pull.sh | 36 +++++++++++++++++++++++++++++++++-
t/annotate-tests.sh | 2 +-
t/t4013-diff-various.sh | 2 ++
t/t4200-rerere.sh | 2 ++
t/t5500-fetch-pack.sh | 6 +++++-
t/t5521-pull-options.sh | 2 ++
t/t5524-pull-msg.sh | 2 +-
t/t5700-clone-reference.sh | 4 ++--
t/t6022-merge-rename.sh | 2 ++
t/t6026-merge-attr.sh | 2 +-
t/t6029-merge-subtree.sh | 1 +
t/t6037-merge-ours-theirs.sh | 2 ++
t/t9114-git-svn-dcommit-merge.sh | 2 +-
t/t9400-git-cvsserver-server.sh | 2 +-
t/t9500-gitweb-standalone-no-errors.sh | 2 +-
15 files changed, 59 insertions(+), 10 deletions(-)
diff --git a/git-pull.sh b/git-pull.sh
index 638aabb..4a6a863 100755
--- a/git-pull.sh
+++ b/git-pull.sh
@@ -41,13 +41,21 @@ test -f "$GIT_DIR/MERGE_HEAD" && die_merge
strategy_args= diffstat= no_commit= squash= no_ff= ff_only=
log_arg= verbosity= progress= recurse_submodules= verify_signatures=
merge_args= edit=
+
curr_branch=$(git symbolic-ref -q HEAD)
curr_branch_short="${curr_branch#refs/heads/}"
+
+# See if we are configured to rebase by default.
+# The value $rebase is, throughout the main part of the code:
+# (empty) - the user did not have any preference
+# true - the user told us to integrate by rebasing
+# flase - the user told us to integrate by merging
rebase=$(git config --bool branch.$curr_branch_short.rebase)
if test -z "$rebase"
then
rebase=$(git config --bool pull.rebase)
fi
+
dry_run=
while :
do
@@ -113,7 +121,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)
@@ -219,6 +228,7 @@ test true = "$rebase" && {
fi
done
}
+
orig_head=$(git rev-parse -q --verify HEAD)
git fetch $verbosity $progress $dry_run $recurse_submodules --update-head-ok "$@" || exit 1
test -z "$dry_run" || exit 0
@@ -264,6 +274,30 @@ case "$merge_head" in
die "$(gettext "Cannot rebase onto multiple branches")"
fi
;;
+*)
+ # integrating with a single other history
+ merge_head=${merge_head% }
+ if test -z "$rebase$no_ff$ff_only${squash#--no-squash}" &&
+ test -n "$orig_head" &&
+ ! $(git merge-base --is-ancestor "$orig_head" "$merge_head")
+ then
+echo >&2 "orig-head was $orig_head"
+echo >&2 "merge-head is $merge_head"
+git show >&2 --oneline -s "$orig_head" "$merge_head"
+
+ die "The pull does not fast-forward; please specify
+if you want to merge or rebase.
+
+Use either
+
+ git pull --rebase
+ git pull --merge
+
+You can also use 'git config pull.rebase true' (if you want --rebase) or
+'git config pull.rebase false' (if you want --merge) to set this once for
+this project and forget about it."
+ fi
+ ;;
esac
if test -z "$orig_head"
diff --git a/t/annotate-tests.sh b/t/annotate-tests.sh
index c56a77d..af02c6d 100644
--- a/t/annotate-tests.sh
+++ b/t/annotate-tests.sh
@@ -79,7 +79,7 @@ test_expect_success \
test_expect_success \
'merge-setup part 3' \
- 'git pull . branch1'
+ 'git pull --merge . branch1'
test_expect_success \
'Two lines blamed on A, one on B, two on B1, one on B2' \
diff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh
index e77c09c..1ee2198 100755
--- a/t/t4013-diff-various.sh
+++ b/t/t4013-diff-various.sh
@@ -12,6 +12,8 @@ LF='
test_expect_success setup '
+ git config pull.rebase false &&
+
GIT_AUTHOR_DATE="2006-06-26 00:00:00 +0000" &&
GIT_COMMITTER_DATE="2006-06-26 00:00:00 +0000" &&
export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
diff --git a/t/t4200-rerere.sh b/t/t4200-rerere.sh
index 7f6666f..0563357 100755
--- a/t/t4200-rerere.sh
+++ b/t/t4200-rerere.sh
@@ -25,6 +25,8 @@ test_description='git rerere
. ./test-lib.sh
test_expect_success 'setup' '
+ git config pull.rebase false &&
+
cat >a1 <<-\EOF &&
Some title
==========
diff --git a/t/t5500-fetch-pack.sh b/t/t5500-fetch-pack.sh
index fd2598e..4be8877 100755
--- a/t/t5500-fetch-pack.sh
+++ b/t/t5500-fetch-pack.sh
@@ -143,7 +143,11 @@ test_expect_success 'clone shallow depth 1 with fsck' '
'
test_expect_success 'clone shallow' '
- git clone --no-single-branch --depth 2 "file://$(pwd)/." shallow
+ git clone --no-single-branch --depth 2 "file://$(pwd)/." shallow &&
+ (
+ cd shallow &&
+ git config pull.rebase false
+ )
'
test_expect_success 'clone shallow depth count' '
diff --git a/t/t5521-pull-options.sh b/t/t5521-pull-options.sh
index 453aba5..d821fab 100755
--- a/t/t5521-pull-options.sh
+++ b/t/t5521-pull-options.sh
@@ -91,6 +91,8 @@ test_expect_success 'git pull --force' '
[branch "master"]
remote = two
merge = refs/heads/master
+ [pull]
+ rebase = false
EOF
git pull two &&
test_commit A &&
diff --git a/t/t5524-pull-msg.sh b/t/t5524-pull-msg.sh
index 8cccecc..660714b 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 --log --merge &&
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..e12d90b 100755
--- a/t/t6022-merge-rename.sh
+++ b/t/t6022-merge-rename.sh
@@ -10,6 +10,8 @@ modify () {
test_expect_success setup \
'
+git config pull.rebase false &&
+
cat >A <<\EOF &&
a aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
b bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
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..3ca29c4 100755
--- a/t/t6029-merge-subtree.sh
+++ b/t/t6029-merge-subtree.sh
@@ -41,6 +41,7 @@ test_expect_success 'setup' '
mkdir git &&
cd git &&
git init &&
+ git config pull.rebase false &&
echo git >git.c &&
o2=$(git hash-object git.c) &&
git add git.c &&
diff --git a/t/t6037-merge-ours-theirs.sh b/t/t6037-merge-ours-theirs.sh
index 3889eca..41bf060 100755
--- a/t/t6037-merge-ours-theirs.sh
+++ b/t/t6037-merge-ours-theirs.sh
@@ -66,6 +66,8 @@ test_expect_success 'binary file with -Xours/-Xtheirs' '
'
test_expect_success 'pull passes -X to underlying merge' '
+ git config pull.rebase false &&
+
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 &&
diff --git a/t/t9114-git-svn-dcommit-merge.sh b/t/t9114-git-svn-dcommit-merge.sh
index f524d2f..dfce024 100755
--- a/t/t9114-git-svn-dcommit-merge.sh
+++ b/t/t9114-git-svn-dcommit-merge.sh
@@ -62,7 +62,7 @@ test_expect_success 'setup git mirror and merge' '
echo friend > README &&
cat tmp >> README &&
git commit -a -m "friend" &&
- git pull . merge
+ git pull --merge . merge
'
test_debug 'gitk --all & sleep 1'
diff --git a/t/t9400-git-cvsserver-server.sh b/t/t9400-git-cvsserver-server.sh
index 0431386..76b8640 100755
--- a/t/t9400-git-cvsserver-server.sh
+++ b/t/t9400-git-cvsserver-server.sh
@@ -46,7 +46,7 @@ test_expect_success 'setup' '
touch secondrootfile &&
git add secondrootfile &&
git commit -m "second root") &&
- git pull secondroot master &&
+ git pull --merge secondroot master &&
git clone -q --bare "$WORKDIR/.git" "$SERVERDIR" >/dev/null 2>&1 &&
GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
GIT_DIR="$SERVERDIR" git config gitcvs.logfile "$SERVERDIR/gitcvs.log" &&
diff --git a/t/t9500-gitweb-standalone-no-errors.sh b/t/t9500-gitweb-standalone-no-errors.sh
index 6fca193..787c6cc 100755
--- a/t/t9500-gitweb-standalone-no-errors.sh
+++ b/t/t9500-gitweb-standalone-no-errors.sh
@@ -328,7 +328,7 @@ test_expect_success \
git add b &&
git commit -a -m "On branch" &&
git checkout master &&
- git pull . b &&
+ git pull --merge . b &&
git tag merge_commit'
test_expect_success \
--
1.8.3.1-794-ga13ccd6
next prev parent reply other threads:[~2013-06-27 19:49 UTC|newest]
Thread overview: 69+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-22 11:50 first parent, commit graph layout, and pull merge direction Andreas Krey
2013-05-22 18:07 ` Junio C Hamano
2013-05-23 9:06 ` Andreas Krey
2013-05-23 9:48 ` John Szakmeister
2013-05-23 10:07 ` Jeremy Rosen
2013-05-23 10:29 ` Andreas Krey
2013-05-23 11:08 ` John Keeping
2013-05-23 16:01 ` Junio C Hamano
2013-05-23 16:41 ` John Keeping
2013-05-23 21:01 ` Junio C Hamano
2013-05-23 21:55 ` John Keeping
2013-05-23 21:59 ` Felipe Contreras
2013-05-23 22:11 ` Junio C Hamano
2013-05-23 22:46 ` Felipe Contreras
2013-05-23 22:54 ` Junio C Hamano
2013-05-23 23:09 ` Felipe Contreras
2013-05-23 23:26 ` Junio C Hamano
2013-05-23 23:53 ` Felipe Contreras
2013-05-24 8:29 ` John Keeping
2013-05-24 9:38 ` John Szakmeister
2013-05-24 0:03 ` Linus Torvalds
2013-05-24 0:21 ` Junio C Hamano
2013-05-24 0:24 ` Linus Torvalds
2013-05-24 0:25 ` Felipe Contreras
2013-05-24 0:32 ` Felipe Contreras
2013-05-24 16:26 ` Junio C Hamano
2013-05-24 20:47 ` Philip Oakley
2013-06-27 19:48 ` Junio C Hamano [this message]
2013-06-27 20:10 ` [PATCH] pull: require choice between rebase/merge on non-fast-forward pull W. Trevor King
2013-06-27 21:20 ` Junio C Hamano
2013-06-28 1:08 ` W. Trevor King
2013-06-28 6:34 ` Matthieu Moy
2013-06-28 9:09 ` W. Trevor King
2013-06-28 11:52 ` Matthieu Moy
2013-06-28 12:28 ` W. Trevor King
2013-06-27 20:11 ` Fredrik Gustafsson
2013-06-27 20:49 ` Junio C Hamano
2013-06-27 20:30 ` W. Trevor King
2013-06-27 20:58 ` Junio C Hamano
2013-06-27 22:16 ` Matthieu Moy
2013-06-28 1:19 ` W. Trevor King
2013-06-28 8:09 ` John Keeping
2013-06-28 17:22 ` Junio C Hamano
2013-06-28 17:42 ` John Keeping
2013-06-28 22:41 ` Junio C Hamano
2013-07-02 21:18 ` John Keeping
2013-07-14 15:03 ` [PATCH] fixup! " John Keeping
2013-07-15 4:23 ` Junio C Hamano
2013-08-28 23:22 ` [PATCH] " Felipe Contreras
2013-07-18 14:30 ` John Keeping
2013-07-18 17:38 ` Andreas Schwab
2013-07-18 18:00 ` Junio C Hamano
2013-07-18 19:35 ` [PATCH v2] " Junio C Hamano
2013-07-19 0:54 ` Eric Sunshine
2013-07-19 16:22 ` Junio C Hamano
2013-07-19 20:29 ` Eric Sunshine
2013-07-19 22:20 ` Junio C Hamano
2013-07-19 22:30 ` Eric Sunshine
2013-07-19 22:55 ` Junio C Hamano
2014-01-22 19:08 ` Flimm
2013-05-24 17:11 ` first parent, commit graph layout, and pull merge direction Andreas Krey
2013-05-24 19:23 ` Junio C Hamano
2013-05-23 19:25 ` Andreas Krey
2013-05-24 9:29 ` Holger Hellmuth (IKS)
2013-05-24 13:42 ` Andreas Krey
2013-05-24 15:05 ` Holger Hellmuth (IKS)
2013-05-24 17:24 ` Andreas Krey
2013-05-23 11:34 ` Felipe Contreras
2013-05-23 12:21 ` Andreas Krey
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7v4ncjs5az.fsf_-_@alter.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=a.krey@gmx.de \
--cc=git@vger.kernel.org \
--cc=john@keeping.me.uk \
--cc=john@szakmeister.net \
--cc=torvalds@linux-foundation.org \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).