Skip to content

Fix git get_default_branch remote - #2394

Open
shinenelson wants to merge 6 commits into
Bash-it:masterfrom
shinenelson:fix/get-default-branch-remote
Open

Fix git get_default_branch remote#2394
shinenelson wants to merge 6 commits into
Bash-it:masterfrom
shinenelson:fix/get-default-branch-remote

Conversation

@shinenelson

Copy link
Copy Markdown
Contributor

Description

This change-set improves the get_default_branch function in
git.aliases.bash to pick any configured remote if origin is
unavailable.

Motivation and Context

Previously, the get_default_branch function assumed 'origin' as the
remote and tried to get the symbolic-ref of that remote. For people
whose defaultRemoteName is custom and not 'origin', the function is
broken which in turn breaks all aliases calling the function.

Instead of assuming the default remote is always 'origin', the
function now:

  • Checks if origin exists and uses it as the default remote
  • Falls back to the first available remote if origin doesn't exist
  • Properly detects the default branch for the selected remote

How Has This Been Tested?

There were no tests that existed because this was a function within
aliases. New tests has been added for the function.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • If my change requires a change to the documentation, I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • If I have added a new file, I also added it to clean_files.txt and formatted it using lint_clean_files.sh.
  • I have added tests to cover my changes, and all the new and existing tests pass.

claude and others added 3 commits August 1, 2026 01:57
Instead of assuming the default remote is always 'origin', the function now:
- Checks if origin exists and uses it as the default remote
- Falls back to the first available remote if origin doesn't exist
- Properly detects the default branch for the selected remote
Tests verify that get_default_branch:
- Returns the correct branch when origin exists
- Falls back to the first available remote when origin doesn't exist
- Handles missing remotes gracefully
- Properly strips the remote prefix from the symbolic ref
- Prefers origin when multiple remotes are available
Annotate test/aliases/git.bats with proper SPDX copyright and license
information for legal compliance.
Comment thread aliases/available/git.aliases.bash Fixed
claude added 2 commits August 1, 2026 03:30
Quote the variable expansion inside the parameter expansion pattern
to satisfy shellcheck SC2295 requirements.
Include the aliases directory in the default test discovery so that
test/run without arguments includes alias tests.
@shinenelson

shinenelson commented Jul 31, 2026

Copy link
Copy Markdown
Contributor Author

I guess parallelism is doomed in the CI environment now.

When we fixed the GNU/Linux builds, now macOS has decided to fail which in-turn cancels the GNU/Linux job. 😕


Edit : It seems a re-run of the CI checks have fixed the issue. Maybe GitHub Actions did not like the slavery references.

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.

3 participants