From 337761a602935c1ecdf05352805d24eff0188d4e Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Mon, 12 Jan 2026 07:48:56 -0800 Subject: [PATCH 1/6] Add diagnostics --- git-clone-related | 68 ++++++++++++------- git-find-branch | 2 +- .../test-git-clone-related.sh | 39 ++++++----- 3 files changed, 68 insertions(+), 41 deletions(-) diff --git a/git-clone-related b/git-clone-related index 7c06bbb..9556052 100755 --- a/git-clone-related +++ b/git-clone-related @@ -56,8 +56,10 @@ if [ "$1" = "--upstream-branch" ]; then shift fi +SCRIPTNAME="$(basename "$0")" + if [ "$#" -lt 2 ]; then - echo "Usage: $0 UPSTREAM_ORG REPO [DESTINATION] [GIT_CLONE_ARGS...]" >&2 + echo "Usage: ${SCRIPTNAME} UPSTREAM_ORG REPO [DESTINATION] [GIT_CLONE_ARGS...]" >&2 exit 1 fi @@ -89,10 +91,11 @@ if [ "$#" -eq 0 ]; then fi if [ -n "$DEBUG" ]; then - echo "Entering git-clone-related $UPSTREAM_ORG $REPO_NAME $DESTINATION $*" + echo "Entering ${SCRIPTNAME} $UPSTREAM_ORG $REPO_NAME $DESTINATION $*" + echo "${SCRIPTNAME}: PWD = ${PWD}" fi -echo "In directory $(pwd) :" +echo "In directory ${PWD} :" if [ -d "${DESTINATION}" ]; then echo "git-clone-related: destination ${DESTINATION} exists; pulling" # Use "cd" because older versions of git (eg, CircleCI) don't support the -C command-line option. @@ -106,55 +109,72 @@ elif [ -e "${DESTINATION}" ]; then else SCRIPT_DIR="$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd -P)" - CI_INFO="$SCRIPT_DIR/../plume-scripts/ci-info" - if [ ! -f "$CI_INFO" ]; then - CI_INFO="$SCRIPT_DIR/../.plume-scripts/ci-info" - fi - if [ ! -f "$CI_INFO" ]; then - CI_INFO="$SCRIPT_DIR/.plume-scripts/ci-info" - fi - if [ ! -f "$CI_INFO" ]; then + # Set PLUME_SCRIPTS. + for dir in "../plume-scripts" ".plume-scripts" "../.plume-scripts"; do + if [ -d "${SCRIPT_DIR}/${dir}" ]; then + PLUME_SCRIPTS="${SCRIPT_DIR}/${dir}" + fi + done + if [ -z "$PLUME_SCRIPTS" ]; then (cd "$SCRIPT_DIR" && git clone -q --depth 1 https://github.com/plume-lib/plume-scripts .plume-scripts) + PLUME_SCRIPTS="${SCRIPT_DIR}/.plume-scripts" fi + + CI_INFO="${PLUME_SCRIPTS}/ci-info" if [ ! -f "$CI_INFO" ]; then echo "CI_INFO does not exist: $CI_INFO" exit 1 fi if [ -n "$DEBUG" ]; then - echo "About to run ci-info --debug" + echo "${SCRIPTNAME}: About to run: ci-info --debug" "${CI_INFO}" --debug "${UPSTREAM_ORG}" - echo "Ran ci-info --debug" - echo "About to run ci-info" + echo "${SCRIPTNAME}: Done: ci-info --debug" + echo "${SCRIPTNAME}: About to run: ci-info" + fi + ci_info_output="$("${CI_INFO}" "${UPSTREAM_ORG}")" + if [ -n "$DEBUG" ]; then + echo "${SCRIPTNAME}: Done: ci-info" + echo "---- start of ci-info output ----" + # If `set -v` is on, the output will appear doubled, with the first copy preceded by "+ echo ". + echo "${ci_info_output}" + echo "---- end of ci-info output ----" + echo "${SCRIPTNAME}: About to eval ci-info output in ${PWD}" fi - eval "$("${CI_INFO}" "${UPSTREAM_ORG}")" + eval "${ci_info_output}" if [ -n "$DEBUG" ]; then - echo "Finished running ci-info" + echo "${SCRIPTNAME}: Done: eval ci-info output in ${PWD}" fi UPSTREAM_REPO_URL="https://github.com/${UPSTREAM_ORG}/${REPO_NAME}.git" if [ -n "$DEBUG" ]; then - echo "About to run git-find-fork" "${CI_ORGANIZATION}" "${UPSTREAM_ORG}" "${REPO_NAME}" + echo "${SCRIPTNAME}: About to run: git-find-fork" "${CI_ORGANIZATION}" "${UPSTREAM_ORG}" "${REPO_NAME}" fi # REPO_URL is what will be cloned. It might be the same as UPSTREAM_REPO_URL. REPO_URL=$("${SCRIPT_DIR}"/git-find-fork "${CI_ORGANIZATION}" "${UPSTREAM_ORG}" "${REPO_NAME}") if [ -n "$DEBUG" ]; then - echo "git-find-fork ${CI_ORGANIZATION} ${UPSTREAM_ORG} ${REPO_NAME} => ${REPO_URL}" + echo "${SCRIPTNAME}: Done: git-find-fork ${CI_ORGANIZATION} ${UPSTREAM_ORG} ${REPO_NAME} => ${REPO_URL}" fi if [ -n "$DEBUG" ]; then - echo "About to run git-find-branch" "${REPO_URL}" "${CI_BRANCH_NAME}" ${FALLBACK_BRANCH:+"$FALLBACK_BRANCH"} + echo "${SCRIPTNAME}: About to run: git-find-branch" "${REPO_URL}" "${CI_BRANCH_NAME}" ${FALLBACK_BRANCH:+"$FALLBACK_BRANCH"} fi REPO_BRANCH=$("${SCRIPT_DIR}"/git-find-branch "${REPO_URL}" "${CI_BRANCH_NAME}" ${FALLBACK_BRANCH:+"$FALLBACK_BRANCH"}) if [ -n "$DEBUG" ]; then - echo "git-find-branch ${REPO_URL} ${CI_BRANCH_NAME} => ${REPO_BRANCH}" + echo "${SCRIPTNAME}: Done: git-find-branch ${REPO_URL} ${CI_BRANCH_NAME} => ${REPO_BRANCH}" fi if [ "$UPSTREAM_REPO_URL" != "$REPO_URL" ] && [ "$REPO_BRANCH" != "$CI_BRANCH_NAME" ]; then - ## Don't use the fallback branch (e.g., master) of the downstream repo + ## Don't use the fallback branch (e.g., master) of the downstream repo. REPO_URL="$UPSTREAM_REPO_URL" + if [ -n "$DEBUG" ]; then + echo "${SCRIPTNAME}: About to run: git-find-branch" "${REPO_URL}" "${CI_BRANCH_NAME}" ${FALLBACK_BRANCH:+"$FALLBACK_BRANCH"} + fi REPO_BRANCH=$("${SCRIPT_DIR}"/git-find-branch "${REPO_URL}" "${CI_BRANCH_NAME}" ${FALLBACK_BRANCH:+"$FALLBACK_BRANCH"}) + if [ -n "$DEBUG" ]; then + echo "${SCRIPTNAME}: Done: git-find-branch" "${REPO_URL}" "${CI_BRANCH_NAME}" ${FALLBACK_BRANCH:+"$FALLBACK_BRANCH"} = > "${REPO_BRANCH}" + fi fi - echo "About to run: git clone -q -b ${REPO_BRANCH} $* ${REPO_URL} ${DESTINATION}" + echo "${SCRIPTNAME}: About to run: git clone -q -b ${REPO_BRANCH} $* ${REPO_URL} ${DESTINATION}" # Try twice in case of network lossage. 60 seconds is not enough for a branch of the JDK. timeout 180 git clone -q -b "${REPO_BRANCH}" "$@" "${REPO_URL}" "${DESTINATION}" \ || { echo "Retrying 'git clone ... ${REPO_URL} ${DESTINATION}' after timeout" \ @@ -162,8 +182,8 @@ else && sleep 180 \ && { timeout 180 git clone -q -b "${REPO_BRANCH}" "$@" "${REPO_URL}" "${DESTINATION}" \ || { - echo "git-clone-related: failed: git clone -q -b ${REPO_BRANCH}" "$@" "${REPO_URL} ${DESTINATION}" + echo "${SCRIPTNAME}: failed: git clone -q -b ${REPO_BRANCH}" "$@" "${REPO_URL} ${DESTINATION}" exit 2 }; }; } fi -echo "git-clone-related: ${DESTINATION} is at $(cd "${DESTINATION}" && git rev-parse HEAD)" +echo "${SCRIPTNAME}: ${DESTINATION} is at $(cd "${DESTINATION}" && git rev-parse HEAD)" diff --git a/git-find-branch b/git-find-branch index d9edcc3..286bddc 100755 --- a/git-find-branch +++ b/git-find-branch @@ -1,6 +1,6 @@ #!/bin/sh -# Usage: git-find-branch REPO_URL BRANCH ... +# Usage: git-find-branch REPO_URL BRANCH... # Prints either the first BRANCH that exists in REPO_URL, # or else prints the default branch name if none of the given branches exists. diff --git a/tests/git-clone-related-test/test-git-clone-related.sh b/tests/git-clone-related-test/test-git-clone-related.sh index a80558b..0088b6d 100755 --- a/tests/git-clone-related-test/test-git-clone-related.sh +++ b/tests/git-clone-related-test/test-git-clone-related.sh @@ -1,13 +1,13 @@ #!/bin/sh -# Test one invocation of git-clone-related +# Test one invocation of git-clone-related. -# arguments: +# Arguments: # 1: repo from which to run git-clone-related # 2: branch from which to run git-clone-related # 3: git-clone-related arguments -# 4: repo that should be cloned -# 5: branch that should be cloned +# 4: expected repo that should be cloned +# 5: expected branch that should be cloned START_REPO=$1 START_BRANCH=$2 @@ -17,15 +17,17 @@ GOAL_BRANCH=$5 set -o errexit -o nounset # set -o pipefail + # Display commands and their arguments as they are executed. # set -x -# set -v : Display shell input lines as they are read. +# Display shell input lines as they are read. +# set -v USER=${USER:-git-clone-related} -PLUME_SCRIPTS=$(cd ../../ && pwd -P) -startdir=$(mktemp -d 2> /dev/null || mktemp -d -t 'startdir') -goaldir=$(mktemp -d 2> /dev/null || mktemp -d -t 'goaldir') -rm -rf "$startdir" "$goaldir" +GIT_SCRIPTS=$(cd ../../ && pwd -P) +startdir=$(mktemp -d --tmpdir test-git-clone-related-startdir-XXXXXX 2> /dev/null || mktemp -d 2> /dev/null) +resultdir=$(mktemp -d --tmpdir test-git-clone-related-resultdir-XXXXXX 2> /dev/null || mktemp -d 2> /dev/null) +rm -rf "$startdir" "$resultdir" git clone --branch "$START_BRANCH" "$START_REPO" "$startdir" -q --single-branch --depth 1 # This test might itself be running under CI, so unset the variables that @@ -35,21 +37,26 @@ unset BUILD_SOURCEBRANCH unset TRAVIS unset CIRCLE_COMPARE_URL unset GITHUB_HEAD_REF + +echo "$0: About to run: (cd $startdir && ${GIT_SCRIPTS}/git-clone-related $ARGS $resultdir)" # shellcheck disable=SC2086 # $ARGS should not be quoted -(cd "$startdir" && "${PLUME_SCRIPTS}"/git-clone-related $ARGS "$goaldir") -clonedrepo=$(git -C "$goaldir" config --get remote.origin.url) -# git 2.22 and later has `git branch --show-current`; CircleCI doesn't have that version yet. -clonedbranch=$(git -C "$goaldir" rev-parse --abbrev-ref HEAD) +(cd "$startdir" && "${GIT_SCRIPTS}"/git-clone-related $ARGS "$resultdir") +echo "$0: Done: (cd $startdir && ${GIT_SCRIPTS}/git-clone-related $ARGS $resultdir)" -rm -rf "$startdir" "$goaldir" +clonedrepo=$(git -C "$resultdir" config --get remote.origin.url) +# git 2.22 and later has `git branch --show-current`; CircleCI doesn't have that version yet. +clonedbranch=$(git -C "$resultdir" rev-parse --abbrev-ref HEAD) if [ "$clonedrepo" != "$GOAL_REPO" ]; then echo "test-git-clone-related.sh \"$1\" \"$2\" \"$3\" \"$4\" \"$5\"" - echo "expected repo $GOAL_REPO, got: $clonedrepo" + echo "expected repo $GOAL_REPO, got $clonedrepo, in $resultdir" exit 2 fi if [ "$clonedbranch" != "$GOAL_BRANCH" ]; then echo "test-git-clone-related.sh \"$1\" \"$2\" \"$3\" \"$4\" \"$5\"" - echo "expected branch $GOAL_BRANCH, got: $clonedbranch" + echo "expected branch $GOAL_BRANCH, got $clonedbranch, in $resultdir" exit 2 fi + +# This comes after the failure exits, so we don't clean up if the test fails. +rm -rf "$startdir" "$resultdir" From 62b1080cf267a9eb96c3e1768f1a5e9c027ef1f0 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Mon, 12 Jan 2026 11:13:11 -0800 Subject: [PATCH 2/6] Don't show path to script --- git-clone-related | 2 +- git-find-fork | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/git-clone-related b/git-clone-related index 7c06bbb..680eff4 100755 --- a/git-clone-related +++ b/git-clone-related @@ -57,7 +57,7 @@ if [ "$1" = "--upstream-branch" ]; then fi if [ "$#" -lt 2 ]; then - echo "Usage: $0 UPSTREAM_ORG REPO [DESTINATION] [GIT_CLONE_ARGS...]" >&2 + echo "Usage: $(basename -- "$0") UPSTREAM_ORG REPO [DESTINATION] [GIT_CLONE_ARGS...]" >&2 exit 1 fi diff --git a/git-find-fork b/git-find-fork index e7f0cc5..09d5e3a 100755 --- a/git-find-fork +++ b/git-find-fork @@ -10,9 +10,9 @@ # Often, you can use the `git-clone-related` script instead of this one. if [ "$#" -ne 3 ]; then - script=$(basename -- "$0") - >&2 echo "Error: $script requires 3 arguments, got $#" - >&2 echo "Usage: $script ORG UPSTREAM_ORG REPONAME" + SCRIPT_NAME=$(basename -- "$0") + >&2 echo "Error: ${SCRIPT_NAME} requires 3 arguments, got $#" + >&2 echo "Usage: ${SCRIPT_NAME} ORG UPSTREAM_ORG REPONAME" exit 1 fi From 2f449e176a9a6d1024f24f8c31c7eea2108df591 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Mon, 12 Jan 2026 17:45:07 -0800 Subject: [PATCH 3/6] Use in more places --- git-clone-related | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/git-clone-related b/git-clone-related index ba8bb2e..8186c1b 100755 --- a/git-clone-related +++ b/git-clone-related @@ -56,8 +56,10 @@ if [ "$1" = "--upstream-branch" ]; then shift fi +SCRIPT_NAME=$(basename -- "$0") + if [ "$#" -lt 2 ]; then - echo "Usage: $(basename -- "$0") UPSTREAM_ORG REPO_NAME [DESTINATION] [GIT_CLONE_ARGS...]" >&2 + echo "Usage: ${SCRIPT_NAME} UPSTREAM_ORG REPO_NAME [DESTINATION] [GIT_CLONE_ARGS...]" >&2 exit 1 fi @@ -167,4 +169,4 @@ else }; }; } fi -echo "$0: ${DESTINATION} is at $(cd "${DESTINATION}" && git rev-parse HEAD)" +echo "${SCRIPT_NAME}: ${DESTINATION} is at $(cd "${DESTINATION}" && git rev-parse HEAD)" From 2d4cbed5d3587f66a4756885f73b2489d910bc9e Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Mon, 12 Jan 2026 18:08:11 -0800 Subject: [PATCH 4/6] script name --- git-clone-related | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/git-clone-related b/git-clone-related index 51ed889..8f580c8 100755 --- a/git-clone-related +++ b/git-clone-related @@ -56,6 +56,7 @@ if [ "$1" = "--upstream-branch" ]; then shift fi +SCRIPT_DIR="$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd -P)" SCRIPT_NAME=$(basename -- "$0") if [ "$#" -lt 2 ]; then @@ -76,12 +77,12 @@ if [ "$#" -ne 0 ] && ! beginswith "-" "$1"; then cd "$DESTINATION" pwd -P )" ]; then - echo "git-clone-related: destination is same as current directory" + echo "${SCRIPT_NAME}: destination is same as current directory" exit 1 fi else if [ "${REPO_NAME}" = "${PWD##*/}" ]; then - echo "git-clone-related: provide a destination argument" + echo "${SCRIPT_NAME}: provide a destination argument" exit 1 fi DESTINATION=../${REPO_NAME} @@ -92,23 +93,20 @@ fi if [ -n "$DEBUG" ]; then echo "Entering ${SCRIPT_NAME} $UPSTREAM_ORG $REPO_NAME $DESTINATION $*" - echo "${SCRIPT_NAME}: PWD = ${PWD}" fi echo "In directory ${PWD} :" if [ -d "${DESTINATION}" ]; then - echo "git-clone-related: destination ${DESTINATION} exists; pulling" + echo "${SCRIPT_NAME}: destination ${DESTINATION} exists; pulling" # Use "cd" because older versions of git (eg, CircleCI) don't support the -C command-line option. # In a Travis pull request, a repository can be in state "(HEAD detached at b475d58d)" # and "git pull" fails. (cd "${DESTINATION}" && (git pull -q || (git branch && true))) elif [ -e "${DESTINATION}" ]; then - echo "git-clone-related: destination ${DESTINATION} exists and is not a directory" + echo "${SCRIPT_NAME}: destination ${DESTINATION} exists and is not a directory" file "${DESTINATION}" exit 1 else - SCRIPT_DIR="$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd -P)" - # Set PLUME_SCRIPTS. for dir in "../plume-scripts" ".plume-scripts" "../.plume-scripts"; do if [ -d "${SCRIPT_DIR}/${dir}" ]; then From a029a9fa4d3da6479883bef86670eaf8643d81bb Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Mon, 12 Jan 2026 18:20:06 -0800 Subject: [PATCH 5/6] Improve formatting --- git-clone-related | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/git-clone-related b/git-clone-related index 8f580c8..8b00308 100755 --- a/git-clone-related +++ b/git-clone-related @@ -165,11 +165,11 @@ else ## Don't use the fallback branch (e.g., master) of the downstream repo. REPO_URL="$UPSTREAM_REPO_URL" if [ -n "$DEBUG" ]; then - echo "${SCRIPT_NAME}: About to run: git-find-branch" "${REPO_URL}" "${CI_BRANCH_NAME}" ${FALLBACK_BRANCH:+"$FALLBACK_BRANCH"} + echo "${SCRIPT_NAME}: About to run: git-find-branch \"${REPO_URL}\" \"${CI_BRANCH_NAME}\" ${FALLBACK_BRANCH:+"$FALLBACK_BRANCH"}" fi REPO_BRANCH=$("${SCRIPT_DIR}"/git-find-branch "${REPO_URL}" "${CI_BRANCH_NAME}" ${FALLBACK_BRANCH:+"$FALLBACK_BRANCH"}) if [ -n "$DEBUG" ]; then - echo "${SCRIPT_NAME}: Done: git-find-branch" "${REPO_URL}" "${CI_BRANCH_NAME}" ${FALLBACK_BRANCH:+"$FALLBACK_BRANCH"} = > "${REPO_BRANCH}" + echo "${SCRIPT_NAME}: Done: git-find-branch \"${REPO_URL}\" \"${CI_BRANCH_NAME}\" ${FALLBACK_BRANCH:+"$FALLBACK_BRANCH"} => ${REPO_BRANCH}" fi fi echo "${SCRIPT_NAME}: About to run: git clone -q -b ${REPO_BRANCH} $* ${REPO_URL} ${DESTINATION}" From e0a26cac58ea6e36dc2be716d485853ab2c346a9 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Mon, 12 Jan 2026 20:30:22 -0800 Subject: [PATCH 6/6] Add line break --- git-clone-related | 1 + 1 file changed, 1 insertion(+) diff --git a/git-clone-related b/git-clone-related index 8b00308..2b12450 100755 --- a/git-clone-related +++ b/git-clone-related @@ -130,6 +130,7 @@ else echo "${SCRIPT_NAME}: Done: ci-info --debug" echo "${SCRIPT_NAME}: About to run: ci-info" fi + ci_info_output="$("${CI_INFO}" "${UPSTREAM_ORG}")" if [ -n "$DEBUG" ]; then echo "${SCRIPT_NAME}: Done: ci-info"