Skip to content

Fix creating references containing '@' #854

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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion git/repo/fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,14 @@ def rev_parse(repo, rev):
ref = repo.head.ref
else:
if token == '@':
ref = name_to_object(repo, rev[:start], return_ref=True)
try:
Copy link
Member

Choose a reason for hiding this comment

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

A better solution might be to stop treating @ as special outside of the spots that it is allowed in.
I am a hesitant to let it make assumptions unless there absolutely is no other way. Or in other words, I believe the git or C implementation is deterministic here

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for your feedback, I'll try it when I have time in the next weeks.

ref = name_to_object(repo, rev[:start], return_ref=True)
except BadObject:
# If this doesn't result in an object we most likely
# encounter a reference containing the '@' character.
# In this case we just to continue the search.
start += 1
continue
else:
obj = name_to_object(repo, rev[:start])
# END handle token
Expand Down
4 changes: 4 additions & 0 deletions git/test/test_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,10 @@ def test_rw_rev_parse(self, rwrepo):
ahead = rwrepo.create_head('aaaaaaaa')
assert(rwrepo.rev_parse(str(ahead)) == ahead.commit)

# verify @ in branch names are possible
bhead = rwrepo.create_head('aaa@aaa')
assert (rwrepo.rev_parse(str(bhead)) == bhead.commit)

def test_rev_parse(self):
rev_parse = self.rorepo.rev_parse

Expand Down