@@ -402,9 +402,11 @@ function gitPullOrClone() {
402
402
fi
403
403
[[ -z " $repo " ]] && return 1
404
404
[[ -z " $branch " ]] && branch=" master"
405
- if [[ -z " $depth " && " $__persistent_repos " -ne 1 && -z " $commit " ]]; then
406
- depth=1
407
- else
405
+
406
+ # if no depth is provided default to shallow clone (depth 1)
407
+ [[ -z " $depth " ]] && depth=1
408
+ # if we are using persistent repos or checking out a specific commit, don't shallow clone
409
+ if [[ " $__persistent_repos " -eq 1 || -n " $commit " ]]; then
408
410
depth=0
409
411
fi
410
412
@@ -416,14 +418,24 @@ function gitPullOrClone() {
416
418
417
419
if [[ -d " $dir /.git" ]]; then
418
420
pushd " $dir " > /dev/null
421
+ # if we are using persistent repos, fetch the latest remote changes and clean the source so
422
+ # any patches can be re-applied as needed.
423
+ if [[ " $__persistent_repos " -eq 1 ]]; then
424
+ runCmd git fetch
425
+ runCmd git reset --hard
426
+ runCmd git clean -f -d
427
+ fi
419
428
runCmd git checkout " $branch "
420
- runCmd git pull --ff-only
421
- runCmd git submodule update --init --recursive
429
+ # only try to pull if we are on a tracking branch
430
+ if [[ -n " $( git config --get branch.$branch .merge) " ]]; then
431
+ runCmd git pull --ff-only
432
+ runCmd git submodule update --init --recursive
433
+ fi
422
434
popd > /dev/null
423
435
else
424
436
local git=" git clone --recursive"
425
437
if [[ " $depth " -gt 0 ]]; then
426
- git+=" --depth $depth "
438
+ git+=" --depth $depth --shallow-submodules "
427
439
fi
428
440
git+=" --branch $branch "
429
441
printMsgs " console" " $git \" $repo \" \" $dir \" "
0 commit comments