{"thread":{"id":"34679","subject":"[PATCH] pull: Allow pull to preserve merges when rebasing.","startedAt":"2013-08-12T06:21:58Z","lastAt":"2013-08-12T16:28:01Z","messageCount":3,"participants":["Stephen Haberman","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"225075","messageId":"1376288518-4875-1-git-send-email-stephen@exigencecorp.com","threadId":"34679","inReplyTo":null,"subject":"[PATCH] pull: Allow pull to preserve merges when rebasing.","fromName":"Stephen Haberman","fromEmail":"stephen@exigencecorp.com","sentAt":"2013-08-12T06:21:58Z","receivedAt":"2013-08-12T06:21:58Z","isPatch":true,"sender":{"key":"stephen@exigencecorp.com","avatar":"https://gravatar.com/avatar/23b93ad70a06ce53505f17ddba65176edbcfb6588e7a4c1a2dca04aaf0a6aff1?d=mp&s=160"},"body":"If a user is working on master, and has merged in their feature branch, but now\nhas to \"git pull\" because master moved, with pull.rebase their feature branch\nwill be flattened into master.\n\nThis is because \"git pull\" currently does not know about rebase's preserve\nmerges flag, which would avoid this behavior, as it would instead replay just\nthe merge commit of the feature branch onto the new master, and not replay each\nindividual commit in the feature branch.\n\nAdd a --rebase=preserve option, which will pass along --preserve-merges to\nrebase.\n\nAlso add 'preserve' to the allowed values for the pull.rebase config setting.\n\nSigned-off-by: Stephen Haberman <stephen@exigencecorp.com>\n---\nHi,\n\nThis is v4 of my pull.rebase=preserve patch, previously discussed here:\n\nhttp://thread.gmane.org/gmane.comp.version-control.git/232140\n\nThis version addresses feedback from Andreas about using case statements\ninstead of yoda conditions, and feedback from both Andreas and Junio\nabout avoiding ambiguity with \"--rebase preserve\". Now it must be\n\"--rebase=preseve\".\n\nI assume I'm doing the right thing by just posting another version of\nthis patch to the git list; let me know if I'm missing something.\n\nThanks!\n\n Documentation/config.txt   |  8 +++++\n Documentation/git-pull.txt | 18 +++++++----\n git-pull.sh                | 27 +++++++++++++---\n t/t5520-pull.sh            | 81 ++++++++++++++++++++++++++++++++++++++++++++++\n 4 files changed, 123 insertions(+), 11 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex ec57a15..4c22be2 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -766,6 +766,10 @@ branch.<name>.rebase::\n \t\"git pull\" is run. See \"pull.rebase\" for doing this in a non\n \tbranch-specific manner.\n +\n+\tWhen preserve, also pass `--preserve-merges` along to 'git rebase'\n+\tso that locally committed merge commits will not be flattened\n+\tby running 'git pull'.\n++\n *NOTE*: this is a possibly dangerous operation; do *not* use\n it unless you understand the implications (see linkgit:git-rebase[1]\n for details).\n@@ -1826,6 +1830,10 @@ pull.rebase::\n \tpull\" is run. See \"branch.<name>.rebase\" for setting this on a\n \tper-branch basis.\n +\n+\tWhen preserve, also pass `--preserve-merges` along to 'git rebase'\n+\tso that locally committed merge commits will not be flattened\n+\tby running 'git pull'.\n++\n *NOTE*: this is a possibly dangerous operation; do *not* use\n it unless you understand the implications (see linkgit:git-rebase[1]\n for details).\ndiff --git a/Documentation/git-pull.txt b/Documentation/git-pull.txt\nindex 6ef8d59..beea10b 100644\n--- a/Documentation/git-pull.txt\n+++ b/Documentation/git-pull.txt\n@@ -102,12 +102,18 @@ include::merge-options.txt[]\n :git-pull: 1\n \n -r::\n---rebase::\n-\tRebase the current branch on top of the upstream branch after\n-\tfetching.  If there is a remote-tracking branch corresponding to\n-\tthe upstream branch and the upstream branch was rebased since last\n-\tfetched, the rebase uses that information to avoid rebasing\n-\tnon-local changes.\n+--rebase[=false|true|preserve]::\n+\tWhen true, rebase the current branch on top of the upstream\n+\tbranch after fetching. If there is a remote-tracking branch\n+\tcorresponding to the upstream branch and the upstream branch\n+\twas rebased since last fetched, the rebase uses that information\n+\tto avoid rebasing non-local changes.\n++\n+When preserve, also rebase the current branch on top of the upstream\n+branch, but pass `--preserve-merges` along to `git rebase` so that\n+locally created merge commits will not be flattened.\n++\n+When false, merge the current branch into the upstream branch.\n +\n See `pull.rebase`, `branch.<name>.rebase` and `branch.autosetuprebase` in\n linkgit:git-config[1] if you want to make `git pull` always use\ndiff --git a/git-pull.sh b/git-pull.sh\nindex f0df41c..6ae6640 100755\n--- a/git-pull.sh\n+++ b/git-pull.sh\n@@ -4,7 +4,7 @@\n #\n # Fetch one or more remote refs and merge it/them into the current HEAD.\n \n-USAGE='[-n | --no-stat] [--[no-]commit] [--[no-]squash] [--[no-]ff] [-s strategy]... [<fetch-options>] <repo> <head>...'\n+USAGE='[-n | --no-stat] [--[no-]commit] [--[no-]squash] [--[no-]ff] [-r=[true|false|preserve]] [-s strategy]... [<fetch-options>] <repo> <head>...'\n LONG_USAGE='Fetch one or more remote refs and integrate it/them with the current HEAD.'\n SUBDIRECTORY_OK=Yes\n OPTIONS_SPEC=\n@@ -40,13 +40,13 @@ test -f \"$GIT_DIR/MERGE_HEAD\" && die_merge\n \n strategy_args= diffstat= no_commit= squash= no_ff= ff_only=\n log_arg= verbosity= progress= recurse_submodules= verify_signatures=\n-merge_args= edit=\n+merge_args= edit= rebase_args=\n curr_branch=$(git symbolic-ref -q HEAD)\n curr_branch_short=\"${curr_branch#refs/heads/}\"\n-rebase=$(git config --bool branch.$curr_branch_short.rebase)\n+rebase=$(git config branch.$curr_branch_short.rebase)\n if test -z \"$rebase\"\n then\n-\trebase=$(git config --bool pull.rebase)\n+\trebase=$(git config pull.rebase)\n fi\n dry_run=\n while :\n@@ -110,6 +110,9 @@ do\n \t\tesac\n \t\tmerge_args=\"$merge_args$xx \"\n \t\t;;\n+\t-r=*|--r=*|--re=*|--reb=*|--reba=*|--rebas=*|--rebase=*)\n+\t\trebase=\"${1#*=}\"\n+\t\t;;\n \t-r|--r|--re|--reb|--reba|--rebas|--rebase)\n \t\trebase=true\n \t\t;;\n@@ -145,6 +148,20 @@ do\n \tshift\n done\n \n+case \"$rebase\" in\n+preserve)\n+\trebase=true\n+\trebase_args=--preserve-merges\n+\t;;\n+true|false|'')\n+\t;;\n+*)\n+\techo \"Invalid value for --rebase, should be true, false, or preserve\"\n+\tusage\n+\texit 1\n+\t;;\n+esac\n+\n error_on_no_merge_candidates () {\n \texec >&2\n \tfor opt\n@@ -292,7 +309,7 @@ fi\n merge_name=$(git fmt-merge-msg $log_arg <\"$GIT_DIR/FETCH_HEAD\") || exit\n case \"$rebase\" in\n true)\n-\teval=\"git-rebase $diffstat $strategy_args $merge_args $verbosity\"\n+\teval=\"git-rebase $diffstat $strategy_args $merge_args $rebase_args $verbosity\"\n \teval=\"$eval --onto $merge_head ${oldremoteref:-$merge_head}\"\n \t;;\n *)\ndiff --git a/t/t5520-pull.sh b/t/t5520-pull.sh\nindex ed4d9c8..8be0482 100755\n--- a/t/t5520-pull.sh\n+++ b/t/t5520-pull.sh\n@@ -148,6 +148,87 @@ test_expect_success 'branch.to-rebase.rebase should override pull.rebase' '\n \ttest new = $(git show HEAD:file2)\n '\n \n+# add a feature branch, keep-merge, that is merged into master, so the\n+# test can try preserving the merge commit (or not) with various\n+# --rebase flags/pull.rebase settings.\n+test_expect_success 'preserve merge setup' '\n+\tgit reset --hard before-rebase &&\n+\tgit checkout -b keep-merge second^ &&\n+\ttest_commit file3 &&\n+\tgit checkout to-rebase &&\n+\tgit merge keep-merge &&\n+\tgit tag before-preserve-rebase\n+'\n+\n+test_expect_success 'pull.rebase=false create a new merge commit' '\n+\tgit reset --hard before-preserve-rebase &&\n+\ttest_config pull.rebase false &&\n+\tgit pull . copy &&\n+\ttest $(git rev-parse HEAD^1) = $(git rev-parse before-preserve-rebase) &&\n+\ttest $(git rev-parse HEAD^2) = $(git rev-parse copy) &&\n+\ttest file3 = $(git show HEAD:file3.t)\n+'\n+\n+test_expect_success 'pull.rebase=true flattens keep-merge' '\n+\tgit reset --hard before-preserve-rebase &&\n+\ttest_config pull.rebase true &&\n+\tgit pull . copy &&\n+\ttest $(git rev-parse HEAD^^) = $(git rev-parse copy) &&\n+\ttest file3 = $(git show HEAD:file3.t)\n+'\n+\n+test_expect_success 'pull.rebase=preserve rebases and merges keep-merge' '\n+\tgit reset --hard before-preserve-rebase &&\n+\ttest_config pull.rebase preserve &&\n+\tgit pull . copy &&\n+\ttest $(git rev-parse HEAD^^) = $(git rev-parse copy) &&\n+\ttest $(git rev-parse HEAD^2) = $(git rev-parse keep-merge)\n+'\n+\n+test_expect_success 'pull.rebase=invalid fails' '\n+\tgit reset --hard before-preserve-rebase &&\n+\ttest_config pull.rebase invalid &&\n+\t! git pull . copy\n+'\n+\n+test_expect_success '--rebase=false create a new merge commit' '\n+\tgit reset --hard before-preserve-rebase &&\n+\ttest_config pull.rebase true &&\n+\tgit pull --rebase=false . copy &&\n+\ttest $(git rev-parse HEAD^1) = $(git rev-parse before-preserve-rebase) &&\n+\ttest $(git rev-parse HEAD^2) = $(git rev-parse copy) &&\n+\ttest file3 = $(git show HEAD:file3.t)\n+'\n+\n+test_expect_success '--rebase=true rebases and flattens keep-merge' '\n+\tgit reset --hard before-preserve-rebase &&\n+\ttest_config pull.rebase preserve &&\n+\tgit pull --rebase=true . copy &&\n+\ttest $(git rev-parse HEAD^^) = $(git rev-parse copy) &&\n+\ttest file3 = $(git show HEAD:file3.t)\n+'\n+\n+test_expect_success '--rebase=preserve rebases and merges keep-merge' '\n+\tgit reset --hard before-preserve-rebase &&\n+\ttest_config pull.rebase true &&\n+\tgit pull --rebase=preserve . copy &&\n+\ttest $(git rev-parse HEAD^^) = $(git rev-parse copy) &&\n+\ttest $(git rev-parse HEAD^2) = $(git rev-parse keep-merge)\n+'\n+\n+test_expect_success '--rebase=invalid fails' '\n+\tgit reset --hard before-preserve-rebase &&\n+\t! git pull --rebase=invalid . copy\n+'\n+\n+test_expect_success '--rebase overrides pull.rebase=preserve and flattens keep-merge' '\n+\tgit reset --hard before-preserve-rebase &&\n+\ttest_config pull.rebase preserve &&\n+\tgit pull --rebase . copy &&\n+\ttest $(git rev-parse HEAD^^) = $(git rev-parse copy) &&\n+\ttest file3 = $(git show HEAD:file3.t)\n+'\n+\n test_expect_success '--rebase with rebased upstream' '\n \n \tgit remote add -f me . &&\n-- \n1.8.1.2\n"},{"id":"225079","messageId":"7vpptjz9r1.fsf@alter.siamese.dyndns.org","threadId":"34679","inReplyTo":"1376288518-4875-1-git-send-email-stephen@exigencecorp.com","subject":"Re: [PATCH] pull: Allow pull to preserve merges when rebasing.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-08-12T06:46:58Z","receivedAt":"2013-08-12T06:46:58Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Stephen Haberman <stephen@exigencecorp.com> writes:\n\n> I assume I'm doing the right thing by just posting another version of\n> this patch to the git list; let me know if I'm missing something.\n\nThanks.  Writing the \"story so far...\" summary like you did after\nthe three-dash line was very helpful.\n\n> diff --git a/git-pull.sh b/git-pull.sh\n> index f0df41c..6ae6640 100755\n> --- a/git-pull.sh\n> +++ b/git-pull.sh\n> @@ -4,7 +4,7 @@\n>  #\n>  # Fetch one or more remote refs and merge it/them into the current HEAD.\n>  \n> -USAGE='[-n | --no-stat] [--[no-]commit] [--[no-]squash] [--[no-]ff] [-s strategy]... [<fetch-options>] <repo> <head>...'\n> +USAGE='[-n | --no-stat] [--[no-]commit] [--[no-]squash] [--[no-]ff] [-r=[true|false|preserve]] [-s strategy]... [<fetch-options>] <repo> <head>...'\n\n\"-r\", even though it happens to be accepted, is not a good idea\nhere, as there are other --r* commands that are not --rebase.\n\n\t[--[no-]rebase|--rebase=preserve]\n\nwould be better.\n\n> @@ -40,13 +40,13 @@ test -f \"$GIT_DIR/MERGE_HEAD\" && die_merge\n>  \n>  strategy_args= diffstat= no_commit= squash= no_ff= ff_only=\n>  log_arg= verbosity= progress= recurse_submodules= verify_signatures=\n> -merge_args= edit=\n> +merge_args= edit= rebase_args=\n>  curr_branch=$(git symbolic-ref -q HEAD)\n>  curr_branch_short=\"${curr_branch#refs/heads/}\"\n> -rebase=$(git config --bool branch.$curr_branch_short.rebase)\n> +rebase=$(git config branch.$curr_branch_short.rebase)\n>  if test -z \"$rebase\"\n>  then\n> -\trebase=$(git config --bool pull.rebase)\n> +\trebase=$(git config pull.rebase)\n\n\nThis is a grave regression (the same for the earlier one that reads\nthe branch.*.rebase configuraiton).  Those who did any of the\nfollowing will be broken:\n\n\t[pull]\n\t\t;; any of the following are \"true\"\n        \trebase\n                rebase = yes\n                rebase = 1\n                ;; any of the following are \"false\"\n                rebase = no\n                rebase = 0\n\nYou would want \"bool or string\" helper function to parse it\ncorrectly, something like:\n\n\tbool_or_string_config () {\n        \tgit config --bool \"$1\" 2>/dev/null || git config \"$1\"\n\t}\n\n\trebase=$(boo_or_string_config pull.rebase)\n"},{"id":"225114","messageId":"20130812112801.0aae67a2@sh9","threadId":"34679","inReplyTo":"7vpptjz9r1.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] pull: Allow pull to preserve merges when rebasing.","fromName":"Stephen Haberman","fromEmail":"stephen@exigencecorp.com","sentAt":"2013-08-12T16:28:01Z","receivedAt":"2013-08-12T16:28:01Z","isPatch":true,"sender":{"key":"stephen@exigencecorp.com","avatar":"https://gravatar.com/avatar/23b93ad70a06ce53505f17ddba65176edbcfb6588e7a4c1a2dca04aaf0a6aff1?d=mp&s=160"},"body":"Hi Junio,\n\n> \"-r\", even though it happens to be accepted, is not a good idea\n> here, as there are other --r* commands that are not --rebase.\n> \n> \t[--[no-]rebase|--rebase=preserve]\n\nCool, I will change that.\n\n> You would want \"bool or string\" helper function to parse it\n> correctly, something like:\n\nOh, interesting, I had not thought of that--thanks for that\ngit config --bool snippet, that's really helpful.\n\n- Stephen\n"}]}