{"thread":{"id":"8945","subject":"[PATCH 2/2] rebase: allow starting from a dirty tree.","startedAt":"2007-07-09T07:59:18Z","lastAt":"2007-07-09T07:59:18Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"46842","messageId":"7vwsxauhwp.fsf@assigned-by-dhcp.cox.net","threadId":"8945","inReplyTo":null,"subject":"[PATCH 2/2] rebase: allow starting from a dirty tree.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-07-09T07:59:18Z","receivedAt":"2007-07-09T07:59:18Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"This uses the new \"git stash create\" interface to stash away the dirty state\nyou have in your working tree before starting a rebase, and then replaying\nit when you are done with stashing.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n\n * Not 'master' material yet without heavy field testing, and it is\n   not a good time to do so before 1.5.3-rc1, so this will stay\n   in 'pu' and perhaps in 'next' for now.\n\n git-rebase.sh |   66 ++++++++++++++++++++++++++++++++++++++++++++------------\n 1 files changed, 52 insertions(+), 14 deletions(-)\n\ndiff --git a/git-rebase.sh b/git-rebase.sh\nindex cbafa14..602723a 100755\n--- a/git-rebase.sh\n+++ b/git-rebase.sh\n@@ -116,10 +116,25 @@ call_merge () {\n }\n \n finish_rb_merge () {\n+\tif test -f \"$dotest/stash\"\n+\tthen\n+\t\tstash=$(cat \"$dotest/stash\")\n+\t\tgit stash apply --index \"$stash\"\n+\tfi\n \trm -r \"$dotest\"\n \techo \"All done.\"\n }\n \n+unstash_and_exit () {\n+\terr=$?\n+\tif test -f \"$1\" && test $err = 0\n+\tthen\n+\t\tstash=$(cat \"$1\")\n+\t\tgit stash apply --index \"$stash\"\n+\tfi\n+\texit $err\n+}\n+\n is_interactive () {\n \ttest -f \"$dotest\"/interactive ||\n \twhile case $#,\"$1\" in 0,|*,-i|*,--interactive) break ;; esac\n@@ -155,7 +170,7 @@ do\n \t\t\texit\n \t\tfi\n \t\tgit am --resolved --3way --resolvemsg=\"$RESOLVEMSG\"\n-\t\texit\n+\t\tunstash_and_exit .dotest/stash\n \t\t;;\n \t--skip)\n \t\tif test -d \"$dotest\"\n@@ -175,20 +190,29 @@ do\n \t\t\texit\n \t\tfi\n \t\tgit am -3 --skip --resolvemsg=\"$RESOLVEMSG\"\n-\t\texit\n+\t\tunstash_and_exit .dotest/stash\n \t\t;;\n \t--abort)\n \t\tgit rerere clear\n \t\tif test -d \"$dotest\"\n \t\tthen\n+\t\t\tif test -f \"$dotest/stash\"\n+\t\t\tthen\n+\t\t\t\tstash=$(cat \"$dotest/stash\")\n+\t\t\tfi\n \t\t\trm -r \"$dotest\"\n \t\telif test -d .dotest\n \t\tthen\n+\t\t\tif test -f \".dotest/stash\"\n+\t\t\tthen\n+\t\t\t\tstash=$(cat \".dotest/stash\")\n+\t\t\tfi\n \t\t\trm -r .dotest\n \t\telse\n \t\t\tdie \"No rebase in progress?\"\n \t\tfi\n \t\tgit reset --hard ORIG_HEAD\n+\t\ttest -z \"$stash\" || git stash apply --index \"$stash\"\n \t\texit\n \t\t;;\n \t--onto)\n@@ -252,16 +276,6 @@ else\n \tfi\n fi\n \n-# The tree must be really really clean.\n-git update-index --refresh || exit\n-diff=$(git diff-index --cached --name-status -r HEAD)\n-case \"$diff\" in\n-?*)\techo \"cannot rebase: your index is not up-to-date\"\n-\techo \"$diff\"\n-\texit 1\n-\t;;\n-esac\n-\n # The upstream head must be given.  Make sure it is valid.\n upstream_name=\"$1\"\n upstream=`git rev-parse --verify \"${upstream_name}^0\"` ||\n@@ -271,11 +285,20 @@ upstream=`git rev-parse --verify \"${upstream_name}^0\"` ||\n onto_name=${newbase-\"$upstream_name\"}\n onto=$(git rev-parse --verify \"${onto_name}^0\") || exit\n \n+# The tree must be clean enough for us to create a stash\n+stash=$(git stash create) || exit\n+if test -n \"$stash\"\n+then\n+\techo >&2 \"Stashed away your working tree changes\"\n+\tgit reset --hard\n+fi\n+\n # If a hook exists, give it a chance to interrupt\n if test -x \"$GIT_DIR/hooks/pre-rebase\"\n then\n \t\"$GIT_DIR/hooks/pre-rebase\" ${1+\"$@\"} || {\n \t\techo >&2 \"The pre-rebase hook refused to rebase.\"\n+\t\ttest -z \"$stash\" || git stash apply --index \"$stash\"\n \t\texit 1\n \t}\n fi\n@@ -284,7 +307,10 @@ fi\n case \"$#\" in\n 2)\n \tbranch_name=\"$2\"\n-\tgit-checkout \"$2\" || usage\n+\tgit-checkout \"$2\" || {\n+\t\ttest -z \"$stash\" || git stash apply --index \"$stash\"\n+\t\tusage\n+\t}\n \t;;\n *)\n \tif branch_name=`git symbolic-ref -q HEAD`\n@@ -307,6 +333,7 @@ if test \"$upstream\" = \"$onto\" && test \"$mb\" = \"$onto\" &&\n \t! git rev-list --parents \"$onto\"..\"$branch\" | grep \" .* \" > /dev/null\n then\n \techo >&2 \"Current branch $branch_name is up to date.\"\n+\ttest -z \"$stash\" || git stash apply --index \"$stash\"\n \texit 0\n fi\n \n@@ -326,6 +353,7 @@ git-reset --hard \"$onto\"\n if test \"$mb\" = \"$branch\"\n then\n \techo >&2 \"Fast-forwarded $branch_name to $onto_name.\"\n+\ttest -z \"$stash\" || git stash apply --index \"$stash\"\n \texit 0\n fi\n \n@@ -333,7 +361,16 @@ if test -z \"$do_merge\"\n then\n \tgit format-patch -k --stdout --full-index --ignore-if-in-upstream \"$upstream\"..ORIG_HEAD |\n \tgit am $git_am_opt --binary -3 -k --resolvemsg=\"$RESOLVEMSG\"\n-\texit $?\n+\terr=$?\n+\n+\tif test $err = 0\n+\tthen\n+\t\ttest -z \"$stash\" || git stash apply --index \"$stash\"\n+\t\texit\n+\telse\n+\t\ttest -z \"$stash\" || echo \"$stash\" >.dotest/stash\n+\t\texit $err\n+\tfi\n fi\n \n # start doing a rebase with git-merge\n@@ -344,6 +381,7 @@ echo \"$onto\" > \"$dotest/onto\"\n echo \"$onto_name\" > \"$dotest/onto_name\"\n prev_head=`git rev-parse HEAD^0`\n echo \"$prev_head\" > \"$dotest/prev_head\"\n+test -z \"$stash\" || echo \"$stash\" >\"$dotest/stash\"\n \n msgnum=0\n for cmt in `git rev-list --reverse --no-merges \"$upstream\"..ORIG_HEAD`\n-- \n1.5.3.rc0.81.g1ed84\n"}]}