* [PATCH 2/2] rebase: allow starting from a dirty tree.
@ 2007-07-09 7:59 Junio C Hamano
0 siblings, 0 replies; only message in thread
From: Junio C Hamano @ 2007-07-09 7:59 UTC (permalink / raw)
To: git
This uses the new "git stash create" interface to stash away the dirty state
you have in your working tree before starting a rebase, and then replaying
it when you are done with stashing.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
* Not 'master' material yet without heavy field testing, and it is
not a good time to do so before 1.5.3-rc1, so this will stay
in 'pu' and perhaps in 'next' for now.
git-rebase.sh | 66 ++++++++++++++++++++++++++++++++++++++++++++------------
1 files changed, 52 insertions(+), 14 deletions(-)
diff --git a/git-rebase.sh b/git-rebase.sh
index cbafa14..602723a 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -116,10 +116,25 @@ call_merge () {
}
finish_rb_merge () {
+ if test -f "$dotest/stash"
+ then
+ stash=$(cat "$dotest/stash")
+ git stash apply --index "$stash"
+ fi
rm -r "$dotest"
echo "All done."
}
+unstash_and_exit () {
+ err=$?
+ if test -f "$1" && test $err = 0
+ then
+ stash=$(cat "$1")
+ git stash apply --index "$stash"
+ fi
+ exit $err
+}
+
is_interactive () {
test -f "$dotest"/interactive ||
while case $#,"$1" in 0,|*,-i|*,--interactive) break ;; esac
@@ -155,7 +170,7 @@ do
exit
fi
git am --resolved --3way --resolvemsg="$RESOLVEMSG"
- exit
+ unstash_and_exit .dotest/stash
;;
--skip)
if test -d "$dotest"
@@ -175,20 +190,29 @@ do
exit
fi
git am -3 --skip --resolvemsg="$RESOLVEMSG"
- exit
+ unstash_and_exit .dotest/stash
;;
--abort)
git rerere clear
if test -d "$dotest"
then
+ if test -f "$dotest/stash"
+ then
+ stash=$(cat "$dotest/stash")
+ fi
rm -r "$dotest"
elif test -d .dotest
then
+ if test -f ".dotest/stash"
+ then
+ stash=$(cat ".dotest/stash")
+ fi
rm -r .dotest
else
die "No rebase in progress?"
fi
git reset --hard ORIG_HEAD
+ test -z "$stash" || git stash apply --index "$stash"
exit
;;
--onto)
@@ -252,16 +276,6 @@ else
fi
fi
-# The tree must be really really clean.
-git update-index --refresh || exit
-diff=$(git diff-index --cached --name-status -r HEAD)
-case "$diff" in
-?*) echo "cannot rebase: your index is not up-to-date"
- echo "$diff"
- exit 1
- ;;
-esac
-
# The upstream head must be given. Make sure it is valid.
upstream_name="$1"
upstream=`git rev-parse --verify "${upstream_name}^0"` ||
@@ -271,11 +285,20 @@ upstream=`git rev-parse --verify "${upstream_name}^0"` ||
onto_name=${newbase-"$upstream_name"}
onto=$(git rev-parse --verify "${onto_name}^0") || exit
+# The tree must be clean enough for us to create a stash
+stash=$(git stash create) || exit
+if test -n "$stash"
+then
+ echo >&2 "Stashed away your working tree changes"
+ git reset --hard
+fi
+
# If a hook exists, give it a chance to interrupt
if test -x "$GIT_DIR/hooks/pre-rebase"
then
"$GIT_DIR/hooks/pre-rebase" ${1+"$@"} || {
echo >&2 "The pre-rebase hook refused to rebase."
+ test -z "$stash" || git stash apply --index "$stash"
exit 1
}
fi
@@ -284,7 +307,10 @@ fi
case "$#" in
2)
branch_name="$2"
- git-checkout "$2" || usage
+ git-checkout "$2" || {
+ test -z "$stash" || git stash apply --index "$stash"
+ usage
+ }
;;
*)
if branch_name=`git symbolic-ref -q HEAD`
@@ -307,6 +333,7 @@ if test "$upstream" = "$onto" && test "$mb" = "$onto" &&
! git rev-list --parents "$onto".."$branch" | grep " .* " > /dev/null
then
echo >&2 "Current branch $branch_name is up to date."
+ test -z "$stash" || git stash apply --index "$stash"
exit 0
fi
@@ -326,6 +353,7 @@ git-reset --hard "$onto"
if test "$mb" = "$branch"
then
echo >&2 "Fast-forwarded $branch_name to $onto_name."
+ test -z "$stash" || git stash apply --index "$stash"
exit 0
fi
@@ -333,7 +361,16 @@ if test -z "$do_merge"
then
git format-patch -k --stdout --full-index --ignore-if-in-upstream "$upstream"..ORIG_HEAD |
git am $git_am_opt --binary -3 -k --resolvemsg="$RESOLVEMSG"
- exit $?
+ err=$?
+
+ if test $err = 0
+ then
+ test -z "$stash" || git stash apply --index "$stash"
+ exit
+ else
+ test -z "$stash" || echo "$stash" >.dotest/stash
+ exit $err
+ fi
fi
# start doing a rebase with git-merge
@@ -344,6 +381,7 @@ echo "$onto" > "$dotest/onto"
echo "$onto_name" > "$dotest/onto_name"
prev_head=`git rev-parse HEAD^0`
echo "$prev_head" > "$dotest/prev_head"
+test -z "$stash" || echo "$stash" >"$dotest/stash"
msgnum=0
for cmt in `git rev-list --reverse --no-merges "$upstream"..ORIG_HEAD`
--
1.5.3.rc0.81.g1ed84
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2007-07-09 7:59 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-07-09 7:59 [PATCH 2/2] rebase: allow starting from a dirty tree Junio C Hamano
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox