@@ -13,6 +13,7 @@ git-rebase --continue | --abort | --skip | --edit-todo
1313 Available options are
1414v,verbose! display a diffstat of what changed upstream
1515q,quiet! be quiet. implies --no-stat
16+ autostash! automatically stash/stash pop before and after
1617onto=! rebase onto given branch instead of upstream
1718p,preserve-merges! try to recreate merges instead of ignoring them
1819s,strategy=! use the given merge strategy
@@ -64,6 +65,7 @@ apply_dir="$GIT_DIR"/rebase-apply
6465verbose=
6566diffstat=
6667test " $( git config --bool rebase.stat) " = true && diffstat=t
68+ autostash=" $( git config --bool rebase.autostash || echo false) "
6769git_am_opt=
6870rebase_root=
6971force_rebase=
@@ -143,13 +145,42 @@ move_to_original_branch () {
143145 esac
144146}
145147
148+ finish_rebase () {
149+ if test -f " $state_dir /autostash"
150+ then
151+ stash_sha1=$( cat " $state_dir /autostash" )
152+ if git stash apply $stash_sha1 2>&1 > /dev/null
153+ then
154+ echo " $( gettext ' Applied autostash.' ) "
155+ else
156+ ref_stash=refs/stash &&
157+ >> " $GIT_DIR /logs/$ref_stash " &&
158+ git update-ref -m " autostash" $ref_stash $stash_sha1 ||
159+ die " $( eval_gettext ' Cannot store $stash_sha1' ) "
160+
161+ gettext ' Applying autostash resulted in conflicts.
162+ Your changes are safe in the stash.
163+ You can run "git stash pop" or "git stash drop" it at any time.
164+ '
165+ fi
166+ fi
167+ git gc --auto &&
168+ rm -rf " $state_dir "
169+ }
170+
146171run_specific_rebase () {
147172 if [ " $interactive_rebase " = implied ]; then
148173 GIT_EDITOR=:
149174 export GIT_EDITOR
150175 autosquash=
151176 fi
152177 . git-rebase--$type
178+ ret=$?
179+ if test $ret -eq 0
180+ then
181+ finish_rebase
182+ fi
183+ exit $ret
153184}
154185
155186run_pre_rebase_hook () {
241272 --stat)
242273 diffstat=t
243274 ;;
275+ --autostash)
276+ autostash=true
277+ ;;
244278 -v)
245279 verbose=t
246280 diffstat=t
@@ -341,7 +375,7 @@ abort)
341375 ;;
342376 esac
343377 output git reset --hard $orig_head
344- rm -r " $state_dir "
378+ finish_rebase
345379 exit
346380 ;;
347381edit-todo)
@@ -480,6 +514,18 @@ case "$#" in
480514 ;;
481515esac
482516
517+ if test " $autostash " = true && ! (require_clean_work_tree) 2> /dev/null
518+ then
519+ stash_sha1=$( git stash create " autostash" ) ||
520+ die " $( gettext ' Cannot autostash' ) "
521+
522+ mkdir -p " $state_dir " &&
523+ echo $stash_sha1 > " $state_dir /autostash" &&
524+ stash_abbrev=$( git rev-parse --short $stash_sha1 ) &&
525+ echo " $( eval_gettext ' Created autostash: $stash_abbrev' ) " &&
526+ git reset --hard
527+ fi
528+
483529require_clean_work_tree " rebase" " $( gettext " Please commit or stash them." ) "
484530
485531# Now we are rebasing commits $upstream..$orig_head (or with --root,
0 commit comments