From: Simon Sasburg <simon.sasburg@gmail.com>
To: gitster@pobox.com
Cc: git@vger.kernel.org, Simon Sasburg <Simon.Sasburg@gmail.com>
Subject: [PATCH 1/3] Introduce --dirty option to git-rebase, allowing you to start from a dirty state.
Date: Thu, 1 Nov 2007 22:30:22 +0100 [thread overview]
Message-ID: <1193952624-608-2-git-send-email-Simon.Sasburg@gmail.com> (raw)
In-Reply-To: <1193952624-608-1-git-send-email-Simon.Sasburg@gmail.com>
This will store the difference between HEAD and the index into a commit,
and the difference between the index and the working tree into a commit.
When the rebase is done, it restores the index and the working tree
by undoing these commits with git-reset.
Signed-off-by: Simon Sasburg <Simon.Sasburg@gmail.com>
---
git-rebase.sh | 63 ++++++++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 54 insertions(+), 9 deletions(-)
diff --git a/git-rebase.sh b/git-rebase.sh
index 224cca9..c923c3b 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -42,6 +42,7 @@ To restore the original branch and stop rebasing run \"git rebase --abort\".
unset newbase
strategy=recursive
do_merge=
+fix_dirty=
dotest=$GIT_DIR/.dotest-merge
prec=4
verbose=
@@ -117,9 +118,39 @@ call_merge () {
finish_rb_merge () {
rm -r "$dotest"
+ restore_dirty_state
echo "All done."
}
+store_dirty_state () {
+ echo "Storing dirty index/working tree"
+ diff=$(git diff --cached)
+ case "$diff" in
+ ?*) git commit -m "REBASE--dirty: store HEAD..index diff"
+ ;;
+ esac
+ diff=$(git diff)
+ case "$diff" in
+ ?*) git commit -a -m "REBASE--dirty: store index..workingtree diff"
+ ;;
+ esac
+}
+
+restore_dirty_state () {
+ lastmsg=$(git-rev-list HEAD^..HEAD --pretty=oneline | sed "s:[^ ]* ::")
+ if test "$lastmsg" = "REBASE--dirty: store index..workingtree diff"
+ then
+ echo "Restoring dirty index state"
+ git reset --mixed HEAD^
+ fi
+ lastmsg=$(git-rev-list HEAD^..HEAD --pretty=oneline | sed "s:[^ ]* ::")
+ if test "$lastmsg" = "REBASE--dirty: store HEAD..index diff"
+ then
+ echo "Restoring dirty working dir state"
+ git reset --soft HEAD^
+ fi
+}
+
is_interactive () {
test -f "$dotest"/interactive ||
while :; do case $#,"$1" in 0,|*,-i|*,--interactive) break ;; esac
@@ -156,6 +187,10 @@ do
git am --resolved --3way --resolvemsg="$RESOLVEMSG"
exit
;;
+ --dirty)
+ do_merge=t
+ fix_dirty=t
+ ;;
--skip)
if test -d "$dotest"
then
@@ -188,6 +223,7 @@ do
die "No rebase in progress?"
fi
git reset --hard ORIG_HEAD
+ restore_dirty_state
exit
;;
--onto)
@@ -253,15 +289,19 @@ 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 tree must be really really clean, unless --dirty is given.
+if test "$fix_dirty" = ""
+then
+ 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
+
+fi
# The upstream head must be given. Make sure it is valid.
upstream_name="$1"
@@ -318,6 +358,11 @@ then
GIT_PAGER='' git diff --stat --summary "$mb" "$onto"
fi
+if test "$fix_dirty" = "t"
+then
+ store_dirty_state
+fi
+
# Rewind the head to "$onto"; this saves our current head in ORIG_HEAD.
echo "First, rewinding head to replay your work on top of it..."
git-reset --hard "$onto"
--
1.5.3.4.502.g37c97
next prev parent reply other threads:[~2007-11-01 21:33 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-01 21:30 [RFC PATCH 0/3] Starting rebase from dirty tree Simon Sasburg
2007-11-01 21:30 ` Simon Sasburg [this message]
2007-11-01 21:30 ` [PATCH 2/3] Implement --dirty for git-rebase--interactive Simon Sasburg
2007-11-01 21:30 ` [PATCH 3/3] Make git-svn rebase --dirty pass along --dirty to git-rebase Simon Sasburg
2007-11-12 19:51 ` [PATCH 2/3] Implement --dirty for git-rebase--interactive Junio C Hamano
2007-11-01 22:30 ` [PATCH 1/3] Introduce --dirty option to git-rebase, allowing you to start from a dirty state Junio C Hamano
2007-11-01 22:36 ` Junio C Hamano
2007-11-02 5:08 ` Shawn O. Pearce
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=1193952624-608-2-git-send-email-Simon.Sasburg@gmail.com \
--to=simon.sasburg@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@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).