From 93ce190cd16b4c5ff16cc000eb75bd6e6c3238ac Mon Sep 17 00:00:00 2001 From: Mike Lundy Date: Thu, 29 Jul 2010 00:04:29 +0200 Subject: [PATCH] rebase: support -X to pass through strategy options git-rebase calls out to merge strategies, but did not support merge strategy options so far. Add this, in the same style used in git-merge. Sadly we have to do the full quoting/eval dance here, since merge-recursive supports the --subtree= option which potentially contains whitespace. This patch does not cover git rebase -i, which does not call any merge strategy directly except in --preserve-merges, and even then only for merges. [jc: with a trivial fix-up for 'expr'] Signed-off-by: Mike Lundy Signed-off-by: Thomas Rast Signed-off-by: Junio C Hamano --- Documentation/git-rebase.txt | 7 +++++++ git-rebase.sh | 24 +++++++++++++++++++++++- t/t3402-rebase-merge.sh | 9 +++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt index be23ad235..b4314568f 100644 --- a/Documentation/git-rebase.txt +++ b/Documentation/git-rebase.txt @@ -250,6 +250,13 @@ on top of the branch using the given strategy, using the 'ours' strategy simply discards all patches from the , which makes little sense. +-X :: +--strategy-option=:: + Pass the through to the merge strategy. + This implies `\--merge` and, if no strategy has been + specified, `-s recursive`. Note the reversal of 'ours' and + 'theirs' as noted in above for the `-m` option. + -q:: --quiet:: Be quiet. Implies --no-stat. diff --git a/git-rebase.sh b/git-rebase.sh index ab4afa7de..7d1c5c386 100755 --- a/git-rebase.sh +++ b/git-rebase.sh @@ -44,6 +44,7 @@ To restore the original branch and stop rebasing run \"git rebase --abort\". " unset newbase strategy=recursive +strategy_opts= do_merge= dotest="$GIT_DIR"/rebase-merge prec=4 @@ -112,7 +113,7 @@ call_merge () { then export GIT_MERGE_VERBOSITY=1 fi - git-merge-$strategy "$cmt^" -- "$hd" "$cmt" + eval 'git-merge-$strategy' $strategy_opts '"$cmt^" -- "$hd" "$cmt"' rv=$? case "$rv" in 0) @@ -293,6 +294,27 @@ do -M|-m|--m|--me|--mer|--merg|--merge) do_merge=t ;; + -X*|--strategy-option*) + case "$#,$1" in + 1,-X|1,--strategy-option) + usage ;; + *,-X|*,--strategy-option) + newopt="$2" + shift ;; + *,--strategy-option=*) + newopt="$(expr " $1" : ' --strategy-option=\(.*\)')" ;; + *,-X*) + newopt="$(expr " $1" : ' -X\(.*\)')" ;; + 1,*) + usage ;; + esac + strategy_opts="$strategy_opts $(git rev-parse --sq-quote "--$newopt")" + do_merge=t + if test -n "$strategy" + then + strategy=recursive + fi + ;; -s=*|--s=*|--st=*|--str=*|--stra=*|--strat=*|--strate=*|\ --strateg=*|--strategy=*|\ -s|--s|--st|--str|--stra|--strat|--strate|--strateg|--strategy) diff --git a/t/t3402-rebase-merge.sh b/t/t3402-rebase-merge.sh index 7b7d07269..2bea65634 100755 --- a/t/t3402-rebase-merge.sh +++ b/t/t3402-rebase-merge.sh @@ -74,6 +74,15 @@ test_expect_success 'rebase the other way' ' git rebase --merge side ' +test_expect_success 'rebase -Xtheirs' ' + git checkout -b conflicting master~2 && + echo "AB $T" >> original && + git commit -mconflicting original && + git rebase -Xtheirs master && + grep AB original && + ! grep 11 original +' + test_expect_success 'merge and rebase should match' ' git diff-tree -r test-rebase test-merge >difference && if test -s difference -- 2.11.0