From b1dc62c388ed2fd87c0193118c13d201892727fb Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Sun, 5 Oct 2025 19:26:06 +0300 Subject: [PATCH] Auto-detect git remote name instead of assuming 'origin' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds automatic detection of git remote name when BASH_IT_REMOTE is not set, fixing issues for users with non-standard remote names like 'me', 'upstream', 'fork', etc. **Problem:** Commands like `bash-it version`, `bash-it update`, and `bash-it doctor` hard-coded the remote name as "origin", causing failures when users have different remote naming conventions: ``` $ bash-it version error: No such remote 'origin' ``` **Solution:** Created `_bash-it-get-remote-name()` helper function that: 1. Returns BASH_IT_REMOTE if already set (preserves user override) 2. Auto-detects first available remote via `git remote | head -n 1` 3. Falls back to "origin" if no remotes found Updated three functions to use auto-detection: - `_bash-it-update-()` (lib/helpers.bash:254) - `_bash-it-version()` (lib/helpers.bash:370) - `_bash-it-doctor-summary()` (lib/helpers.bash:564) **Benefits:** - No configuration required for single-remote repos - Works with any remote name (me, fork, upstream, etc.) - Backward compatible: BASH_IT_REMOTE override still works - Fallback to "origin" maintains existing behavior for edge cases **Testing:** - Verified with non-standard remote name 'me' - Tested BASH_IT_REMOTE environment variable preservation - Shellcheck passes with no warnings Fixes #2317 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- lib/helpers.bash | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index 3dc988c1f1..7f89490914 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -42,6 +42,24 @@ function _make_reload_alias() { echo "source '${BASH_IT?}/scripts/reloader.bash' '${1?}' '${2?}'" } +# Auto-detect git remote name for bash-it repository +# Returns the first remote found, or "origin" as fallback +function _bash-it-get-remote-name() { + local remote_name + + # If BASH_IT_REMOTE is already set, use it + if [[ -n "${BASH_IT_REMOTE:-}" ]]; then + echo "${BASH_IT_REMOTE}" + return 0 + fi + + # Try to get the first remote from git + remote_name="$(git remote 2> /dev/null | head -n 1)" + + # Fallback to "origin" if no remotes found + echo "${remote_name:-origin}" +} + # Alias for reloading aliases # shellcheck disable=SC2139 alias reload_aliases="$(_make_reload_alias alias aliases)" @@ -233,9 +251,7 @@ function _bash-it-update-() { return 1 fi - if [[ -z "$BASH_IT_REMOTE" ]]; then - BASH_IT_REMOTE="origin" - fi + BASH_IT_REMOTE="$(_bash-it-get-remote-name)" git fetch "$BASH_IT_REMOTE" --tags &> /dev/null @@ -351,9 +367,7 @@ function _bash-it-version() { pushd "${BASH_IT?}" > /dev/null || return - if [[ -z "${BASH_IT_REMOTE:-}" ]]; then - BASH_IT_REMOTE="origin" - fi + BASH_IT_REMOTE="$(_bash-it-get-remote-name)" BASH_IT_GIT_REMOTE="$(git remote get-url "$BASH_IT_REMOTE")" BASH_IT_GIT_URL="${BASH_IT_GIT_REMOTE%.git}" @@ -547,9 +561,7 @@ function _bash-it-doctor-summary() { current_commit="$(git rev-parse --short HEAD 2> /dev/null || echo 'unknown')" current_tag="$(git describe --exact-match --tags 2> /dev/null || echo 'none')" - if [[ -z "${BASH_IT_REMOTE:-}" ]]; then - BASH_IT_REMOTE="origin" - fi + BASH_IT_REMOTE="$(_bash-it-get-remote-name)" # Get version info relative to tags latest_tag="$(git describe --tags --abbrev=0 2> /dev/null || echo 'none')"