rebase: fix run_specific_rebase's use of "return" on FreeBSD
[gitweb.git] / git-rebase.sh
index b2f1c76dc3ede707870564a8ba73af6d1753e95c..7ab6434a4ff9e95d639bdf7914e50fb327abe8af 100755 (executable)
@@ -143,15 +143,31 @@ move_to_original_branch () {
        esac
 }
 
-run_specific_rebase () {
+run_specific_rebase_internal () {
        if [ "$interactive_rebase" = implied ]; then
                GIT_EDITOR=:
                export GIT_EDITOR
                autosquash=
        fi
+       # On FreeBSD, the shell's "return" returns from the current
+       # function, not from the current file inclusion.
+       # run_specific_rebase_internal has the file inclusion as a
+       # last statement, so POSIX and FreeBSD's return will do the
+       # same thing.
        . git-rebase--$type
 }
 
+run_specific_rebase () {
+       run_specific_rebase_internal
+       ret=$?
+       if test $ret -eq 0
+       then
+               git gc --auto &&
+               rm -rf "$state_dir"
+       fi
+       exit $ret
+}
+
 run_pre_rebase_hook () {
        if test -z "$ok_to_skip_pre_rebase" &&
           test -x "$GIT_DIR/hooks/pre-rebase"
@@ -473,7 +489,7 @@ case "$#" in
                head_name="detached HEAD"
                branch_name=HEAD ;# detached
        fi
-       orig_head=$(git rev-parse --verify "${branch_name}^0") || exit
+       orig_head=$(git rev-parse --verify HEAD) || exit
        ;;
 *)
        die "BUG: unexpected number of arguments left to parse"