-
Notifications
You must be signed in to change notification settings - Fork 26
/
git-cms-remote
executable file
·121 lines (112 loc) · 3.05 KB
/
git-cms-remote
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#! /bin/bash
function usage() {
cat <<@EOF
usage: git cms-remote add [--ssh|--https] [-w|--enable-push] USER
Description:
Adds a remote repository called USER pointing to https://github.com/USER/cmssw.git .
By default only fetching from this remote is enabled, using the HTTPS protocol.
The default behaviour is to immediately fetch the new remote repository; this can be
disabled with the '--no-fetch' option.
Pushing can be enabled with the '-w' or '--enable-push' option; the default is
to use the SSH protocol.
If '--ssh' is given, the SSH protocol will be used for all URLs.
If '--https' is given, the HTTPS protocol will be used for all URLS.
Options:
-h|--help display this usage message
--https use the HTTPS protocol for fetching and pushing
--ssh use the SSH protocol for fetching and pushing
--fetch automatically fetch the new remote (default)
--no-fetch do not automatically fetch the new remote
-w|--enable-push enable pushing to the new remote
@EOF
exit $1
}
# get default protocol from git config, or use "mixed" by default
PROTOCOL=$(git config --get cms.protocol || echo mixed)
if [ "$PROTOCOL" != "https" ] && [ "$PROTOCOL" != "ssh" ] && [ "$PROTOCOL" != "mixed" ]; then
$ECHO "Unsupported value $PROTOCOL in cms.protocol (choose https, ssh, mixed)"
exit 1
fi
READONLY=true
FETCH=true
COMMAND=
TARGET=
while [ "$#" != 0 ]; do
case "$1" in
-h | --help )
usage 0
;;
--https )
INITOPTIONS="$INITOPTIONS $1"
PROTOCOL=https
shift
;;
--ssh )
INITOPTIONS="$INITOPTIONS $1"
PROTOCOL=ssh
shift
;;
--fetch )
FETCH=true
shift
;;
--no-fetch )
FETCH=false
shift
;;
-w | --enable-push )
READONLY=false
shift
;;
-*)
echo Unknown option $1
usage 1
;;
*)
if [ "$COMMAND" == "" ]; then
COMMAND=$1
elif [ "$TARGET" == "" ]; then
TARGET=$1
else
echo Unexpected argument $1
usage 1
fi
shift
;;
esac
done
# initialize the local repository
if [ -z "$CMSSW_BASE" ]; then
echo "CMSSW environment not setup, please run 'cmsenv' before 'git cms-remote'."
exit 1
fi
if ! [ -d $CMSSW_BASE/src/.git ]; then
git cms-init --upstream-only $INITOPTIONS
fi
cd $CMSSW_BASE/src
case "$COMMAND" in
add )
if [ "$TARGET" == "" ]; then
usage 1
fi
if [ "$PROTOCOL" == "ssh" ]; then
git remote add $TARGET [email protected]:$TARGET/cmssw.git
else
git remote add $TARGET https://github.com/$TARGET/cmssw.git
fi
if [ "$READONLY" == "true" ]; then
git remote set-url --push $TARGET disabled
elif [ "$PROTOCOL" == "https" ]; then
git remote set-url --push $TARGET https://github.com/$TARGET/cmssw.git
else
git remote set-url --push $TARGET [email protected]:$TARGET/cmssw.git
fi
if [ "$FETCH" == "true" ]; then
git fetch $TARGET
fi
;;
* )
echo Unknown subcommand: $COMMAND
usage 1
;;
esac