@@ -5,6 +5,9 @@ shopt -s dotglob
55# make sure we can GTFO
66trap ' echo >&2 Ctrl+C captured, exiting; exit 1' SIGINT
77
8+ # if bashbrew is missing, bail early with a sane error
9+ bashbrew --version > /dev/null
10+
811usage () {
912 cat << -EOUSAGE
1013 usage: $0 [PR number] [repo[:tag]]
5760pull=" $1 " # PR number
5861shift
5962
60- # dir="$(dirname "$(readlink -f "$BASH_SOURCE")")"
63+ diffDir=" $( readlink -f " $BASH_SOURCE " ) "
64+ diffDir=" $( dirname " $diffDir " ) "
6165
6266tempDir=" $( mktemp -d) "
6367trap " rm -rf '$tempDir '" EXIT
@@ -67,12 +71,19 @@ git clone --quiet \
6771 https://github.com/docker-library/official-images.git \
6872 oi
6973
70- git -C oi fetch --quiet \
71- origin " pull/$pull /merge" :pull
74+ if [ " $pull " != ' 0' ]; then
75+ git -C oi fetch --quiet \
76+ origin " pull/$pull /merge" :refs/heads/pull
77+ else
78+ git -C oi fetch --quiet --update-shallow \
79+ " $diffDir " HEAD:refs/heads/pull
80+ fi
7281
73- images=( " $@ " )
74- if [ " ${# images[@]} " -eq 0 ]; then
75- images=( $( git -C oi/library diff --name-only HEAD...pull -- . | xargs -n1 basename) )
82+ if [ " $# " -eq 0 ]; then
83+ images=" $( git -C oi/library diff --name-only HEAD...pull -- .) "
84+ [ -n " $images " ] || exit 0
85+ images=" $( xargs -n1 basename <<< " $images" ) "
86+ set -- $images
7687fi
7788
7889export BASHBREW_CACHE=" ${BASHBREW_CACHE:- ${XDG_CACHE_HOME:- $HOME / .cache} / bashbrew} "
@@ -146,7 +157,8 @@ copy-tar() {
146157
147158 local d dockerfiles=()
148159 for d in " $src " /* /.bashbrew-dockerfile-name; do
149- local bf=" $( < " $d " ) " dDir=" $( dirname " $d " ) "
160+ local bf; bf=" $( < " $d " ) "
161+ local dDir; dDir=" $( dirname " $d " ) "
150162 dockerfiles+=( " $dDir /$bf " )
151163 if [ " $bf " = ' Dockerfile' ]; then
152164 # if "Dockerfile.builder" exists, let's check that too (busybox, hello-world)
@@ -205,7 +217,8 @@ copy-tar() {
205217 # "find: warning: -path ./xxx/ will not match anything because it ends with /."
206218 local findGlobbedPath=" ${f%/ } "
207219 findGlobbedPath=" ${findGlobbedPath# ./ } "
208- globbed=( $( cd " $dDir " && find -path " ./$findGlobbedPath " ) )
220+ local globbedStr; globbedStr=" $( cd " $dDir " && find -path " ./$findGlobbedPath " ) "
221+ local -a globbed=( $globbedStr )
209222 if [ " ${# globbed[@]} " -eq 0 ]; then
210223 globbed=( " $f " )
211224 fi
@@ -243,9 +256,9 @@ git -C temp init --quiet
243256git -C temp config user.name ' Bogus'
244257git -C temp config user.email ' bogus@bogus'
245258
246- bashbrew list " ${images[@]} " | sort -uV > temp/_bashbrew-list || :
247- bashbrew cat --format " $archesListTemplate " " ${images[@]} " | sort -V > temp/_bashbrew-arches || :
248- bashbrew cat --format " $sharedTagsListTemplate " " ${images[@]} " | grep -vE ' ^$' | sort -V > temp/_bashbrew-shared-tags || :
259+ bashbrew list " ${images[@]} " 2>> temp/_bashbrew.err | sort -uV > temp/_bashbrew-list || :
260+ bashbrew cat --format " $archesListTemplate " " ${images[@]} " 2>> temp/_bashbrew.err | sort -V > temp/_bashbrew-arches || :
261+ bashbrew cat --format " $sharedTagsListTemplate " " ${images[@]} " 2>> temp/_bashbrew.err | grep -vE ' ^$' | sort -V > temp/_bashbrew-shared-tags || :
249262for image in " ${images[@]} " ; do
250263 if script=" $( bashbrew cat -f " $template " " $image " ) " ; then
251264 mkdir tar
@@ -260,9 +273,9 @@ git -C temp commit --quiet --allow-empty -m 'initial' || :
260273git -C oi checkout --quiet pull
261274
262275git -C temp rm --quiet -rf . || :
263- bashbrew list " ${images[@]} " | sort -uV > temp/_bashbrew-list || :
264- bashbrew cat --format " $archesListTemplate " " ${images[@]} " | sort -V > temp/_bashbrew-arches || :
265- bashbrew cat --format " $sharedTagsListTemplate " " ${images[@]} " | grep -vE ' ^$' | sort -V > temp/_bashbrew-shared-tags || :
276+ bashbrew list " ${images[@]} " 2>> temp/_bashbrew.err | sort -uV > temp/_bashbrew-list || :
277+ bashbrew cat --format " $archesListTemplate " " ${images[@]} " 2>> temp/_bashbrew.err | sort -V > temp/_bashbrew-arches || :
278+ bashbrew cat --format " $sharedTagsListTemplate " " ${images[@]} " 2>> temp/_bashbrew.err | grep -vE ' ^$' | sort -V > temp/_bashbrew-shared-tags || :
266279script=" $( bashbrew cat -f " $template " " ${images[@]} " ) "
267280mkdir tar
268281( eval " $script " | tar -xiC tar )
0 commit comments