-
Notifications
You must be signed in to change notification settings - Fork 246
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
default to upstream branch #140
Conversation
c814e32
to
7eeef18
Compare
git-open
Outdated
branch_name=$(git name-rev --name-only HEAD 2>/dev/null) | ||
tracked_remote=$(git config "branch.$branch_name.remote") | ||
branch=${2:-$(git symbolic-ref -q --short HEAD)} | ||
upstream_branch=$(git config "branch.$branch.merge" | sed "s/^refs\/heads\///") |
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.
https://git-scm.com/docs/git-config#Documentation/git-config.txt-branchltnamegtmerge It looks like this could have multiple values but git config will just get the first value so it should be fine.
I think we can convert a lot of these lines to git for-each-ref
.
git for-each-ref --format='%(upstream:short)' "$(git symbolic-ref -q HEAD)"
. will return origin/upstream-branch
for example and then it can be split like the urlpath is below. I feel like we may be able to simplify some of the existing code here
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'm fine with pushing this off, it's not a big deal. I would like to not use sed though, for now something like this would work:
branch_ref="$(git symbolic-ref -q HEAD)"
tracked_remote="$(git for-each-ref --format='%(upstream:remotename)' "$branch_ref")"
upstream_branch="$(git for-each-ref --format='%(upstream:lstrip=-1)' "$branch_ref")"
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.
Travis tests fails for remotename
, is it new? fatal: unrecognized %(upstream:remotename) argument: remotename
Other than that I wouldn't mind for-each-ref
, though it would need some more tweaking to handle user input.
Also lstrip=-1
wouldn't work for me since I have a /
in my remote branch name, though lstrip=3
seems to to do the trick
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.
Did another attempt without sed
using parameter-substitution
upstream_branch_full_name=$(git config "branch.$branch.merge")
upstream_branch=${upstream_branch_full_name#"refs/heads/"}
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.
Good call looks semi-new (from 2017): git/git@cc72385.
7eeef18
to
f56eb1d
Compare
f56eb1d
to
3d1ad21
Compare
Sorry for taking so long to get to this, looks good 👍 |
Hello again
I always name my remote branches with a prefix. For instance I push
upstream-branch
to remote branchlovef.code/upstream-branch
. Therefore I likegit open
to default open the upstream branch. Currently I would instead get a 404