Skip to content

Commit

Permalink
Merge branch 'rr/rebase-autostash'
Browse files Browse the repository at this point in the history
* rr/rebase-autostash:
  rebase: implement --[no-]autostash and rebase.autostash
  rebase --merge: return control to caller, for housekeeping
  rebase -i: return control to caller, for housekeeping
  am: return control to caller, for housekeeping
  rebase: prepare to do generic housekeeping
  rebase -i: don't error out if $state_dir already exists
  am: tighten a conditional that checks for $dotest
  • Loading branch information
Junio C Hamano committed Jun 11, 2013
2 parents 52faa0e + 5879477 commit 45acb75
Show file tree
Hide file tree
Showing 8 changed files with 235 additions and 16 deletions.
8 changes: 8 additions & 0 deletions Documentation/config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1867,6 +1867,14 @@ rebase.stat::
rebase.autosquash::
If set to true enable '--autosquash' option by default.

rebase.autostash::
When set to true, automatically create a temporary stash
before the operation begins, and apply it after the operation
ends. This means that you can run rebase on a dirty worktree.
However, use with care: the final stash application after a
successful rebase might result in non-trivial conflicts.
Defaults to false.

receive.autogc::
By default, git-receive-pack will run "git-gc --auto" after
receiving data from git-push and updating refs. You can stop
Expand Down
10 changes: 10 additions & 0 deletions Documentation/git-rebase.txt
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ rebase.stat::
rebase.autosquash::
If set to true enable '--autosquash' option by default.

rebase.autostash::
If set to true enable '--autostash' option by default.

OPTIONS
-------
--onto <newbase>::
Expand Down Expand Up @@ -394,6 +397,13 @@ If the '--autosquash' option is enabled by default using the
configuration variable `rebase.autosquash`, this option can be
used to override and disable this setting.

--[no-]autostash::
Automatically create a temporary stash before the operation
begins, and apply it after the operation ends. This means
that you can run rebase on a dirty worktree. However, use
with care: the final stash application after a successful
rebase might result in non-trivial conflicts.

--no-ff::
With --interactive, cherry-pick all rebased commits instead of
fast-forwarding over the unchanged ones. This ensures that the
Expand Down
13 changes: 10 additions & 3 deletions git-am.sh
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,8 @@ done
# If the dotest directory exists, but we have finished applying all the
# patches in them, clear it out.
if test -d "$dotest" &&
test -f "$dotest/last" &&
test -f "$dotest/next" &&
last=$(cat "$dotest/last") &&
next=$(cat "$dotest/next") &&
test $# != 0 &&
Expand All @@ -454,7 +456,7 @@ then
rm -fr "$dotest"
fi

if test -d "$dotest"
if test -d "$dotest" && test -f "$dotest/last" && test -f "$dotest/next"
then
case "$#,$skip$resolved$abort" in
0,*t*)
Expand Down Expand Up @@ -904,5 +906,10 @@ if test -s "$dotest"/rewritten; then
fi
fi

rm -fr "$dotest"
git gc --auto
# If am was called with --rebasing (from git-rebase--am), it's up to
# the caller to take care of housekeeping.
if ! test -f "$dotest/rebasing"
then
rm -fr "$dotest"
git gc --auto
fi
8 changes: 4 additions & 4 deletions git-rebase--am.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ case "$action" in
continue)
git am --resolved --resolvemsg="$resolvemsg" &&
move_to_original_branch
exit
return
;;
skip)
git am --skip --resolvemsg="$resolvemsg" &&
move_to_original_branch
exit
return
;;
esac

Expand Down Expand Up @@ -56,7 +56,7 @@ else
As a result, git cannot rebase them.
EOF
exit $?
return $?
fi

git am $git_am_opt --rebasing --resolvemsg="$resolvemsg" <"$GIT_DIR/rebased-patches"
Expand All @@ -68,7 +68,7 @@ fi
if test 0 != $ret
then
test -d "$state_dir" && write_basic_state
exit $ret
return $ret
fi

move_to_original_branch
11 changes: 6 additions & 5 deletions git-rebase--interactive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -628,17 +628,16 @@ do_next () {
"$GIT_DIR"/hooks/post-rewrite rebase < "$rewritten_list"
true # we don't care if this hook failed
fi &&
rm -rf "$state_dir" &&
git gc --auto &&
warn "Successfully rebased and updated $head_name."

exit
return 1 # not failure; just to break the do_rest loop
}

