Skip to content

Commit fa1dad9

Browse files
committed
Fix linkage check script to handle detached HEAD state
The beam-linkage-check.sh script previously used 'git rev-parse --abbrev-ref HEAD' to save the current position before switching branches. When in detached HEAD state (common when verifying PRs), this returns the string 'HEAD' instead of a valid ref, causing the cleanup function to fail to restore the original position. This change: - Uses 'git rev-parse HEAD' to get the full commit SHA instead of branch name - Adds '-c advice.detachedHead=false' to suppress warnings in cleanup - Adds explanatory comments Fixes #20558
1 parent d9c1e4e commit fa1dad9

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

sdks/java/build-tools/beam-linkage-check.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,12 @@ if [ ! -z "$(git diff)" ]; then
6969
exit 1
7070
fi
7171

72-
STARTING_REF=$(git rev-parse --abbrev-ref HEAD)
72+
# Use the full commit SHA instead of branch name to handle detached HEAD state.
73+
# This commonly happens when verifying someone else's PR, which involves
74+
# merging two non-branch references. See https://github.com/apache/beam/issues/20558
75+
STARTING_REF=$(git rev-parse HEAD)
7376
function cleanup() {
74-
git checkout $STARTING_REF
77+
git -c advice.detachedHead=false checkout $STARTING_REF
7578
}
7679
trap cleanup EXIT
7780

0 commit comments

Comments
 (0)