forked from OpenXT/openxt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
do_branch.sh
executable file
·64 lines (52 loc) · 1.47 KB
/
do_branch.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#! /bin/bash
set -e
REPO="/home/xc_source/git/xenclient"
BRANCH="master"
NEW_BRANCH=""
usage()
{
echo "$0: [-N] [-b BRANCH] [-r REPO] -n NEW_BRANCH"
}
unset NOACTION
while [ "$#" -ne 0 ]; do
case "$1" in
-b) BRANCH="$2"; shift 2 ;;
-n) NEW_BRANCH="$2"; shift 2;;
-r) REPO="$2"; shift 2;;
-N) NOACTION=-n; shift;;
--) shift ; break ;;
*) usage ; exit 1;;
esac
done
if [ "x$REPO" == "x" -o "x$BRANCH" == "x" -o "x$NEW_BRANCH" == "x" ]
then
usage
exit 1
fi
log() { "$@" ; }
for i in "$REPO"/*.git
do
dir="`basename "${i%.git}"`"
branch="$BRANCH"
if [ ! -d "$dir" ]; then
rm -rf "$dir.tmp"
log git clone -n "$i" "$dir.tmp"
mv "$dir.tmp" "$dir"
fi
branches=$(cd $dir && git branch -a)
if [ "x${branches}" == "x" ]; then
echo "NOTE: no branches in $dir"
continue
fi
(
cd $dir
if ! git show-ref $branch ; then
headbranch="`cat .git/HEAD | cut -d'/' -f3`"
echo "Branch $branch doesn't exist, use ${headbranch} for $dir"
branch=${headbranch}
fi
git checkout ${branch}
git branch ${NEW_BRANCH} ${branch}
sudo git push ${NOACTION} origin ${NEW_BRANCH}
)
done