Skip to content

Commit 5372b44

Browse files
CopilotByron
andauthored
Refine at-sign rev parsing fix
Agent-Logs-Url: https://github.com/gitpython-developers/GitPython/sessions/0273e08f-ead0-4b1e-b148-b103851caca9 Co-authored-by: Byron <63622+Byron@users.noreply.github.com>
1 parent d8a4958 commit 5372b44

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

git/repo/fun.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -266,16 +266,15 @@ def rev_parse(repo: "Repo", rev: str) -> AnyGitObject:
266266
parsed_to = 0
267267
lr = len(rev)
268268
while start < lr:
269+
at_points_to_reflog = False
269270
if rev[start] not in "^~:@":
270271
start += 1
271272
continue
272273
if rev[start] == "@":
273274
next_char = rev[start + 1] if start + 1 < lr else None
274-
if start == 0:
275-
if next_char not in (None, "{", "^", "~", ":"):
276-
start += 1
277-
continue
278-
elif next_char != "{":
275+
at_points_to_reflog = next_char == "{"
276+
is_head_shorthand = start == 0 and next_char in (None, "^", "~", ":")
277+
if not (at_points_to_reflog or is_head_shorthand):
279278
start += 1
280279
continue
281280
# END handle start
@@ -301,7 +300,7 @@ def rev_parse(repo: "Repo", rev: str) -> AnyGitObject:
301300

302301
start += 1
303302

304-
if token == "@" and (start >= lr or rev[start] != "{"):
303+
if token == "@" and not at_points_to_reflog:
305304
obj = cast(AnyGitObject, ref.commit)
306305
ref = None
307306
parsed_to = start

test/test_repo.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ def test_commit_from_tag_starting_with_at(self, rw_dir):
159159
commit = repo.index.commit("init")
160160
repo.create_tag("@foo")
161161

162+
self.assertEqual(repo.tags["@foo"].commit, commit)
162163
self.assertEqual(repo.commit("@"), commit)
163164
self.assertEqual(repo.commit("@foo"), commit)
164165

0 commit comments

Comments
 (0)