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

Fix get_branch() to work if the current branch shares a name with a tag #5912

Merged
merged 4 commits into from
Dec 21, 2018

Conversation

cjerdonek
Copy link
Member

This PR tightens up a helper function to address an edge case revealed by issue #5867.

The helper function returns the name of the branch that HEAD is at, if HEAD is at a branch. However, this didn't work if HEAD is at a branch whose name also matches the name of a tag.

I found that the cleanest way to do this was to use a Git command that exits with status code 1 in the case of a detached HEAD, so I added a new argument to call_subprocess() that lets one indicate additional return codes that are okay (i.e. in addition to 0).

This new argument will also help on another issue that can benefit from a similar Git command that returns 0 or 1.

@cjerdonek cjerdonek added C: vcs pip's interaction with version control systems like git, svn and bzr skip news Does not need a NEWS file entry (eg: trivial changes) labels Oct 24, 2018
@cjerdonek
Copy link
Member Author

@di Since you've written or reviewed PR's that involve using Git in different ways, I thought you might be a good person to take a look at this PR.

@cjerdonek
Copy link
Member Author

@pradyunsg Would you be able to review this PR? The main change is to replace a use of git rev-parse with git symbolic-ref, because it has more predictable behavior in the presence of ambiguous names.

Also, the new returncodes argument is something I wanted to use for a PR after PR #6001 which you just reviewed.

@BrownTruck
Copy link
Contributor

Hello!

I am an automated bot and I have noticed that this pull request is not currently able to be merged. If you are able to either merge the master branch into this pull request or rebase this pull request against master then it will be eligible for code review and hopefully merging!

@BrownTruck BrownTruck added the needs rebase or merge PR has conflicts with current master label Dec 6, 2018
@pradyunsg
Copy link
Member

Hey @cjerdonek!

I'm back on OSS for a bit now; any chance you could update this PR?

@ssbarnea
Copy link
Contributor

@cjerdonek Please rebase it.

@cjerdonek
Copy link
Member Author

Hi @pradyunsg, sure, I should be able to get to it within the next couple days or so.

@pypa-bot pypa-bot removed the needs rebase or merge PR has conflicts with current master label Dec 16, 2018
@cjerdonek
Copy link
Member Author

@pradyunsg This is now updated.

@cjerdonek
Copy link
Member Author

@pradyunsg The tests are passing now.

@@ -653,6 +653,7 @@ def call_subprocess(
show_stdout=True, # type: bool
cwd=None, # type: Optional[str]
on_returncode='raise', # type: str
returncodes=None, # type: Optional[Iterable[int]]
Copy link
Member

Choose a reason for hiding this comment

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

maybe accepted_returncodes or acceptable_returncodes ?

Copy link
Member Author

Choose a reason for hiding this comment

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

@xavfernandez Thanks! To confirm, do you think these names are okay even if they are in addition to zero?

args = ['rev-parse', '--abbrev-ref', 'HEAD']
output = self.run_command(args, show_stdout=False, cwd=location)
branch = output.strip()
# The -q causes the command to exit with status code 1 instead of
Copy link
Member

Choose a reason for hiding this comment

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

Maybe The -q causes the command to exit with status code 1 and empty output instead of ?

Copy link
Member Author

Choose a reason for hiding this comment

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

@xavfernandez Just to clarify to you, the stdout is empty either way. It's just the exit code that changes (and a message to stderr is suppressed). But will be good to add that info in the comments in any case.

@cjerdonek
Copy link
Member Author

@xavfernandez Thanks for the review! I tried addressing your comments.

@@ -17,7 +17,7 @@

if MYPY_CHECK_RUNNING:
from typing import ( # noqa: F401
Dict, Optional, Tuple, List, Type, Any, Mapping, Text
Any, Dict, Iterable, List, Mapping, Optional, Text, Tuple, Type
Copy link
Member

Choose a reason for hiding this comment

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

This has to be automated. I'll have to check how to do this.

@lock
Copy link

lock bot commented May 31, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot added the auto-locked Outdated issues that have been locked by automation label May 31, 2019
@lock lock bot locked as resolved and limited conversation to collaborators May 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
auto-locked Outdated issues that have been locked by automation C: vcs pip's interaction with version control systems like git, svn and bzr skip news Does not need a NEWS file entry (eg: trivial changes)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants