Signed-off-by: Simon Sasburg <Simon.Sasburg@xxxxxxxxx> --- git-rebase--interactive.sh | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 40 insertions(+), 2 deletions(-) diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh index 76dc679..326076b 100755 --- a/git-rebase--interactive.sh +++ b/git-rebase--interactive.sh @@ -25,6 +25,7 @@ REWRITTEN="$DOTEST"/rewritten PRESERVE_MERGES= STRATEGY= VERBOSE= +FIX_DIRTY= test -d "$REWRITTEN" && PRESERVE_MERGES=t test -f "$DOTEST"/strategy && STRATEGY="$(cat "$DOTEST"/strategy)" test -f "$DOTEST"/verbose && VERBOSE=t @@ -56,6 +57,35 @@ require_clean_work_tree () { die "Working tree is dirty" } +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 +} + ORIG_REFLOG_ACTION="$GIT_REFLOG_ACTION" comment_for_reflog () { @@ -329,6 +359,7 @@ do_next () { test ! -f "$DOTEST"/verbose || git diff-tree --stat $(cat "$DOTEST"/head)..HEAD } && + restore_dirty_state && rm -rf "$DOTEST" && git gc --auto && warn "Successfully rebased and updated $HEADNAME." @@ -378,6 +409,7 @@ do ;; esac && output git reset --hard $HEAD && + restore_dirty_state && rm -rf "$DOTEST" exit ;; @@ -417,6 +449,9 @@ do ''|-h) usage ;; + --dirty) + FIX_DIRTY=t + ;; *) test -d "$DOTEST" && die "Interactive rebase already started" @@ -435,7 +470,7 @@ do ;; esac - require_clean_work_tree + test "$FIX_DIRTY" = "t" || require_clean_work_tree if test ! -z "$2" then @@ -445,9 +480,12 @@ do die "Could not checkout $2" fi - HEAD=$(git rev-parse --verify HEAD) || die "No HEAD?" UPSTREAM=$(git rev-parse --verify "$1") || die "Invalid base" + test "$FIX_DIRTY" = "t" && store_dirty_state + + HEAD=$(git rev-parse --verify HEAD) || die "No HEAD?" + mkdir "$DOTEST" || die "Could not create temporary $DOTEST" test -z "$ONTO" && ONTO=$UPSTREAM -- 1.5.3.4.502.g37c97 - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html