Skip to content

Commit 3880853

Browse files
authored
Merge pull request #3415 from joolswills/gitPullOrClone_improvements
gitPullOrClone improvements
2 parents 405f7e7 + cde7334 commit 3880853

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

scriptmodules/helpers.sh

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -402,9 +402,11 @@ function gitPullOrClone() {
402402
fi
403403
[[ -z "$repo" ]] && return 1
404404
[[ -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
408410
depth=0
409411
fi
410412

@@ -416,14 +418,24 @@ function gitPullOrClone() {
416418

417419
if [[ -d "$dir/.git" ]]; then
418420
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
419428
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
422434
popd > /dev/null
423435
else
424436
local git="git clone --recursive"
425437
if [[ "$depth" -gt 0 ]]; then
426-
git+=" --depth $depth"
438+
git+=" --depth $depth --shallow-submodules"
427439
fi
428440
git+=" --branch $branch"
429441
printMsgs "console" "$git \"$repo\" \"$dir\""

0 commit comments

Comments
 (0)