Skip to content

Commit 1f56852

Browse files
committed
helpers / gitPullOrClone - fixup / improve persistent repos support
When env __persistent_repos is 1, we do full checkouts of repositories. This allows users with diskspace to spare to speed up source updates, by avoiding doing a shallow clone everytime. However, it was not working for cases where a module switched to a newer tag/branch as remote changes were not fetched first. This is now fixed. Also fixed errors thrown when calling gitPullOrClone on an existing repository when doing git pull, when HEAD is detached (for tags) or there is no tracking branch.
1 parent 8da6340 commit 1f56852

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

scriptmodules/helpers.sh

Lines changed: 17 additions & 5 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,9 +418,19 @@ 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"

0 commit comments

Comments
 (0)