tizen beta release
[platform/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 # If --cancel option is given, just reset git and exit.
24 test "$1" == "--cancel" && reset_branch 0
25
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
29
30 # Extract patch files from latest commit
31 git format-patch -N --output-directory ${PATCH_DIR} ${ORIG_BRANCH}
32
33 # Reset branch to original branch
34 reset_branch 0
35
36 # Done. Notice howto
37 echo ""
38 echo "Creating your patch is done. Your patch is in ${PATCH_DIR}. Check your patch and add to git."