git: normalize reference during unbundle

Summary:
Certain git bundles might contain references like "BUNDLE_HEAD" that would be
ignored by usual paths. Normalize them to visibleheads refs.

Differential Revision: D33968793

fbshipit-source-id: a3d6fc1a7d73328cddf0ebddfe7b7a021d929528
This commit is contained in:
Jun Wu 2022-02-03 15:19:52 -08:00 committed by Facebook GitHub Bot
parent 1582804af2
commit c4334d4e7b

View File

@ -375,8 +375,17 @@ def _writevisibleheadrefs(repo, nodes):
def _writerefs(repo, refnodes):
"""write git references. refnodes is a list of (ref, node)."""
"""write git references. refnodes is a list of (ref, node).
Only 'refs/heads/<name>' references are written (as local bookmarks).
Other references will be normalized to `refs/visibleheads/<hex>`.
"""
for (ref, node) in refnodes:
ref = str(ref)
if not ref.startswith("refs/heads/"):
# ref might be non-standard like "BUNDLE_HEAD".
# normalize it to a visiblehead ref.
ref = str(RefName.visiblehead(node))
callgit(repo, ["update-ref", str(ref), hex(node)])