Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions git-clone-related
Original file line number Diff line number Diff line change
Expand Up @@ -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: $0 UPSTREAM_ORG REPO_NAME [DESTINATION] [GIT_CLONE_ARGS...]" >&2
exit 1
fi

Expand Down Expand Up @@ -155,7 +155,7 @@ else
REPO_BRANCH=$("${SCRIPT_DIR}"/git-find-branch "${REPO_URL}" "${CI_BRANCH_NAME}" ${FALLBACK_BRANCH:+"$FALLBACK_BRANCH"})
fi
echo "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.
# Try twice in case of network lossage. 60 seconds is not enough to clone 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" \
&& rm -rf "${DESTINATION}" \
Expand All @@ -166,4 +166,5 @@ else
exit 2
}; }; }
fi
echo "git-clone-related: ${DESTINATION} is at $(cd "${DESTINATION}" && git rev-parse HEAD)"

echo "$0: ${DESTINATION} is at $(cd "${DESTINATION}" && git rev-parse HEAD)"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

Using $0 may produce inconsistent output paths.

$0 will display the actual invocation path (e.g., ./git-clone-related, ../git-scripts/git-clone-related, or an absolute path) rather than the consistent git-clone-related: prefix. This could make log parsing or grepping for this script's output less predictable.

If consistent output is preferred, consider using basename "$0":

-echo "$0: ${DESTINATION} is at $(cd "${DESTINATION}" && git rev-parse HEAD)"
+echo "$(basename "$0"): ${DESTINATION} is at $(cd "${DESTINATION}" && git rev-parse HEAD)"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
echo "$0: ${DESTINATION} is at $(cd "${DESTINATION}" && git rev-parse HEAD)"
echo "$(basename "$0"): ${DESTINATION} is at $(cd "${DESTINATION}" && git rev-parse HEAD)"
🤖 Prompt for AI Agents
In @git-clone-related at line 170, The echo line uses $0 which can vary by
invocation; change it to a stable script name by using basename "$0" (or a
hardcoded string) in the echo so the output consistently begins with
"git-clone-related:"; update the line that currently echoes "$0: ${DESTINATION}
is at $(cd \"${DESTINATION}\" && git rev-parse HEAD)" to use basename "$0" (or
the literal script name) while keeping the DESTINATION and git rev-parse
subshell intact.

22 changes: 12 additions & 10 deletions tests/git-clone-related-test/test-git-clone-related.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ set -o errexit -o nounset
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"
resultdir=$(mktemp -d 2> /dev/null || mktemp -d -t 'resultdir')
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
Expand All @@ -35,21 +35,23 @@ unset BUILD_SOURCEBRANCH
unset TRAVIS
unset CIRCLE_COMPARE_URL
unset GITHUB_HEAD_REF

# 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)
(cd "$startdir" && "${PLUME_SCRIPTS}"/git-clone-related $ARGS "$resultdir")

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 "$goaldir" rev-parse --abbrev-ref HEAD)
clonedbranch=$(git -C "$resultdir" rev-parse --abbrev-ref HEAD)

rm -rf "$startdir" "$goaldir"
rm -rf "$startdir" "$resultdir"

if [ "$clonedrepo" != "$GOAL_REPO" ]; then
echo "test-git-clone-related.sh \"$1\" \"$2\" \"$3\" \"$4\" \"$5\""
echo "expected repo $GOAL_REPO, got: $clonedrepo"
echo "error: test-git-clone-related.sh \"$1\" \"$2\" \"$3\" \"$4\" \"$5\""
echo "error: expected repo $GOAL_REPO, got: $clonedrepo"
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 "error: test-git-clone-related.sh \"$1\" \"$2\" \"$3\" \"$4\" \"$5\""
echo "error: expected branch $GOAL_BRANCH, got: $clonedbranch"
exit 2
fi