6 PATCH_DIR=$LIB_DIR/patch
8 CURRENT_BRANCH="`git branch --no-color 2>/dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`"
9 PATCH_BRANCH="temp-patch"
10 ORIG_BRANCH_FILE="${CWD}/.current_branch.txt"
11 ORIG_BRANCH="`cat $ORIG_BRANCH_FILE 2>/dev/null`"
15 if test -n "$1"; then ret=$1; else ret=1; fi;
16 echo "Restore to original git branch."
17 git checkout ${ORIG_BRANCH}
18 git branch -D ${PATCH_BRANCH}
19 rm -f $ORIG_BRANCH_FILE
23 # If --cancel option is given, just reset git and exit.
24 test "$1" == "--cancel" && reset_branch 0
26 # Make sure if current branch is PATCH_BRANCH
27 test ! -f "$ORIG_BRANCH_FILE" && echo "ERROR: Original branch file ($ORIG_BRANCH_FILE) is not found!" && exit 1
28 test "${CURRENT_BRANCH}" != "$PATCH_BRANCH" && echo "ERROR: Current branch is not '$PATCH_BRANCH'." && exit 1
30 # Extract patch files from latest commit
31 git format-patch -N --output-directory ${PATCH_DIR} ${ORIG_BRANCH}
33 # Reset branch to original branch
38 echo "Creating your patch is done. Your patch is in ${PATCH_DIR}. Check your patch and add to git."