From 987ed0c003ba53a475a240ff5168c4298c09fea0 Mon Sep 17 00:00:00 2001 From: Michele Locati Date: Wed, 21 Mar 2018 12:27:19 +0100 Subject: Avoid using tee to capture stderr, add support for upcoming git version --- bin/incremental-git-filterbranch | 54 +++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/bin/incremental-git-filterbranch b/bin/incremental-git-filterbranch index 3f59037..b27cea2 100755 --- a/bin/incremental-git-filterbranch +++ b/bin/incremental-git-filterbranch @@ -640,9 +640,9 @@ processBranch () { processBranch_tagNameFilter='read -r tag; printf "filter-branch/converted-tags/%s" "${tag}"' fi rm -rf "${WORKER_REPOSITORY_DIR}.map" - exec 3>&1 + set +o errexit # shellcheck disable=SC2086 - if processBranch_stdErr=$(git -C "${WORKER_REPOSITORY_DIR}" filter-branch \ + git -C "${WORKER_REPOSITORY_DIR}" filter-branch \ ${FILTER} \ --remap-to-ancestor \ --tag-name-filter "${processBranch_tagNameFilter}" \ @@ -651,38 +651,40 @@ processBranch () { --state-branch "refs/filter-branch/state" \ --force \ -- "${processBranch_range}" \ - 1>&3 2>&1 | tee /dev/stderr - ) + 2>"${WORKER_REPOSITORY_DIR}.stderr" + processBranch_rc=$? + set -o errexit + if test -s "${WORKER_REPOSITORY_DIR}.stderr" then - processBranch_rc=0 - else - processBranch_rc=1 + cat "${WORKER_REPOSITORY_DIR}.stderr" >&2 + if test ${processBranch_rc} -eq 1 + then + if test -n "$(cat "${WORKER_REPOSITORY_DIR}.stderr" | grep -E '^Found nothing to rewrite$')" + then + processBranch_rc=2 + fi + fi + fi + if test ${processBranch_rc} -ne 0 -a ${processBranch_rc} -ne 2 + then + die 'git failed' fi - exec 3>&- - if test "${processBranch_rc}" -ne 0 + if test "${TAGS_PLAN}" = 'all' -a -n "${processBranch_tags}" then - if test -n "${processBranch_stdErr##*Found nothing to rewrite*}" + if ! processBranchTag_availableTags="$(git -C "${WORKER_REPOSITORY_DIR}" tag --list | grep -E '^filter-branch/converted-tags/' | sed -E 's:^filter-branch/converted-tags/::')" then - die 'git failed' + processBranchTag_availableTags='' fi - else - if test "${TAGS_PLAN}" = 'all' -a -n "${processBranch_tags}" - then - if ! processBranchTag_availableTags="$(git -C "${WORKER_REPOSITORY_DIR}" tag --list | grep -E '^filter-branch/converted-tags/' | sed -E 's:^filter-branch/converted-tags/::')" + for processBranch_tag in ${processBranch_tags} + do + if ! itemInList "${processBranch_tag}" "${processBranchTag_availableTags}" then - processBranchTag_availableTags='' - fi - for processBranch_tag in ${processBranch_tags} - do - if ! itemInList "${processBranch_tag}" "${processBranchTag_availableTags}" + if stringPassesLists "${processBranch_tag}" "${TAG_WHITELIST}" "${TAG_BLACKLIST}" then - if stringPassesLists "${processBranch_tag}" "${TAG_WHITELIST}" "${TAG_BLACKLIST}" - then - processNotConvertedTag "${processBranch_tag}" - fi + processNotConvertedTag "${processBranch_tag}" fi - done - fi + fi + done fi echo " - storing state" git -C "${WORKER_REPOSITORY_DIR}" branch -f "filter-branch/filtered/${1}" FETCH_HEAD -- cgit v1.2.3