# can only return 0, when the infinite loop breaks
do_rest () {
while :
do
do_next
do_next || break
done
}

Expand Down Expand Up @@ -805,11 +804,13 @@ first and then run 'git rebase --continue' again."

require_clean_work_tree "rebase"
do_rest
return 0
;;
skip)
git rerere clear

do_rest
return 0
;;
edit-todo)
git stripspace --strip-comments <"$todo" >"$todo".new
Expand Down Expand Up @@ -842,7 +843,7 @@ then
fi

orig_head=$(git rev-parse --verify HEAD) || die "No HEAD?"
mkdir "$state_dir" || die "Could not create temporary $state_dir"
mkdir -p "$state_dir" || die "Could not create temporary $state_dir"

: > "$state_dir"/interactive || die "Could not mark as interactive"
write_basic_state
Expand Down
5 changes: 2 additions & 3 deletions git-rebase--merge.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ finish_rb_merge () {
"$GIT_DIR"/hooks/post-rewrite rebase <"$state_dir"/rewritten
fi
fi
rm -r "$state_dir"
say All done.
}

Expand All @@ -110,7 +109,7 @@ continue)
continue_merge
done
finish_rb_merge
exit
return
;;
skip)
read_state
Expand All @@ -122,7 +121,7 @@ skip)
continue_merge
done
finish_rb_merge
exit
return
;;
esac

Expand Down
48 changes: 47 additions & 1 deletion git-rebase.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ git-rebase --continue | --abort | --skip | --edit-todo
Available options are
v,verbose! display a diffstat of what changed upstream
q,quiet! be quiet. implies --no-stat
autostash! automatically stash/stash pop before and after
onto=! rebase onto given branch instead of upstream
p,preserve-merges! try to recreate merges instead of ignoring them
s,strategy=! use the given merge strategy
Expand Down Expand Up @@ -64,6 +65,7 @@ apply_dir="$GIT_DIR"/rebase-apply
verbose=
diffstat=
test "$(git config --bool rebase.stat)" = true && diffstat=t
autostash="$(git config --bool rebase.autostash || echo false)"
git_am_opt=
rebase_root=
force_rebase=
Expand Down Expand Up @@ -143,13 +145,42 @@ move_to_original_branch () {
esac
}

finish_rebase () {
if test -f "$state_dir/autostash"
then
stash_sha1=$(cat "$state_dir/autostash")
if git stash apply $stash_sha1 2>&1 >/dev/null
then
echo "$(gettext 'Applied autostash.')"
else
ref_stash=refs/stash &&
>>"$GIT_DIR/logs/$ref_stash" &&
git update-ref -m "autostash" $ref_stash $stash_sha1 ||
die "$(eval_gettext 'Cannot store $stash_sha1')"

gettext 'Applying autostash resulted in conflicts.
Your changes are safe in the stash.
You can run "git stash pop" or "git stash drop" it at any time.
'
fi
fi
git gc --auto &&
rm -rf "$state_dir"
}

run_specific_rebase () {
if [ "$interactive_rebase" = implied ]; then
GIT_EDITOR=:
export GIT_EDITOR
autosquash=
fi
. git-rebase--$type
ret=$?
if test $ret -eq 0
then
finish_rebase
fi
exit $ret
}

run_pre_rebase_hook () {
Expand Down Expand Up @@ -241,6 +272,9 @@ do
--stat)
diffstat=t
;;
--autostash)
autostash=true
;;
-v)
verbose=t
diffstat=t
Expand Down Expand Up @@ -341,7 +375,7 @@ abort)
;;
esac
output git reset --hard $orig_head
rm -r "$state_dir"
finish_rebase
exit
;;
edit-todo)
Expand Down Expand Up @@ -480,6 +514,18 @@ case "$#" in
;;
esac

if test "$autostash" = true && ! (require_clean_work_tree) 2>/dev/null
then
stash_sha1=$(git stash create "autostash") ||
die "$(gettext 'Cannot autostash')"

mkdir -p "$state_dir" &&
echo $stash_sha1 >"$state_dir/autostash" &&
stash_abbrev=$(git rev-parse --short $stash_sha1) &&
echo "$(eval_gettext 'Created autostash: $stash_abbrev')" &&
git reset --hard
fi

require_clean_work_tree "rebase" "$(gettext "Please commit or stash them.")"

# Now we are rebasing commits $upstream..$orig_head (or with --root,
Expand Down
Loading

0 comments on commit 45acb75

Please sign in to comment.