-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Fix git get_default_branch remote #2394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
seefood
merged 6 commits into
Bash-it:master
from
shinenelson:fix/get-default-branch-remote
Aug 9, 2026
+96
−3
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cac3f18
Fix get_default_branch to detect any remote
claude b6d35c4
Add tests for get_default_branch function
claude ed7076b
Add SPDX license headers to test file
shinenelson 05da1c4
Fix SC2295: quote variable expansion in parameter expansion
claude b269dbb
Add aliases test directory to test discovery
claude f07fcc9
replace master references to trunk
shinenelson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| # SPDX-FileCopyrightText: 2026 Shine Nelson <bash-it@shinenelson.com> | ||
| # SPDX-License-Identifier: MIT | ||
|
|
||
| # shellcheck shell=bats | ||
|
|
||
| load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" | ||
|
|
||
| function local_setup_file() { | ||
| setup_libs "" | ||
| } | ||
|
|
||
| function local_setup() { | ||
| TEST_REPO="${BATS_FILE_TMPDIR}/test-repo-${BATS_TEST_NUMBER}" | ||
| mkdir -p "${TEST_REPO}" | ||
| cd "${TEST_REPO}" || false | ||
| git init . 2>&1 | grep -v "Reinitialized" || true | ||
|
|
||
| source "${BASH_IT?}/aliases/available/git.aliases.bash" | ||
| } | ||
|
|
||
| @test "get_default_branch: returns main when origin points to main" { | ||
| # Set up a local remote-like structure | ||
| git remote add origin "https://github.com/test/repo.git" | ||
| git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/main | ||
|
|
||
| run get_default_branch | ||
| assert_success | ||
| assert_output "main" | ||
| } | ||
|
|
||
| @test "get_default_branch: returns trunk when origin points to trunk" { | ||
| git remote add origin "https://github.com/test/repo.git" | ||
| git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/trunk | ||
|
|
||
| run get_default_branch | ||
| assert_success | ||
| assert_output "trunk" | ||
| } | ||
|
|
||
| @test "get_default_branch: falls back to first remote when origin doesn't exist" { | ||
| git remote add upstream "https://github.com/upstream/repo.git" | ||
| git symbolic-ref refs/remotes/upstream/HEAD refs/remotes/upstream/main | ||
|
|
||
| run get_default_branch | ||
| assert_success | ||
| assert_output "main" | ||
| } | ||
|
|
||
| @test "get_default_branch: returns empty when no remotes exist" { | ||
| run get_default_branch | ||
| assert_success | ||
| assert_output "" | ||
| } | ||
|
|
||
| @test "get_default_branch: returns empty when remote has no HEAD ref" { | ||
| git remote add origin "https://github.com/test/repo.git" | ||
| # Don't set a HEAD ref, so the git symbolic-ref command will fail | ||
|
|
||
| run get_default_branch | ||
| assert_success | ||
| assert_output "" | ||
| } | ||
|
|
||
| @test "get_default_branch: properly strips remote prefix from branch name" { | ||
| git remote add origin "https://github.com/test/repo.git" | ||
| git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/trunk | ||
|
|
||
| run get_default_branch | ||
| assert_success | ||
| assert_output "trunk" | ||
| } | ||
|
|
||
| @test "get_default_branch: uses origin when both origin and another remote exist" { | ||
| git remote add upstream "https://github.com/upstream/repo.git" | ||
| git remote add origin "https://github.com/test/repo.git" | ||
| git symbolic-ref refs/remotes/upstream/HEAD refs/remotes/upstream/main | ||
| git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/trunk | ||
|
|
||
| run get_default_branch | ||
| assert_success | ||
| assert_output "trunk" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.