Skip to content

Commit 987ed0c

Browse files
committed
Avoid using tee to capture stderr, add support for upcoming git version
1 parent 28ee57c commit 987ed0c

File tree

1 file changed

+28
-26
lines changed

1 file changed

+28
-26
lines changed

bin/incremental-git-filterbranch

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -640,9 +640,9 @@ processBranch () {
640640
processBranch_tagNameFilter='read -r tag; printf "filter-branch/converted-tags/%s" "${tag}"'
641641
fi
642642
rm -rf "${WORKER_REPOSITORY_DIR}.map"
643-
exec 3>&1
643+
set +o errexit
644644
# shellcheck disable=SC2086
645-
if processBranch_stdErr=$(git -C "${WORKER_REPOSITORY_DIR}" filter-branch \
645+
git -C "${WORKER_REPOSITORY_DIR}" filter-branch \
646646
${FILTER} \
647647
--remap-to-ancestor \
648648
--tag-name-filter "${processBranch_tagNameFilter}" \
@@ -651,38 +651,40 @@ processBranch () {
651651
--state-branch "refs/filter-branch/state" \
652652
--force \
653653
-- "${processBranch_range}" \
654-
1>&3 2>&1 | tee /dev/stderr
655-
)
654+
2>"${WORKER_REPOSITORY_DIR}.stderr"
655+
processBranch_rc=$?
656+
set -o errexit
657+
if test -s "${WORKER_REPOSITORY_DIR}.stderr"
656658
then
657-
processBranch_rc=0
658-
else
659-
processBranch_rc=1
659+
cat "${WORKER_REPOSITORY_DIR}.stderr" >&2
660+
if test ${processBranch_rc} -eq 1
661+
then
662+
if test -n "$(cat "${WORKER_REPOSITORY_DIR}.stderr" | grep -E '^Found nothing to rewrite$')"
663+
then
664+
processBranch_rc=2
665+
fi
666+
fi
667+
fi
668+
if test ${processBranch_rc} -ne 0 -a ${processBranch_rc} -ne 2
669+
then
670+
die 'git failed'
660671
fi
661-
exec 3>&-
662-
if test "${processBranch_rc}" -ne 0
672+
if test "${TAGS_PLAN}" = 'all' -a -n "${processBranch_tags}"
663673
then
664-
if test -n "${processBranch_stdErr##*Found nothing to rewrite*}"
674+
if ! processBranchTag_availableTags="$(git -C "${WORKER_REPOSITORY_DIR}" tag --list | grep -E '^filter-branch/converted-tags/' | sed -E 's:^filter-branch/converted-tags/::')"
665675
then
666-
die 'git failed'
676+
processBranchTag_availableTags=''
667677
fi
668-
else
669-
if test "${TAGS_PLAN}" = 'all' -a -n "${processBranch_tags}"
670-
then
671-
if ! processBranchTag_availableTags="$(git -C "${WORKER_REPOSITORY_DIR}" tag --list | grep -E '^filter-branch/converted-tags/' | sed -E 's:^filter-branch/converted-tags/::')"
678+
for processBranch_tag in ${processBranch_tags}
679+
do
680+
if ! itemInList "${processBranch_tag}" "${processBranchTag_availableTags}"
672681
then
673-
processBranchTag_availableTags=''
674-
fi
675-
for processBranch_tag in ${processBranch_tags}
676-
do
677-
if ! itemInList "${processBranch_tag}" "${processBranchTag_availableTags}"
682+
if stringPassesLists "${processBranch_tag}" "${TAG_WHITELIST}" "${TAG_BLACKLIST}"
678683
then
679-
if stringPassesLists "${processBranch_tag}" "${TAG_WHITELIST}" "${TAG_BLACKLIST}"
680-
then
681-
processNotConvertedTag "${processBranch_tag}"
682-
fi
684+
processNotConvertedTag "${processBranch_tag}"
683685
fi
684-
done
685-
fi
686+
fi
687+
done
686688
fi
687689
echo " - storing state"
688690
git -C "${WORKER_REPOSITORY_DIR}" branch -f "filter-branch/filtered/${1}" FETCH_HEAD

0 commit comments

Comments
 (0)