Skip to content

Commit c0c5e05

Browse files
seefoodclaude
andcommitted
Fix remote name detection function
Addresses review feedback on PR Bash-it#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 <[email protected]> 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent f106333 commit c0c5e05

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

lib/helpers.bash

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ function _bash-it-update-() {
234234
fi
235235

236236
if [[ -z "$BASH_IT_REMOTE" ]]; then
237-
BASH_IT_REMOTE=$(_remote_name)
237+
BASH_IT_REMOTE=$(_get-git-default-remote-name)
238238
fi
239239

240240
git fetch "$BASH_IT_REMOTE" --tags &> /dev/null
@@ -352,7 +352,7 @@ function _bash-it-version() {
352352
pushd "${BASH_IT?}" > /dev/null || return
353353

354354
if [[ -z "${BASH_IT_REMOTE:-}" ]]; then
355-
BASH_IT_REMOTE=$(_remote_name)
355+
BASH_IT_REMOTE=$(_get-git-default-remote-name)
356356
fi
357357

358358
BASH_IT_GIT_REMOTE="$(git remote get-url "$BASH_IT_REMOTE")"
@@ -1233,22 +1233,27 @@ function pathmunge() {
12331233
fi
12341234
}
12351235

1236-
function _remote_name() {
1236+
function _get-git-default-remote-name() {
1237+
pushd "${BASH_IT?}" > /dev/null || return
1238+
12371239
local branch
1238-
branch=$(git branch --show-current)
1240+
branch=$(command git branch --show-current)
12391241

12401242
local remote_name=
1241-
remote_name=$(git config --get --default '' "branch.$branch.remote")
1243+
remote_name=$(command git config --get --default '' "branch.$branch.remote")
12421244
if [[ -n "$remote_name" ]]; then
12431245
printf '%s\n' "$remote_name"
1246+
popd > /dev/null || return
12441247
return
12451248
fi
12461249

1247-
if remote_name=$(git remote -v | awk 'NR==1 { name=$1; print name } $1 != name { exit 1 }'); then
1250+
if remote_name=$(command git remote -v | awk 'NR==1 { name=$1; print name } $1 != name { exit 1 }'); then
12481251
printf '%s\n' "$remote_name"
12491252
else
12501253
printf '%s\n' 'origin'
12511254
fi
1255+
1256+
popd > /dev/null || return
12521257
}
12531258

12541259
# `_bash-it-find-in-ancestor` uses the shell's ability to run a function in

0 commit comments

Comments
 (0)