summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxim Kuvyrkov <maxim.kuvyrkov@linaro.org>2021-08-31 15:09:10 +0000
committerMaxim Kuvyrkov <maxim.kuvyrkov@linaro.org>2021-08-31 16:34:56 +0000
commit33488ecffa86c868935b7e3c46f6f9ff5fa459f8 (patch)
treec73f3f72b74a3907e502f32baf69c2e5c92d3eac
parent7626fe1c82396dea3a26220009f009218f2e56b6 (diff)
jenkins-helpers.sh: Save disk space by re-cloning repos
when a reference git repo is available. Change-Id: I64c011baa607b92059aebe39b268dcd08a8ad4d7
-rw-r--r--jenkins-helpers.sh13
1 files changed, 13 insertions, 0 deletions
diff --git a/jenkins-helpers.sh b/jenkins-helpers.sh
index 797e701a..771ef037 100644
--- a/jenkins-helpers.sh
+++ b/jenkins-helpers.sh
@@ -479,7 +479,20 @@ clone_or_update_repo_no_checkout ()
if ! git -C "$dir" status >/dev/null 2>&1; then
# Git repo doesn't exist or is corrupted. Make a new clone.
rm -rf "$dir"
+ fi
+
+ if [ -d "$dir" ] && [ x"$refopt" != x"" ] \
+ && [ "$(du -s "$dir/.git" | cut -f 1)" -gt $((1024*1024)) ]; then
+ # Current clone has grown above 1GB, and we have a reference repo,
+ # which should cut down the size significantly.
+ # Redo the clone to save disk space.
+ # PS: Unfortunately, I could not find a way to make the current clone
+ # use new objects from the reference repo without a full re-clone.
+ # Fortunately, a new clone with a reference repo is quick.
+ rm -rf "$dir"
+ fi
+ if ! [ -d "$dir" ]; then
local single_branch_opt=""
if [ x"$single_branch" != x"" ]; then
single_branch_opt="--single-branch --branch $single_branch"