From f106333de34ba858e9f9a0ba09b22a9a73486a96 Mon Sep 17 00:00:00 2001 From: Edwin Kofler Date: Mon, 2 Jun 2025 05:50:13 -0700 Subject: [PATCH 1/3] Add heuristic for finding default remote name --- lib/helpers.bash | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index 3dc988c1f1..6b9d3b5296 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -234,7 +234,7 @@ function _bash-it-update-() { fi if [[ -z "$BASH_IT_REMOTE" ]]; then - BASH_IT_REMOTE="origin" + BASH_IT_REMOTE=$(_remote_name) fi git fetch "$BASH_IT_REMOTE" --tags &> /dev/null @@ -352,7 +352,7 @@ function _bash-it-version() { pushd "${BASH_IT?}" > /dev/null || return if [[ -z "${BASH_IT_REMOTE:-}" ]]; then - BASH_IT_REMOTE="origin" + BASH_IT_REMOTE=$(_remote_name) fi BASH_IT_GIT_REMOTE="$(git remote get-url "$BASH_IT_REMOTE")" @@ -1233,6 +1233,24 @@ function pathmunge() { fi } +function _remote_name() { + local branch + branch=$(git branch --show-current) + + local remote_name= + remote_name=$(git config --get --default '' "branch.$branch.remote") + if [[ -n "$remote_name" ]]; then + printf '%s\n' "$remote_name" + return + fi + + if remote_name=$(git remote -v | awk 'NR==1 { name=$1; print name } $1 != name { exit 1 }'); then + printf '%s\n' "$remote_name" + else + printf '%s\n' 'origin' + fi +} + # `_bash-it-find-in-ancestor` uses the shell's ability to run a function in # a subshell to simplify our search to a simple `cd ..` and `[[ -r $1 ]]` # without any external dependencies. Let the shell do what it's good at. From c0c5e0573f9bfc51a9c32afde68ec674c76edc99 Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Sat, 4 Oct 2025 22:45:29 +0300 Subject: [PATCH 2/3] Fix remote name detection function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Addresses review feedback on PR #2318: - Rename function to _get-git-default-remote-name (dash naming convention) - Scope function to operate on BASH_IT directory, not CWD - Add command prefix to git commands for safety Original implementation by Edwin Kofler (@hyperupcall) Co-Authored-By: Edwin Kofler 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- lib/helpers.bash | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index 6b9d3b5296..17782ce29f 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -234,7 +234,7 @@ function _bash-it-update-() { fi if [[ -z "$BASH_IT_REMOTE" ]]; then - BASH_IT_REMOTE=$(_remote_name) + BASH_IT_REMOTE=$(_get-git-default-remote-name) fi git fetch "$BASH_IT_REMOTE" --tags &> /dev/null @@ -352,7 +352,7 @@ function _bash-it-version() { pushd "${BASH_IT?}" > /dev/null || return if [[ -z "${BASH_IT_REMOTE:-}" ]]; then - BASH_IT_REMOTE=$(_remote_name) + BASH_IT_REMOTE=$(_get-git-default-remote-name) fi BASH_IT_GIT_REMOTE="$(git remote get-url "$BASH_IT_REMOTE")" @@ -1233,22 +1233,27 @@ function pathmunge() { fi } -function _remote_name() { +function _get-git-default-remote-name() { + pushd "${BASH_IT?}" > /dev/null || return + local branch - branch=$(git branch --show-current) + branch=$(command git branch --show-current) local remote_name= - remote_name=$(git config --get --default '' "branch.$branch.remote") + remote_name=$(command git config --get --default '' "branch.$branch.remote") if [[ -n "$remote_name" ]]; then printf '%s\n' "$remote_name" + popd > /dev/null || return return fi - if remote_name=$(git remote -v | awk 'NR==1 { name=$1; print name } $1 != name { exit 1 }'); then + if remote_name=$(command git remote -v | awk 'NR==1 { name=$1; print name } $1 != name { exit 1 }'); then printf '%s\n' "$remote_name" else printf '%s\n' 'origin' fi + + popd > /dev/null || return } # `_bash-it-find-in-ancestor` uses the shell's ability to run a function in From 12dcac3c38809636ff6c50590056d3256aa07a57 Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Tue, 7 Oct 2025 12:40:52 +0300 Subject: [PATCH 3/3] Apply review feedback: use git --git-dir and simplify awk MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Addresses @akinomyoga's review feedback on PR #2344: 1. **Replace pushd/popd with git --git-dir/--work-tree** - More direct approach without changing shell directory - Avoids side effects from directory changes - Cleaner code without need for popd cleanup 2. **Simplify awk command** - Changed from: `awk 'NR==1 { name=$1; print name } $1 != name { exit 1 }'` - Changed to: `awk 'NR==1 { print $1 }'` - Use bash parameter expansion `${remote_name:-origin}` for fallback - Simpler, more readable, same behavior **Testing:** - ✅ Function correctly returns 'fork' for current repo - ✅ Function correctly returns 'me' for test repo with non-standard remote - ✅ Shellcheck passes with no warnings Co-authored-by: akinomyoga 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- lib/helpers.bash | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index 17782ce29f..a6ff1fcd34 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -1234,26 +1234,18 @@ function pathmunge() { } function _get-git-default-remote-name() { - pushd "${BASH_IT?}" > /dev/null || return - local branch - branch=$(command git branch --show-current) + branch=$(command git --git-dir="${BASH_IT?}/.git" --work-tree="${BASH_IT?}" branch --show-current) local remote_name= - remote_name=$(command git config --get --default '' "branch.$branch.remote") + remote_name=$(command git --git-dir="${BASH_IT?}/.git" --work-tree="${BASH_IT?}" config --get --default '' "branch.$branch.remote") if [[ -n "$remote_name" ]]; then printf '%s\n' "$remote_name" - popd > /dev/null || return return fi - if remote_name=$(command git remote -v | awk 'NR==1 { name=$1; print name } $1 != name { exit 1 }'); then - printf '%s\n' "$remote_name" - else - printf '%s\n' 'origin' - fi - - popd > /dev/null || return + remote_name=$(command git --git-dir="${BASH_IT?}/.git" --work-tree="${BASH_IT?}" remote -v | awk 'NR==1 { print $1 }') + printf '%s\n' "${remote_name:-origin}" } # `_bash-it-find-in-ancestor` uses the shell's ability to run a function in