Skip to content

Fix default branch detection#632

Open
rjriajul wants to merge 1 commit into
BtbN:masterfrom
rjriajul:master
Open

Fix default branch detection#632
rjriajul wants to merge 1 commit into
BtbN:masterfrom
rjriajul:master

Conversation

@rjriajul

@rjriajul rjriajul commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

This pull request updates the way the default branch name is detected in the util/update_scripts.sh script. The new approach uses a more direct and reliable git ls-remote --symref command instead of parsing the output of git remote show.

  • Improved detection of the default branch name by replacing the use of git remote show with git ls-remote --symref and related parsing, making the script more robust and less dependent on output formatting.

pzhlkj6612

This comment was marked as duplicate.

@pzhlkj6612 pzhlkj6612 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Plumbing commands are good for parsing!

Comment thread util/update_scripts.sh Outdated
if [[ -z "${CUR_BRANCH}" ]]; then
# Fetch default branch name
CUR_BRANCH="$(git remote show "${CUR_REPO}" | grep "HEAD branch:" | cut -d":" -f2 | xargs)"
CUR_BRANCH="$(git ls-remote --symref "${CUR_REPO}" HEAD | awk '/^ref:/ {print $2}' | sed 's|refs/heads/||')"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

A very tiny point:

elif [[ -n "${CUR_COMMIT}" ]]; then # GIT
if [[ -n "${CUR_TAGFILTER}" ]]; then
NEW_COMMIT="$(git -c 'versionsort.suffix=-' ls-remote --exit-code --tags --refs --sort "v:refname" "${CUR_REPO}" "refs/tags/${CUR_TAGFILTER}" | tail -n1 | cut -d/ -f3- | xargs)"
else
if [[ -z "${CUR_BRANCH}" ]]; then
# Fetch default branch name
CUR_BRANCH="$(git remote show "${CUR_REPO}" | grep "HEAD branch:" | cut -d":" -f2 | xargs)"
echo "Found default branch ${CUR_BRANCH}"
fi
NEW_COMMIT="$(git ls-remote --exit-code --heads --refs "${CUR_REPO}" refs/heads/"${CUR_BRANCH}" | cut -f1)"
fi

Maybe we can make all git ls-remote usage consistent by adding --exit-code?

Suggested change
CUR_BRANCH="$(git ls-remote --symref "${CUR_REPO}" HEAD | awk '/^ref:/ {print $2}' | sed 's|refs/heads/||')"
CUR_BRANCH="$(git ls-remote --exit-code --symref "${CUR_REPO}" HEAD | awk '/^ref:/ {print $2}' | sed 's|refs/heads/||')"

I know "HEAD" should always be there, though.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch on the --exit-code! I accidentally pushed the fix manually instead of using the UI button, but I just force-pushed again to make sure you were added as a co-author on the commit. Thanks for the review!

Co-authored-by: Mozi <29089388+pzhlkj6612@users.noreply.github.com>
@rjriajul

rjriajul commented Jul 4, 2026

Copy link
Copy Markdown
Contributor Author

Hey @BtbN, just checking in to see if you've had a chance to look at this PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants