Skip to content
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

Merged
merged 1 commit into from
Jun 2, 2019

Conversation

lovef
Copy link
Contributor

@lovef lovef commented Mar 24, 2019

Hello again

I always name my remote branches with a prefix. For instance I push upstream-branch to remote branch lovef.code/upstream-branch. Therefore I like git open to default open the upstream branch. Currently I would instead get a 404

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\///")
Copy link
Collaborator

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

Copy link
Collaborator

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

Copy link
Contributor Author

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

Copy link
Contributor Author

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/"}

Copy link
Collaborator

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.

@lovef lovef force-pushed the lovef.code/upstream-branch branch 4 times, most recently from 7eeef18 to f56eb1d Compare June 2, 2019 11:59
@lovef lovef force-pushed the lovef.code/upstream-branch branch from f56eb1d to 3d1ad21 Compare June 2, 2019 12:24
@derimagia derimagia merged commit 7eeee77 into paulirish:master Jun 2, 2019
@derimagia
Copy link
Collaborator

Sorry for taking so long to get to this, looks good 👍

@lovef lovef deleted the lovef.code/upstream-branch branch June 2, 2019 19:38
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.

None yet

2 participants