forked from cms-sw/cms-git-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-cms-addpkg
executable file
·180 lines (163 loc) · 5.35 KB
/
git-cms-addpkg
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/bin/bash -e
# Mimics addpkg behavior in git.
case `uname` in
Darwin) ECHO=echo ;;
*) ECHO="echo -e" ;;
esac
usage () {
echo "git cms-addpkg [options] SubSystem/Package"
echo "git cms-addpkg [options] -f FILE"
echo
echo "Options:"
$ECHO "-h \tthis help message"
$ECHO
$ECHO "-d, --debug \tenable debug output"
$ECHO "-f, --file FILE \tread the list of packages to be checkoed out from FILE"
$ECHO " --https \tuse https, rather than ssh to access your personal repository"
$ECHO " --ssh \tuse ssh, rather than https to access the official repository"
$ECHO "-q, --quiet, -z \tdo not print out progress"
$ECHO "-y, --yes \tassume yes to all questions"
exit $1
}
VERBOSE=1
INITOPTIONS="" # options passed to git cms-init
VERBOSE_STREAM=/dev/stderr
DEBUG_STREAM=/dev/null
RED='\033[31m'
NORMAL='\033[0m'
verbose () {
if [ "X$VERBOSE" = X1 ]; then
echo "$@"
fi
}
PKG_NAME=
INPUT_FILE=
while [ "$#" != 0 ]; do
case "$1" in
-h | --help )
usage 0;;
-d | --debug )
INITOPTIONS="$INITOPTIONS $1"
shift; set -x; DEBUG_STREAM=/dev/stderr ;;
-f | --file )
OPTION=$1; shift
INPUT_FILE="$1"; shift
if [ ! "$INPUT_FILE" ]; then
$ECHO "git cms-addpkg: option $OPTION requires an argument"
$ECHO
usage 1
elif [ ! -r "$INPUT_FILE" ]; then
$ECHO "git cms-addpkg: file $INPUT_FILE does not exist or is not readable"
$ECHO
usage 1
fi
unset OPTION
;;
-q | --quiet | -z )
INITOPTIONS="$INITOPTIONS $1"
shift; set +x; VERBOSE=0; VERBOSE_STREAM=/dev/null ;;
-y | --yes )
INITOPTIONS="$INITOPTIONS $1"
shift;;
--https )
INITOPTIONS="$INITOPTIONS $1"
shift;;
--ssh )
INITOPTIONS="$INITOPTIONS $1"
shift;;
-*)
echo Unknown option $1 ; usage 1 ;;
*)
if [ "$INPUT_FILE" == "" ]; then
# check out a single package
if [ "X$PKG_NAME" = X ]; then
PKG_NAME=$1
shift
else
echo "git cms-addpkg: you can specify only one package at the time."
exit 1
fi
else
# check out a list of packages via -f / --file FILE
echo "git cms-addpkg: you cannot specify a package and input from file at the same time."
exit 1
fi
;;
esac
done
if [ "$PKG_NAME" == "" ] && [ "$INPUT_FILE" == "" ] ; then
echo "You need to specify at least one package or input file." ; exit 1
fi
if [ "$INPUT_FILE" ]; then
# check the syntax of the input file
INVALID=`cat "$INPUT_FILE" | sed -e's|\s*#.*||' | grep -v '^\s*$' | grep -v -E '^/*\w+(/\w+)?/*$' || true`
if [ -n "$INVALID" ]; then
$ECHO "Some lines of $INPUT_FILE are not in a valid format:"
$ECHO "$RED$INVALID$NORMAL"
exit 1
fi
unset INVALID
fi
# initialize the local repository
if [ -z "$CMSSW_BASE" ]; then
echo "CMSSW environment not setup, please run 'cmsenv' before 'git cms-addpkg'."
exit 1
fi
if ! [ -d $CMSSW_BASE/src/.git ]; then
git cms-init $INITOPTIONS
fi
cd $CMSSW_BASE/src
case `git --version` in
git\ version\ 1.7*)
# git 1.7.x does not support a leading slash in .gitignore and .git/info/sparse-checkout
LEADING_SLASH=
;;
*)
LEADING_SLASH=/
;;
esac
# check if using a reference repository
if [ "$CMSSW_GIT_REFERENCE" == "" ] && [ -f $CMSSW_BASE/src/.git/objects/info/alternates ]; then
CMSSW_GIT_REFERENCE=`cat .git/objects/info/alternates | head -n1`
fi
# if using a personal reference repository, update it from the official one
if [ -e $CMSSW_GIT_REFERENCE/create-`whoami` ]; then
(cd $CMSSW_GIT_REFERENCE ; git remote update origin 2>$VERBOSE_STREAM >$VERBOSE_STREAM)
fi
if [ "$(git status --porcelain --untracked=no | grep '^[ACDMRU]')" ]; then
$ECHO "${RED}Error:${NORMAL} there are staged but not committed changes on your working tree, please commit or stash them."
exit 1
fi
if [ "$INPUT_FILE" ]; then
verbose "Checking out packages"
verbose "`cat "$INPUT_FILE"`"
# add the requested package(s) to the sparse checkout
cp -f $CMSSW_BASE/src/.git/info/sparse-checkout $CMSSW_BASE/src/.git/info/sparse-checkout-new
cat "$INPUT_FILE" | sed -e's|\s*#.*||' | grep -v '^\s*$' | sed -e "s|[/]*$|/|;s|^/*|${LEADING_SLASH}|" >> $CMSSW_BASE/src/.git/info/sparse-checkout-new
cat .git/info/sparse-checkout-new | sort -u > $CMSSW_BASE/src/.git/info/sparse-checkout
rm -f .git/info/sparse-checkout-new
else
verbose "Checking out package $PKG_NAME"
# add the requested package(s) to the sparse checkout
cp -f $CMSSW_BASE/src/.git/info/sparse-checkout $CMSSW_BASE/src/.git/info/sparse-checkout-new
echo "$PKG_NAME" | sed -e "s|[/]*$|/|;s|^/*|${LEADING_SLASH}|" >> $CMSSW_BASE/src/.git/info/sparse-checkout-new
cat .git/info/sparse-checkout-new | sort -u > $CMSSW_BASE/src/.git/info/sparse-checkout
rm -f .git/info/sparse-checkout-new
fi
git read-tree -mu HEAD
CURRENT_BRANCH=`git symbolic-ref --short HEAD`
if [ "$INPUT_FILE" ]; then
for PKG_NAME in `cat $INPUT_FILE`; do
if [ ! -d "$CMSSW_BASE/src/$PKG_NAME" ]; then
[ "$HEADER" ] || { $ECHO "\nThese packages do not exist in branch $CURRENT_BRANCH"; HEADER=done; }
echo $PKG_NAME
fi
done
[ "$HEADER" ] && exit 1
else
if [ ! -d "$CMSSW_BASE/src/$PKG_NAME" ]; then
echo "package $PKG_NAME does not exist in branch $CURRENT_BRANCH"
exit 1
fi
fi
exit 0