Skip to content

Commit

Permalink
Workaround reflog corruption bug in git 2.48
Browse files Browse the repository at this point in the history
In git 2.48, there is an issue where using `git update-ref` add a new
entry to the reflog for a branch will cause corrupted reflog entries to
be created for any symbolic refs referencing the updated reference. This
impacts most usage of `git-revise`, as we update the default `HEAD`
reference indirectly due to using `git rev-parse --symbolic-full-name`
to resolve the identity of a branch.

This patch works around this issue in the common case by checking if the
given name directly names a valid ref or symbolic ref, skipping the
`--symbolic-full-name` resolution if it does. This means that HEAD will
be directly updated by `git update-ref`, and receive valid reflog
entries.

This workaround shouldn't negatively impact other git versions, and is
largely an internal change to how symbolic refs are handled by the
odb.Reference type.

See #138 for details.
  • Loading branch information
mystor committed Jan 23, 2025
1 parent cf5ee2c commit 11c9474
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion gitrevise/odb.py
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,20 @@ class Reference(Generic[GitObjT]): # pylint: disable=unsubscriptable-object

def __init__(self, obj_type: Type[GitObjT], repo: Repository, name: str) -> None:
self._type = obj_type
self.name = repo.git("rev-parse", "--symbolic-full-name", name).decode()

self.name = name
try:
# Silently verify that a ref with the name exists and recover if it
# doesn't.
repo.git("show-ref", "--quiet", "--verify", self.name)
except CalledProcessError:
# `name` could be a branch name which can be resolved to a ref. Try
# to do so with `rev-parse`, and verify that the new name exists.
self.name = repo.git(
"rev-parse", "--symbolic-full-name", self.name
).decode()
repo.git("show-ref", "--verify", self.name)

self.repo = repo
self.refresh()

Expand Down

0 comments on commit 11c9474

Please sign in to comment.