| ... | ... |
@@ -236,6 +236,30 @@ GetOSVersion() {
|
| 236 | 236 |
export os_VENDOR os_RELEASE os_UPDATE os_PACKAGE os_CODENAME |
| 237 | 237 |
} |
| 238 | 238 |
|
| 239 |
+# git update using reference as a branch. |
|
| 240 |
+function git_update_branch() {
|
|
| 241 |
+ |
|
| 242 |
+ GIT_BRANCH=$1 |
|
| 243 |
+ |
|
| 244 |
+ git checkout -f origin/$GIT_BRANCH |
|
| 245 |
+ # a local branch might not exist |
|
| 246 |
+ git branch -D $GIT_BRANCH || true |
|
| 247 |
+ git checkout -b $GIT_BRANCH |
|
| 248 |
+} |
|
| 249 |
+ |
|
| 250 |
+ |
|
| 251 |
+# git update using reference as a tag. Be careful editing source at that repo |
|
| 252 |
+# as working copy will be in a detached mode |
|
| 253 |
+function git_update_tag() {
|
|
| 254 |
+ |
|
| 255 |
+ GIT_TAG=$1 |
|
| 256 |
+ |
|
| 257 |
+ git tag -d $GIT_TAG |
|
| 258 |
+ # fetching given tag only |
|
| 259 |
+ git fetch origin tag $GIT_TAG |
|
| 260 |
+ git checkout -f $GIT_TAG |
|
| 261 |
+} |
|
| 262 |
+ |
|
| 239 | 263 |
|
| 240 | 264 |
# Translate the OS version values into common nomenclature |
| 241 | 265 |
# Sets ``DISTRO`` from the ``os_*`` values |
| ... | ... |
@@ -267,16 +291,16 @@ function git_clone {
|
| 267 | 267 |
|
| 268 | 268 |
GIT_REMOTE=$1 |
| 269 | 269 |
GIT_DEST=$2 |
| 270 |
- GIT_BRANCH=$3 |
|
| 270 |
+ GIT_REF=$3 |
|
| 271 | 271 |
|
| 272 |
- if echo $GIT_BRANCH | egrep -q "^refs"; then |
|
| 272 |
+ if echo $GIT_REF | egrep -q "^refs"; then |
|
| 273 | 273 |
# If our branch name is a gerrit style refs/changes/... |
| 274 | 274 |
if [[ ! -d $GIT_DEST ]]; then |
| 275 | 275 |
[[ "$ERROR_ON_CLONE" = "True" ]] && exit 1 |
| 276 | 276 |
git clone $GIT_REMOTE $GIT_DEST |
| 277 | 277 |
fi |
| 278 | 278 |
cd $GIT_DEST |
| 279 |
- git fetch $GIT_REMOTE $GIT_BRANCH && git checkout FETCH_HEAD |
|
| 279 |
+ git fetch $GIT_REMOTE $GIT_REF && git checkout FETCH_HEAD |
|
| 280 | 280 |
else |
| 281 | 281 |
# do a full clone only if the directory doesn't exist |
| 282 | 282 |
if [[ ! -d $GIT_DEST ]]; then |
| ... | ... |
@@ -284,7 +308,7 @@ function git_clone {
|
| 284 | 284 |
git clone $GIT_REMOTE $GIT_DEST |
| 285 | 285 |
cd $GIT_DEST |
| 286 | 286 |
# This checkout syntax works for both branches and tags |
| 287 |
- git checkout $GIT_BRANCH |
|
| 287 |
+ git checkout $GIT_REF |
|
| 288 | 288 |
elif [[ "$RECLONE" == "yes" ]]; then |
| 289 | 289 |
# if it does exist then simulate what clone does if asked to RECLONE |
| 290 | 290 |
cd $GIT_DEST |
| ... | ... |
@@ -295,10 +319,17 @@ function git_clone {
|
| 295 | 295 |
# (due to the py files having older timestamps than our pyc, so python |
| 296 | 296 |
# thinks the pyc files are correct using them) |
| 297 | 297 |
find $GIT_DEST -name '*.pyc' -delete |
| 298 |
- git checkout -f origin/$GIT_BRANCH |
|
| 299 |
- # a local branch might not exist |
|
| 300 |
- git branch -D $GIT_BRANCH || true |
|
| 301 |
- git checkout -b $GIT_BRANCH |
|
| 298 |
+ |
|
| 299 |
+ # handle GIT_REF accordingly to type (tag, branch) |
|
| 300 |
+ if [[ -n "`git show-ref refs/tags/$GIT_REF`" ]]; then |
|
| 301 |
+ git_update_tag $GIT_REF |
|
| 302 |
+ elif [[ -n "`git show-ref refs/heads/$GIT_REF`" ]]; then |
|
| 303 |
+ git_update_branch $GIT_REF |
|
| 304 |
+ else |
|
| 305 |
+ echo $GIT_REF is neither branch nor tag |
|
| 306 |
+ exit 1 |
|
| 307 |
+ fi |
|
| 308 |
+ |
|
| 302 | 309 |
fi |
| 303 | 310 |
fi |
| 304 | 311 |
} |