Skip to content

Commit 3dcacd7

Browse files
committed
Merge branch 'jk/rebase-am-fork-point'
"git rebase --fork-point" did not filter out patch-identical commits correctly. * jk/rebase-am-fork-point: rebase: omit patch-identical commits with --fork-point rebase--am: use --cherry-pick instead of --ignore-if-in-upstream
2 parents 1673744 + 1e0dacd commit 3dcacd7

File tree

4 files changed

+41
-8
lines changed

4 files changed

+41
-8
lines changed

git-rebase--am.sh

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,13 @@ skip)
2929
;;
3030
esac
3131

32-
test -n "$rebase_root" && root_flag=--root
32+
if test -z "$rebase_root"
33+
# this is now equivalent to ! -z "$upstream"
34+
then
35+
revisions=$upstream...$orig_head
36+
else
37+
revisions=$onto...$orig_head
38+
fi
3339

3440
ret=0
3541
if test -n "$keep_empty"
@@ -38,14 +44,17 @@ then
3844
# empty commits and even if it didn't the format doesn't really lend
3945
# itself well to recording empty patches. fortunately, cherry-pick
4046
# makes this easy
41-
git cherry-pick ${gpg_sign_opt:+"$gpg_sign_opt"} --allow-empty "$revisions"
47+
git cherry-pick ${gpg_sign_opt:+"$gpg_sign_opt"} --allow-empty \
48+
--right-only "$revisions" \
49+
${restrict_revision+^$restrict_revision}
4250
ret=$?
4351
else
4452
rm -f "$GIT_DIR/rebased-patches"
4553

46-
git format-patch -k --stdout --full-index --ignore-if-in-upstream \
54+
git format-patch -k --stdout --full-index --cherry-pick --right-only \
4755
--src-prefix=a/ --dst-prefix=b/ --no-renames --no-cover-letter \
48-
$root_flag "$revisions" >"$GIT_DIR/rebased-patches"
56+
"$revisions" ${restrict_revision+^$restrict_revision} \
57+
>"$GIT_DIR/rebased-patches"
4958
ret=$?
5059

5160
if test 0 != $ret

git-rebase--interactive.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,7 @@ else
963963
fi
964964
git rev-list $merges_option --pretty=oneline --abbrev-commit \
965965
--abbrev=7 --reverse --left-right --topo-order \
966-
$revisions | \
966+
$revisions ${restrict_revision+^$restrict_revision} | \
967967
sed -n "s/^>//p" |
968968
while read -r shortsha1 rest
969969
do

git-rebase.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ If you prefer to skip this patch, run "git rebase --skip" instead.
5959
To check out the original branch and stop rebasing, run "git rebase --abort".')
6060
"
6161
unset onto
62+
unset restrict_revision
6263
cmd=
6364
strategy=
6465
strategy_opts=
@@ -546,7 +547,7 @@ then
546547
"${switch_to:-HEAD}")
547548
if test -n "$new_upstream"
548549
then
549-
upstream=$new_upstream
550+
restrict_revision=$new_upstream
550551
fi
551552
fi
552553

@@ -572,7 +573,7 @@ require_clean_work_tree "rebase" "$(gettext "Please commit or stash them.")"
572573
# and if this is not an interactive rebase.
573574
mb=$(git merge-base "$onto" "$orig_head")
574575
if test "$type" != interactive && test "$upstream" = "$onto" &&
575-
test "$mb" = "$onto" &&
576+
test "$mb" = "$onto" && test -z "$restrict_revision" &&
576577
# linear history?
577578
! (git rev-list --parents "$onto".."$orig_head" | sane_grep " .* ") > /dev/null
578579
then
@@ -626,7 +627,7 @@ if test -n "$rebase_root"
626627
then
627628
revisions="$onto..$orig_head"
628629
else
629-
revisions="$upstream..$orig_head"
630+
revisions="${restrict_revision-$upstream}..$orig_head"
630631
fi
631632

632633
run_specific_rebase

t/t3400-rebase.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,29 @@ test_expect_success 'default to common base in @{upstream}s reflog if no upstrea
169169
test_cmp expect actual
170170
'
171171

172+
test_expect_success 'cherry-picked commits and fork-point work together' '
173+
git checkout default-base &&
174+
echo Amended >A &&
175+
git commit -a --no-edit --amend &&
176+
test_commit B B &&
177+
test_commit new_B B "New B" &&
178+
test_commit C C &&
179+
git checkout default &&
180+
git reset --hard default-base@{4} &&
181+
test_commit D D &&
182+
git cherry-pick -2 default-base^ &&
183+
test_commit final_B B "Final B" &&
184+
git rebase &&
185+
echo Amended >expect &&
186+
test_cmp A expect &&
187+
echo "Final B" >expect &&
188+
test_cmp B expect &&
189+
echo C >expect &&
190+
test_cmp C expect &&
191+
echo D >expect &&
192+
test_cmp D expect
193+
'
194+
172195
test_expect_success 'rebase -q is quiet' '
173196
git checkout -b quiet topic &&
174197
git rebase -q master >output.out 2>&1 &&

0 commit comments

Comments
 (0)