Skip to content

Commit 632e68c

Browse files
authored
Merge pull request #2344 from seefood/feature/fix-remote-name-detection
2 parents 6661156 + 12dcac3 commit 632e68c

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

lib/helpers.bash

Lines changed: 17 additions & 2 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="origin"
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="origin"
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,6 +1233,21 @@ function pathmunge() {
12331233
fi
12341234
}
12351235

1236+
function _get-git-default-remote-name() {
1237+
local branch
1238+
branch=$(command git --git-dir="${BASH_IT?}/.git" --work-tree="${BASH_IT?}" branch --show-current)
1239+
1240+
local remote_name=
1241+
remote_name=$(command git --git-dir="${BASH_IT?}/.git" --work-tree="${BASH_IT?}" config --get --default '' "branch.$branch.remote")
1242+
if [[ -n "$remote_name" ]]; then
1243+
printf '%s\n' "$remote_name"
1244+
return
1245+
fi
1246+
1247+
remote_name=$(command git --git-dir="${BASH_IT?}/.git" --work-tree="${BASH_IT?}" remote -v | awk 'NR==1 { print $1 }')
1248+
printf '%s\n' "${remote_name:-origin}"
1249+
}
1250+
12361251
# `_bash-it-find-in-ancestor` uses the shell's ability to run a function in
12371252
# a subshell to simplify our search to a simple `cd ..` and `[[ -r $1 ]]`
12381253
# without any external dependencies. Let the shell do what it's good at.

0 commit comments

Comments
 (0)