diff options
Diffstat (limited to 'jenkins-helpers.sh')
-rw-r--r-- | jenkins-helpers.sh | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/jenkins-helpers.sh b/jenkins-helpers.sh index b63fa150..5b87a29d 100644 --- a/jenkins-helpers.sh +++ b/jenkins-helpers.sh @@ -358,6 +358,7 @@ clone_or_update_repo_no_checkout () local dir="$1" local url="$2" local reference="$3" + local single_branch="$4" local refopt="" case "$reference" in @@ -378,7 +379,13 @@ clone_or_update_repo_no_checkout () if ! [ -d "$dir/.git" ]; then rm -rf "$dir" - run_with_timeout_and_retry 1h 3 git clone $refopt "$url" "$dir" + + local single_branch_opt="" + if [ x"$single_branch" != x"" ]; then + single_branch_opt="--single-branch --branch $single_branch" + fi + + run_with_timeout_and_retry 1h 3 git clone $refopt $single_branch_opt "$url" "$dir" else # Clean up the clone (this is supposed to re-share objects from # reference clone and keep the size of the clone minimal). @@ -398,8 +405,13 @@ clone_or_update_repo_no_checkout () # Update from URL. git remote add origin "$url" > /dev/null 2>&1 || true git remote set-url origin "$url" - run_with_timeout_and_retry 1h 3 git remote update -p - run_with_timeout_and_retry 1h 3 git fetch -q origin "refs/changes/*:refs/changes/*" + local refspec="+refs/changes/*:refs/changes/*" + if [ x"$single_branch" = x"" ]; then + run_with_timeout_and_retry 1h 3 git remote update -p + else + refspec="+refs/heads/$single_branch:refs/remotes/origin/$single_branch" + fi + run_with_timeout_and_retry 1h 3 git fetch -q origin $refspec --prune ) ) } @@ -418,25 +430,23 @@ clone_or_update_repo () local ref="$2" local url="$3" local reference="auto" + local single_branch="" if [ $# -ge 4 ]; then + if [ $# -ge 5 ]; then + single_branch="$5" + fi reference="$4" fi - clone_or_update_repo_no_checkout "$dir" "$url" "$reference" + clone_or_update_repo_no_checkout "$dir" "$url" "$reference" "$single_branch" - ( - cd "$dir" - - # Convert git branch/tag names into SHA1 - local sha1 - sha1=$(git_rev_parse "." "$ref") - - # Checkout - git reset --hard - git clean -dfx - git checkout --detach "$sha1" - ) + git_clean "$dir" + # Convert git branch/tag names into SHA1 + local sha1 + sha1=$(git_rev_parse "$dir" "$ref") + # Checkout + git -C "$dir" checkout --detach "$sha1" ) } |