Revert "Export"
[framework/web/web-ui-fw.git] / libs / patch / create-patch.sh
1 #!/bin/bash
2
3 cd `dirname $0`/../../
4 CWD=`pwd`
5 LIB_DIR=${CWD}/libs
6 PATCH_DIR=$LIB_DIR/patch
7
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`"
12
13 function reset_branch
14 {
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
20         exit $ret
21 }
22
23 # Make sure if current branch is PATCH_BRANCH
24 test ! -f "$ORIG_BRANCH_FILE" && echo "ERROR: Original branch file ($ORIG_BRANCH_FILE) is not found!" && exit 1
25 test "${CURRENT_BRANCH}" != "$PATCH_BRANCH" && echo "ERROR: Current branch is not '$PATCH_BRANCH'." && exit 1
26
27 # Extract patch files from latest commit
28 git format-patch -N --output-directory ${PATCH_DIR} ${ORIG_BRANCH}
29
30 # Reset branch to original branch
31 reset_branch 0
32
33 # Done. Notice howto
34 echo ""
35 echo "Creating your patch is done. Your patch is in ${PATCH_DIR}. Check your patch and add to git."