Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@mmontes11
Copy link
Contributor

@mmontes11 mmontes11 commented Sep 29, 2020

Closes #1897

Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

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

Thank you for tackling this!

@mmontes11 mmontes11 changed the title Using git branch --show-current for getting the current branch Avoding --short option in git symbolic-ref for getting the current branch Sep 30, 2020
Copy link
Contributor

@samcoe samcoe left a comment

Choose a reason for hiding this comment

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

The code looks good to me. Thank you for adding tests 🙇

Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

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

Looks great! Just a few tiny bits, please ✨


func getBranchShortName(output []byte) string {
branch := firstLine(output)
return strings.TrimPrefix(branch, "refs/heads/")
Copy link

@nightpool nightpool Oct 1, 2020

Choose a reason for hiding this comment

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

looking at the code for git branch --show-current it looks like we maybe should also error if HEAD doesn't point to a branch (if the refs/heads/ prefix isn't present). I don't know when this could happen, but git seems to check for it: https://github.com/git/git/blob/master/builtin/branch.c#L456-L466

Copy link

@nightpool nightpool Oct 1, 2020

Choose a reason for hiding this comment

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

the --shorten rules mention tags and remote-tracking branches https://github.com/git/git/blob/master/refs.c#L520-L528, but i can't get either of those to get reported for HEAD, so this may be a non-issue and just overly-defensive code.

$ git checkout v0.9.0
HEAD is now at bcc2c38 v0.9.0
$ git symbolic-ref HEAD
fatal: ref HEAD is not a symbolic ref

$ git checkout origin/master
Previous HEAD position was bcc2c38 v0.9.0
HEAD is now at 2822914 precompiled formik
$ git symbolic-ref HEAD
fatal: ref HEAD is not a symbolic ref

Copy link
Contributor

Choose a reason for hiding this comment

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

@nightpool Thanks for the thorough review!

I'm not aware that a successful git symbolic-ref HEAD can return any values other than ones prefixed with refs/heads/, so I think the current approach is fine without adding any additional conditionals.

Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

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

@mmontes11 Thanks for the updates! This looks great 👍

@mislav mislav merged commit 2eab4a9 into cli:trunk Oct 6, 2020
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.

gh pr create fails when branch name contains whitespace

4 participants