-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Add heuristic for finding default remote name #2318
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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")" | ||
|
@@ -951,6 +951,24 @@ function pathmunge() { | |
fi | ||
} | ||
|
||
function _remote_name() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure how much the contribution guideline is strictly applied to the project, but Coding Style -
|
||
local branch | ||
branch=$(git branch --show-current) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't this get the information about the git repository of the current working directory? Shouldn't this get the information in the Bash-it repository? |
||
|
||
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. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked over the repo, looks like there is already code covering remote name detection in themes/githelpers.theme.bash
Maybe it's not a bad idea for code reuse, to move this function library to the general libraries and have those functions available globally and not just for a small number of themes that bother to source it.
Any thoughts, @akinomyoga ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(either way, if we keep this, maybe name it a bit more descrive, like
_get_git_default_remote()
)Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the target repositories are different. The functions
_bash-it-{update-,version}
modified in this PR are intended to retrieve the remote in the repository of Bash-It itself, whilegithelpers.theme.sh
is supposed to retrieve information in the repository of the current working directory.edit: I think it would be valid to prepare a function to get the remote name in the current git tree and use it everywhere. For the present purpose, the function can be used as
$(cd "$BASH_IT"; _bash-it-git-get-remote-host)
. However, the feature to determine the remote name doesn't seem to exist ingithelpers.theme.sh
. I think unless the same feature is required by both themes and thebash-it
command, we don't necessarily have to define the function in a single place.