From 42af60c166cd1e0a02f687f39e7da1fbf519820a Mon Sep 17 00:00:00 2001 From: Yu-Ping Wu Date: Tue, 8 Aug 2023 17:54:05 +0800 Subject: [PATCH] util/scripts/update_submodules: Fix branch name greping The command "git branch -a | grep -q ${branch}" may not exit with 0 when pipefail is set. "grep -q" exits immediately with exit code 0 as soon as a match is found. However, at that point "git branch -a" may be still writing to the pipe, leading to SIGPIPE. When pipefail is set, PIPESTATUS 141 will be returned. Fix the problem by not using "grep -q". Also fix the branch name in the generated commit subject. Change-Id: Ic07efb5e2a4f3b7bbc6e76da9e026771bc685bdb Signed-off-by: Yu-Ping Wu Reviewed-on: https://review.coreboot.org/c/coreboot/+/77085 Reviewed-by: Yidi Lin Tested-by: build bot (Jenkins) --- util/scripts/update_submodules | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/util/scripts/update_submodules b/util/scripts/update_submodules index 4ca2925ff7..9f6c14f5b0 100755 --- a/util/scripts/update_submodules +++ b/util/scripts/update_submodules @@ -108,13 +108,13 @@ main() { git fetch 2>/dev/null fi - if git branch -a | grep -q "origin/main"; then - branch_name="origin/main" - elif git branch -a | grep -q "origin/master"; then - branch_name="origin/master" - elif git branch -a | grep -q "origin/trunk"; then - branch_name="origin/trunk" - fi + declare -a branches=("origin/main" "origin/master" "origin/trunk") + for branch in "${branches[@]}"; do + if git branch -a | grep "${branch}" > /dev/null; then + branch_name="${branch}" + break + fi + done updated_commit_id="$(git log --pretty='%h' -n 1 "${branch_name}" -- )" updated_commit_description="$(git log --pretty='%ci - (%s)' -n 1 "${updated_commit_id}")" @@ -138,7 +138,7 @@ main() { cd "${TOP}" || exit 1 git add "${submodule}" > /dev/null 2>&1 || exit 1 git commit -s -F- > /dev/null 2>&1 <<-EOF - Update ${submodule##*/} submodule to upstream master + Update ${submodule##*/} submodule to upstream ${branch##*/} Updating from commit id ${initial_commit_id}: $initial_commit_description