git-rebase--am.shon commit rebase: avoid non-function use of "return" on FreeBSD (9f50d32)
   1# This shell script fragment is sourced by git-rebase to implement
   2# its default, fast, patch-based, non-interactive mode.
   3#
   4# Copyright (c) 2010 Junio C Hamano.
   5#
   6
   7# The whole contents of this file is run by dot-sourcing it from
   8# inside a shell function.  It used to be that "return"s we see
   9# below were not inside any function, and expected to return
  10# to the function that dot-sourced us.
  11#
  12# However, FreeBSD /bin/sh misbehaves on such a construct and
  13# continues to run the statements that follow such a "return".
  14# As a work-around, we introduce an extra layer of a function
  15# here, and immediately call it after defining it.
  16git_rebase__am () {
  17
  18case "$action" in
  19continue)
  20        git am --resolved --resolvemsg="$resolvemsg" &&
  21        move_to_original_branch
  22        return
  23        ;;
  24skip)
  25        git am --skip --resolvemsg="$resolvemsg" &&
  26        move_to_original_branch
  27        return
  28        ;;
  29esac
  30
  31test -n "$rebase_root" && root_flag=--root
  32
  33ret=0
  34if test -n "$keep_empty"
  35then
  36        # we have to do this the hard way.  git format-patch completely squashes
  37        # empty commits and even if it didn't the format doesn't really lend
  38        # itself well to recording empty patches.  fortunately, cherry-pick
  39        # makes this easy
  40        git cherry-pick --allow-empty "$revisions"
  41        ret=$?
  42else
  43        rm -f "$GIT_DIR/rebased-patches"
  44
  45        git format-patch -k --stdout --full-index --ignore-if-in-upstream \
  46                --src-prefix=a/ --dst-prefix=b/ --no-renames --no-cover-letter \
  47                $root_flag "$revisions" >"$GIT_DIR/rebased-patches"
  48        ret=$?
  49
  50        if test 0 != $ret
  51        then
  52                rm -f "$GIT_DIR/rebased-patches"
  53                case "$head_name" in
  54                refs/heads/*)
  55                        git checkout -q "$head_name"
  56                        ;;
  57                *)
  58                        git checkout -q "$orig_head"
  59                        ;;
  60                esac
  61
  62                cat >&2 <<-EOF
  63
  64                git encountered an error while preparing the patches to replay
  65                these revisions:
  66
  67                    $revisions
  68
  69                As a result, git cannot rebase them.
  70                EOF
  71                return $?
  72        fi
  73
  74        git am $git_am_opt --rebasing --resolvemsg="$resolvemsg" <"$GIT_DIR/rebased-patches"
  75        ret=$?
  76
  77        rm -f "$GIT_DIR/rebased-patches"
  78fi
  79
  80if test 0 != $ret
  81then
  82        test -d "$state_dir" && write_basic_state
  83        return $ret
  84fi
  85
  86move_to_original_branch
  87
  88}
  89# ... and then we call the whole thing.
  90git_rebase__am