From: Thomas Rast <trast@student.ethz.ch>
To: git@vger.kernel.org
Cc: Junio C Hamano <junio@pobox.com>, bss@iguanasuicide.net
Subject: [INTERDIFF v3 2/4] rebase: learn to rebase root commit
Date: Fri, 2 Jan 2009 23:41:32 +0100 [thread overview]
Message-ID: <200901022341.36562.trast@student.ethz.ch> (raw)
In-Reply-To: <7c74d8be216b4667f470e34644c4aa26dcfe0cfb.1230935095.git.trast@student.ethz.ch>
The interdiff to v2.
diff --git a/git-rebase.sh b/git-rebase.sh
index 89de3c4..9437e51 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -354,17 +354,20 @@ if test -z "$rebase_root"; then
shift
upstream=`git rev-parse --verify "${upstream_name}^0"` ||
die "invalid upstream $upstream_name"
+ unset root_flag
+else
+ test -z "$newbase" && die "--root must be used with --onto"
+ unset upstream_name
+ unset upstream
+ root_flag="--root"
fi
-test ! -z "$rebase_root" -a -z "$newbase" &&
- die "--root must be used with --onto"
-
# Make sure the branch to rebase onto is valid.
onto_name=${newbase-"$upstream_name"}
onto=$(git rev-parse --verify "${onto_name}^0") || exit
# If a hook exists, give it a chance to interrupt
-run_pre_rebase_hook ${upstream_name+"$upstream_name"} "$@"
+run_pre_rebase_hook $root_flag $upstream_name "$@"
# If the branch to rebase is given, that is the branch we will rebase
# $branch_name -- branch being rebased, or HEAD (already detached)
@@ -403,8 +406,8 @@ case "$#" in
esac
orig_head=$branch
-# Now we are rebasing commits $upstream..$branch (or simply $branch
-# with --root) on top of $onto
+# Now we are rebasing commits $upstream..$branch (or with --root,
+# everything leading up to $branch) on top of $onto
# Check if we are already based on $onto with linear history,
# but this should be done only when upstream and onto are the same.
@@ -441,17 +444,15 @@ then
fi
if test ! -z "$rebase_root"; then
- revisions="$orig_head"
- fp_flag="--root"
+ revisions="$onto..$orig_head"
else
revisions="$upstream..$orig_head"
- fp_flag="--ignore-if-in-upstream"
fi
if test -z "$do_merge"
then
- git format-patch -k --stdout --full-index "$fp_flag" \
- "$revisions" |
+ git format-patch -k --stdout --full-index --ignore-if-in-upstream \
+ $root_flag "$revisions" |
git am $git_am_opt --rebasing --resolvemsg="$RESOLVEMSG" &&
move_to_original_branch
ret=$?
diff --git a/t/t3412-rebase-root.sh b/t/t3412-rebase-root.sh
index 63ec5e6..1978512 100755
--- a/t/t3412-rebase-root.sh
+++ b/t/t3412-rebase-root.sh
@@ -15,7 +15,9 @@ test_expect_success 'prepare repository' '
git commit -m 2 &&
git symbolic-ref HEAD refs/heads/other &&
rm .git/index &&
- rm A &&
+ echo 1 > A &&
+ git add A &&
+ git commit -m 1b &&
echo 3 > B &&
git add B &&
git commit -m 3 &&
@@ -28,6 +30,14 @@ test_expect_success 'rebase --root expects --onto' '
test_must_fail git rebase --root
'
+test_expect_success 'setup pre-rebase hook' '
+ mkdir -p .git/hooks &&
+ cat >.git/hooks/pre-rebase <<EOF &&
+#!$SHELL_PATH
+echo "\$1,\$2" >.git/PRE-REBASE-INPUT
+EOF
+ chmod +x .git/hooks/pre-rebase
+'
cat > expect <<EOF
4
3
@@ -42,6 +52,10 @@ test_expect_success 'rebase --root --onto <newbase>' '
test_cmp expect rebased
'
+test_expect_success 'pre-rebase got correct input (1)' '
+ test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,
+'
+
test_expect_success 'rebase --root --onto <newbase> <branch>' '
git branch work2 other &&
git rebase --root --onto master work2 &&
@@ -49,4 +63,24 @@ test_expect_success 'rebase --root --onto <newbase> <branch>' '
test_cmp expect rebased2
'
+test_expect_success 'pre-rebase got correct input (2)' '
+ test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,work2
+'
+
+test_expect_success 'setup pre-rebase hook that fails' '
+ mkdir -p .git/hooks &&
+ cat >.git/hooks/pre-rebase <<EOF &&
+#!$SHELL_PATH
+false
+EOF
+ chmod +x .git/hooks/pre-rebase
+'
+
+test_expect_success 'pre-rebase hook stops rebase' '
+ git checkout -b stops1 other &&
+ GIT_EDITOR=: test_must_fail git rebase --root --onto master &&
+ test "z$(git symbolic-ref HEAD)" = zrefs/heads/stops1
+ test 0 = $(git rev-list other...stops1 | wc -l)
+'
+
test_done
--
Thomas Rast
trast@{inf,student}.ethz.ch
next prev parent reply other threads:[~2009-01-02 22:42 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-12-29 16:45 [PATCH 0/3] rebase --root Thomas Rast
[not found] ` <cover.1230569041.git.trast@student.ethz.ch>
2008-12-29 16:45 ` rebase: learn to rebase root commit Thomas Rast
2008-12-29 16:45 ` rebase -i: " Thomas Rast
2008-12-29 21:49 ` Thomas Rast
2008-12-29 22:21 ` Boyd Stephen Smith Jr.
2008-12-30 12:23 ` Thomas Rast
2008-12-30 12:29 ` [PATCH v2 1/3] rebase: " Thomas Rast
2008-12-30 12:29 ` [PATCH v2 2/3] rebase -i: " Thomas Rast
2008-12-30 12:29 ` [PATCH v2 3/3] rebase: update documentation for --root Thomas Rast
2009-01-01 21:00 ` [PATCH v2 1/3] rebase: learn to rebase root commit Junio C Hamano
2009-01-02 18:58 ` Johannes Schindelin
2009-01-02 22:20 ` Thomas Rast
2009-01-02 22:28 ` [PATCH v3 1/4] rebase -i: execute hook only after argument checking Thomas Rast
2009-01-02 22:28 ` [PATCH v3 2/4] rebase: learn to rebase root commit Thomas Rast
2009-01-02 22:28 ` [PATCH v3 3/4] rebase -i: " Thomas Rast
2009-01-02 22:28 ` [PATCH v3 4/4] rebase: update documentation for --root Thomas Rast
2009-01-02 22:41 ` [INTERDIFF v3 3/4] rebase -i: learn to rebase root commit Thomas Rast
2009-01-02 22:41 ` Thomas Rast [this message]
2009-01-02 23:06 ` [PATCH v3 2/4] rebase: " Junio C Hamano
2009-01-02 23:45 ` [PATCH v3.1] " Thomas Rast
2009-01-05 17:35 ` [PATCH v3.2] " Thomas Rast
2009-01-06 8:19 ` Junio C Hamano
2009-01-02 22:49 ` [PATCH v2 1/3] " Junio C Hamano
2009-01-02 22:54 ` Thomas Rast
2009-01-02 23:07 ` Junio C Hamano
2008-12-30 8:22 ` rebase -i: " Junio C Hamano
2008-12-29 16:45 ` rebase: update documentation for --root Thomas Rast
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=200901022341.36562.trast@student.ethz.ch \
--to=trast@student.ethz.ch \
--cc=bss@iguanasuicide.net \
--cc=git@vger.kernel.org \
--cc=junio@pobox.com \
/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).