git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephen Haberman <stephen@exigencecorp.com>
To: stephen@exigencecorp.com, git@vger.kernel.org
Cc: Johannes.Schindelin@gmx.de, avarab@gmail.com
Subject: [PATCH] pull: Allow pull to preserve merges when rebasing.
Date: Thu,  8 Aug 2013 12:38:12 -0500	[thread overview]
Message-ID: <1375983492-32282-2-git-send-email-stephen@exigencecorp.com> (raw)
In-Reply-To: <1375983492-32282-1-git-send-email-stephen@exigencecorp.com>

If a user is working on master, and has merged in their feature branch, but now
has to "git pull" because master moved, with pull.rebase their feature branch
will be flattened into master.

This is because "git pull" currently does not know about rebase's preserve
merges flag, which would this behavior, and instead replay on the merge commit
of the feature branch onto the new master, and not the entire feature branch
itself.

Add a -p/--preserve-merges, to pass along git rebase if --rebase is in affect.

Also add a new pull.preserve-merges config setting, to enable this behavior as
the default.

Signed-off-by: Stephen Haberman <stephen@exigencecorp.com>
---
 git-pull.sh     | 11 +++++++++--
 t/t5520-pull.sh | 15 +++++++++++++++
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/git-pull.sh b/git-pull.sh
index f0df41c..61d1efb 100755
--- a/git-pull.sh
+++ b/git-pull.sh
@@ -40,7 +40,7 @@ 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=
+merge_args= edit= rebase_args=
 curr_branch=$(git symbolic-ref -q HEAD)
 curr_branch_short="${curr_branch#refs/heads/}"
 rebase=$(git config --bool branch.$curr_branch_short.rebase)
@@ -48,6 +48,10 @@ if test -z "$rebase"
 then
 	rebase=$(git config --bool pull.rebase)
 fi
+if [ $(git config --bool pull.preserve-merges) = "true" ] ;
+then
+	rebase_args=--preserve-merges
+fi
 dry_run=
 while :
 do
@@ -116,6 +120,9 @@ do
 	--no-r|--no-re|--no-reb|--no-reba|--no-rebas|--no-rebase)
 		rebase=false
 		;;
+	-p|--preserve-merges)
+		rebase_args=--preserve-merges
+		;;
 	--recurse-submodules)
 		recurse_submodules=--recurse-submodules
 		;;
@@ -292,7 +299,7 @@ fi
 merge_name=$(git fmt-merge-msg $log_arg <"$GIT_DIR/FETCH_HEAD") || exit
 case "$rebase" in
 true)
-	eval="git-rebase $diffstat $strategy_args $merge_args $verbosity"
+	eval="git-rebase $diffstat $strategy_args $merge_args $rebase_args $verbosity"
 	eval="$eval --onto $merge_head ${oldremoteref:-$merge_head}"
 	;;
 *)
diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index ed4d9c8..2a2ee97 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -148,6 +148,21 @@ test_expect_success 'branch.to-rebase.rebase should override pull.rebase' '
 	test new = $(git show HEAD:file2)
 '
 
+test_expect_success 'preserve merges' '
+	git reset --hard before-rebase &&
+	test_config pull.rebase true &&
+	test_config pull.preserve-merges true &&
+	git checkout -b keep-merge second^ &&
+	echo new > file3 &&
+	git add file3 &&
+	git commit -m "new file3" &&
+	git checkout to-rebase &&
+	git merge keep-merge &&
+	git pull . copy &&
+	test $(git rev-parse HEAD^^) = $(git rev-parse copy) &&
+	test $(git rev-parse HEAD^2) = $(git rev-parse keep-merge)
+'
+
 test_expect_success '--rebase with rebased upstream' '
 
 	git remote add -f me . &&
-- 
1.8.1.2

  reply	other threads:[~2013-08-08 17:39 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-08 17:38 [RFC] allow git pull to preserve merges Stephen Haberman
2013-08-08 17:38 ` Stephen Haberman [this message]
2013-08-08 19:08   ` [PATCH] pull: Allow pull to preserve merges when rebasing Stephen Haberman
2013-08-08 21:20   ` Johannes Schindelin
2013-08-08 21:35     ` Stephen Haberman
2013-08-08 21:56       ` Philip Oakley
2013-08-08 21:57       ` Junio C Hamano
2013-08-09 14:19         ` Johannes Schindelin
2013-08-09 15:28           ` Stephen Haberman
  -- strict thread matches above, loose matches on Subject: below --
2013-08-10  4:58 Stephen Haberman
2013-08-11  6:16 ` Eric Sunshine
2013-08-11  7:12   ` Eric Sunshine
2013-08-11 21:26 Stephen Haberman
2013-08-11 23:03 ` Andres Perera
2013-08-11 23:09   ` Stephen Haberman
2013-08-11 23:31     ` Andres Perera
2013-08-11 23:38       ` Stephen Haberman
2013-08-12  5:40       ` Junio C Hamano
2013-08-12  7:00         ` Junio C Hamano
2013-08-12 17:04           ` Stephen Haberman
2013-08-12  6:21 Stephen Haberman
2013-08-12  6:46 ` Junio C Hamano
2013-08-12 16:28   ` Stephen Haberman
2013-08-13  3:43 Stephen Haberman

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=1375983492-32282-2-git-send-email-stephen@exigencecorp.com \
    --to=stephen@exigencecorp.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.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.
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).