forked from peter-m-shi/ztool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgitz-super.sh
38 lines (33 loc) · 814 Bytes
/
gitz-super.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/sh
now_pwd=`pwd`
while [[ ! -d ".git" ]]
do
cd ..
if [[ `pwd` = '/' ]]
then
echo 'Not a git repository (or in children of the root directory): .git'
cd ${now_pwd}
exit
fi
done
head=`cat .git/HEAD`
user=`git config --get user.name`
branch=${head##*/}
prefix=`echo $branch | cut -d - -f1`
if [[ $user = $prefix ]]
then
superBranch=${branch%%+*}
superBranch=${superBranch#*-}
else
echo "Sync operation is forbidden. "
echo "Make sure the target branch is your $user's own branch."
fi
if [ -f ".git/refs/heads/${superBranch}" ]; then
git checkout ${superBranch}
else
if [ -f ".git/refs/remotes/origin/${superBranch}" ]; then
git checkout -t origin/${superBranch}
else
echo "Super branch ${superBranch} not existed."
fi
fi