Skip to content

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

hyperupcall
Copy link
Contributor

@hyperupcall hyperupcall commented Jun 2, 2025

Description, Motivation and Context

Fixes #2317

Implementation:

  • If HEAD is not detached, it infers the remote name by the current branch
  • If HEAD is detached, then it infers the remote name by parsing git remote -v, but only if every entry has the same remote name

I've made similar PRs in other projects, so this does work in general.

How Has This Been Tested?

Manual testing

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • If my change requires a change to the documentation, I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • If I have added a new file, I also added it to clean_files.txt and formatted it using lint_clean_files.sh.
  • I have added tests to cover my changes, and all the new and existing tests pass.

@seefood seefood self-assigned this Jun 3, 2025
Copy link
Contributor

@seefood seefood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems legit...

@@ -951,6 +951,24 @@ function pathmunge() {
fi
}

function _remote_name() {
Copy link
Contributor

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 ?

Copy link
Contributor

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() )

Copy link
Contributor

@akinomyoga akinomyoga Jun 9, 2025

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, while githelpers.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 in githelpers.theme.sh. I think unless the same feature is required by both themes and the bash-it command, we don't necessarily have to define the function in a single place.

@@ -951,6 +951,24 @@ function pathmunge() {
fi
}

function _remote_name() {
local branch
branch=$(git branch --show-current)
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -951,6 +951,24 @@ function pathmunge() {
fi
}

function _remote_name() {
Copy link
Contributor

Choose a reason for hiding this comment

The 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 - docs/contributing.rst says

  • When creating new functions, please use a dash ("-") to separate the words of the function's name, e.g. my-new-function. Don't use underscores, e.g. my_new_function.
  • Internal functions that aren't to be used by the end user should start with an underscore, e.g. _my-new-internal-function.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, also maybe call it _get-git-default-remote-name is a bit more descriptive, and add a remark to doc the function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] Fails to auto-infer remote name when possible
3 participants