Revert "Export"
[framework/web/web-ui-fw.git] / libs / patch / prepare-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 CURRENT_BRANCH_FILE=${CWD}/.current_branch.txt
11
12 function reset_branch
13 {
14         echo "Reset git to original git branch..."
15         test -f "$CURRENT_BRANCH_FILE" && CURRENT_BRANCH="`cat $CURRENT_BRANCH_FILE`"
16         git checkout ${CURRENT_BRANCH}
17         test -e ".git/rebase-apply" && git am --abort
18         git branch -D ${PATCH_BRANCH}
19         rm -f $CURRENT_BRANCH_FILE
20         exit 1
21 }
22
23 # If --cancel option is given, just reset git and exit.
24 test "$1" == "--cancel" && reset_branch
25
26 # If current branch file is already exist, reset and exit.
27 test -f "$CURRENT_BRANCH_FILE" && reset_branch
28
29 # Remember current branch name to a file
30 echo "${CURRENT_BRANCH}" > $CURRENT_BRANCH_FILE
31
32 # Make sure if current git is clear.
33 #test -n "`git status -s`" && echo "ERROR: Current git is not clean. Type 'git status' and clean your git up first." && exit 1
34
35 # Reset git 
36 #git reset --hard HEAD
37
38 # Create a temporary branch
39 git branch ${PATCH_BRANCH}       || reset_branch
40 git checkout ${PATCH_BRANCH} || reset_branch
41
42 # Apply existing patches into libs/
43 cd ${LIB_DIR}
44 #for patch in `find ${PATCH_DIR} -name '*.patch' -type f`; do
45 #       patch -p0 < ${patch} || reset_branch
46 #done
47 git am $PATCH_DIR/*.patch
48
49 # Make a temporary commit on $PATCH_BRANCH
50 #git add -f -u .        || reset_branch
51 #git commit -m 'Temporary commit applying existing patches'     || reset_branch
52
53
54 # Done. Notice howto
55 echo ""
56 echo "Set up for patch is done. Current temporary git branch name is '${PATCH_BRANCH}', and a temporary commit is created. (This commit and branch will be removed.)"
57 echo "Go change your source, add&commit into git, and run create-patch.sh to make your commit to a patch file in $PATCH_DIR."
58