pull: Allow pull to preserve merges when rebasing.
PATCH 1/1 pull: Allow pull to preserve merges when rebasing.
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 avoid this behavior, as it would instead replay just the merge commit of the feature branch onto the new master, and not replay each individual commit in the feature branch.
Add a --rebase=preserve option, which will pass along --preserve-merges to rebase.
Also add 'preserve' to the allowed values for the pull.rebase config setting.
---
Hi,
This is v4 of my pull.rebase=preserve patch, previously discussed here:
http://thread.gmane.org/gmane.comp.version-control.git/232140
This version addresses feedback from Andreas about using case statements instead of yoda conditions, and feedback from both Andreas and Junio about avoiding ambiguity with "--rebase preserve". Now it must be "--rebase=preseve".
I assume I'm doing the right thing by just posting another version of this patch to the git list; let me know if I'm missing something.
Thanks!
Documentation/config.txt | 8 +++++ Documentation/git-pull.txt | 18 +++++++---- git-pull.sh | 27 +++++++++++++--- t/t5520-pull.sh | 81 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 123 insertions(+), 11 deletions(-)
Documentation/config.txt +8 -0
@@ -766,6 +766,10 @@ branch.<name>.rebase:: "git pull" is run. See "pull.rebase" for doing this in a non branch-specific manner. + + When preserve, also pass `--preserve-merges` along to 'git rebase' + so that locally committed merge commits will not be flattened + by running 'git pull'. ++ *NOTE*: this is a possibly dangerous operation; do *not* use it unless you understand the implications (see linkgit:git-rebase[1] for details).
@@ -1826,6 +1830,10 @@ pull.rebase:: pull" is run. See "branch.<name>.rebase" for setting this on a per-branch basis. + + When preserve, also pass `--preserve-merges` along to 'git rebase' + so that locally committed merge commits will not be flattened + by running 'git pull'. ++ *NOTE*: this is a possibly dangerous operation; do *not* use it unless you understand the implications (see linkgit:git-rebase[1] for details).
Documentation/git-pull.txt +12 -6
@@ -102,12 +102,18 @@ include::merge-options.txt[] :git-pull: 1 -r:: ---rebase:: - Rebase the current branch on top of the upstream branch after - fetching. If there is a remote-tracking branch corresponding to - the upstream branch and the upstream branch was rebased since last - fetched, the rebase uses that information to avoid rebasing - non-local changes. +--rebase[=false|true|preserve]:: + When true, rebase the current branch on top of the upstream + branch after fetching. If there is a remote-tracking branch + corresponding to the upstream branch and the upstream branch + was rebased since last fetched, the rebase uses that information + to avoid rebasing non-local changes. ++ +When preserve, also rebase the current branch on top of the upstream +branch, but pass `--preserve-merges` along to `git rebase` so that +locally created merge commits will not be flattened. ++ +When false, merge the current branch into the upstream branch. + See `pull.rebase`, `branch.<name>.rebase` and `branch.autosetuprebase` in linkgit:git-config[1] if you want to make `git pull` always use
git-pull.sh +22 -5
@@ -4,7 +4,7 @@ # # Fetch one or more remote refs and merge it/them into the current HEAD. -USAGE='[-n | --no-stat] [--[no-]commit] [--[no-]squash] [--[no-]ff] [-s strategy]... [<fetch-options>] <repo> <head>...' +USAGE='[-n | --no-stat] [--[no-]commit] [--[no-]squash] [--[no-]ff] [-r=[true|false|preserve]] [-s strategy]... [<fetch-options>] <repo> <head>...' LONG_USAGE='Fetch one or more remote refs and integrate it/them with the current HEAD.' SUBDIRECTORY_OK=Yes OPTIONS_SPEC=
@@ -40,13 +40,13 @@ 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) +rebase=$(git config branch.$curr_branch_short.rebase) if test -z "$rebase" then - rebase=$(git config --bool pull.rebase) + rebase=$(git config pull.rebase) fi dry_run= while :
@@ -110,6 +110,9 @@ do esac merge_args="$merge_args$xx " ;; + -r=*|--r=*|--re=*|--reb=*|--reba=*|--rebas=*|--rebase=*) + rebase="${1#*=}" + ;; -r|--r|--re|--reb|--reba|--rebas|--rebase) rebase=true ;;
@@ -145,6 +148,20 @@ do shift done +case "$rebase" in +preserve) + rebase=true + rebase_args=--preserve-merges + ;; +true|false|'') + ;; +*) + echo "Invalid value for --rebase, should be true, false, or preserve" + usage + exit 1 + ;; +esac + error_on_no_merge_candidates () { exec >&2 for opt
@@ -292,7 +309,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}" ;; *)
t/t5520-pull.sh +81 -0
87 lines not on this page · raw message
Signature · 1 line
1.8.1.2
Quoted 2 lines · Stephen Haberman
I assume I'm doing the right thing by just posting another version of this patch to the git list; let me know if I'm missing something.
Thanks. Writing the "story so far..." summary like you did after the three-dash line was very helpful.
git-pull.sh line 7
Quoted 10 lines
git-pull.sh +1
-1@@ -4,7 +4,7 @@ # # Fetch one or more remote refs and merge it/them into the current HEAD. -USAGE='[-n | --no-stat] [--[no-]commit] [--[no-]squash] [--[no-]ff] [-s strategy]... [<fetch-options>] <repo> <head>...' +USAGE='[-n | --no-stat] [--[no-]commit] [--[no-]squash] [--[no-]ff] [-r=[true|false|preserve]] [-s strategy]... [<fetch-options>] <repo> <head>...'
"-r", even though it happens to be accepted, is not a good idea here, as there are other --r* commands that are not --rebase.
[--[no-]rebase|--rebase=preserve]
would be better.
Quoted 4 lines
git-pull.sh +0
-0@@ -40,13 +40,13 @@ 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=
git-pull.sh test -f "$GIT_DIR/MERGE_HEAD" && die_merge · line 49
Quoted 10 lines
git-pull.sh +3
-3-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) +rebase=$(git config branch.$curr_branch_short.rebase) if test -z "$rebase" then - rebase=$(git config --bool pull.rebase) + rebase=$(git config pull.rebase)
This is a grave regression (the same for the earlier one that reads the branch.*.rebase configuraiton). Those who did any of the following will be broken:
[pull]
;; any of the following are "true" rebase
rebase = yes
rebase = 1
;; any of the following are "false" rebase = no
rebase = 0
You would want "bool or string" helper function to parse it correctly, something like:
bool_or_string_config () {
git config --bool "$1" 2>/dev/null || git config "$1"
}
rebase=$(boo_or_string_config pull.rebase)Hi Junio,
Quoted 4 lines
"-r", even though it happens to be accepted, is not a good idea here, as there are other --r* commands that are not --rebase.
[--[no-]rebase|--rebase=preserve]
Cool, I will change that.
Quoted 2 lines
You would want "bool or string" helper function to parse it correctly, something like:
Oh, interesting, I had not thought of that--thanks for that git config --bool snippet, that's really helpful.
- Stephen