summaryrefslogtreecommitdiff
path: root/jenkins-helpers.sh
diff options
context:
space:
mode:
Diffstat (limited to 'jenkins-helpers.sh')
-rw-r--r--jenkins-helpers.sh25
1 files changed, 19 insertions, 6 deletions
diff --git a/jenkins-helpers.sh b/jenkins-helpers.sh
index 3e5ad7cd..c6e23431 100644
--- a/jenkins-helpers.sh
+++ b/jenkins-helpers.sh
@@ -1289,6 +1289,9 @@ breakup_changed_components ()
# fetches of ${paths[@]}" from appropriate revisions.
# Once one of the paths is found in a given revision, we check it out and
# move on to the next revision.
+# Optional "--relative" option supplied as $3 will make get_git_history()
+# output path names relative to the output directory. This is useful when
+# output directory needs to be moved before processing.
get_git_history ()
{
(
@@ -1298,6 +1301,12 @@ get_git_history ()
local repo="$2"
shift 2
+ local relative=false
+ if [ "$1" = "--relative" ]; then
+ relative=true
+ shift 1
+ fi
+
local -a paths=()
while [ $# != 0 ]; do
if [ "$1" = "--" ]; then
@@ -1348,14 +1357,13 @@ get_git_history ()
echo "$tmp_root"
while read rev; do
- local tmp_dir found path
- tmp_dir="$tmp_root/$rev"
- mkdir "$tmp_dir"
+ local found path
+ mkdir "$tmp_root/$rev"
found=false
for path in "${paths[@]}"; do
"${git_archive[@]}" "$rev" -- "$path" "${extra_paths[@]}" \
- | tar -x -C "$tmp_dir" &
+ | tar -x -C "$tmp_root/$rev" &
# "git archive" fails when $path was deleted in $rev.
if wait $!; then
found=true
@@ -1364,13 +1372,18 @@ get_git_history ()
done
if $found; then
- echo "$tmp_dir/$path"
+ if $relative; then
+ echo "$rev/$path"
+ else
+ echo "$tmp_root/$rev/$path"
+ fi
n_revs=$(($n_revs-1))
if [ $n_revs = 0 ]; then
break
fi
else
- rm -r "$tmp_dir"
+ # shellcheck disable=SC2115
+ rm -r "$tmp_root/$rev"
fi
done < <("${git_rev_list[@]}")
)