reuse_refs_check: sibling repos beside the MAIN clone for a worktree (R-1114)
gates / gates (push) Successful in 6m43s
gates / gates (push) Successful in 6m43s
FELHOM_WORKSPACE (set by felhom-controller's runner) names where the sibling repos are; the worktree's own main clone is skipped. Unset: unchanged. Test red-proved both ways. Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
This commit is contained in:
@@ -115,13 +115,33 @@ def index_for(root):
|
||||
return _index_cache[root]
|
||||
|
||||
|
||||
def _main_clone_of_worktree(root):
|
||||
"""The main clone of a linked worktree (its `.git` FILE reads `gitdir: <main>/.git/worktrees/<name>`), else None."""
|
||||
try:
|
||||
with open(os.path.join(root, ".git")) as fh:
|
||||
line = fh.readline().strip()
|
||||
except OSError: # a directory (a main clone) or absent
|
||||
return None
|
||||
if not line.startswith("gitdir:"):
|
||||
return None
|
||||
gitdir = os.path.realpath(line[len("gitdir:"):].strip())
|
||||
head, tail = os.path.split(os.path.dirname(gitdir)) # <main>/.git, "worktrees"
|
||||
if tail != "worktrees" or os.path.basename(head) != ".git":
|
||||
return None
|
||||
return os.path.dirname(head)
|
||||
|
||||
|
||||
def find_siblings(root):
|
||||
"""Immediate sibling dirs of <root> that are themselves git working trees. One level only.
|
||||
|
||||
Returns (list_of_paths, error_message_or_None). A sibling repo that is simply absent is NEVER
|
||||
a failure — a clone in isolation must still be able to check itself.
|
||||
"""
|
||||
parent = os.path.dirname(os.path.abspath(root))
|
||||
# FELHOM_WORKSPACE (R-1114): set by felhom-controller's runner to the MAIN clone's parent when <root> is a
|
||||
# worktree outside git/ (its own parent holds other worktrees, not the sibling repos). The main clone of
|
||||
# <root> itself is then skipped: a path deleted in the worktree must not resolve in the main clone.
|
||||
parent = os.environ.get("FELHOM_WORKSPACE") or os.path.dirname(os.path.abspath(root))
|
||||
own_main = _main_clone_of_worktree(root)
|
||||
try:
|
||||
entries = sorted(os.listdir(parent))
|
||||
except OSError as e:
|
||||
@@ -129,7 +149,7 @@ def find_siblings(root):
|
||||
sibs = []
|
||||
for e in entries:
|
||||
p = os.path.join(parent, e)
|
||||
if os.path.abspath(p) == os.path.abspath(root):
|
||||
if os.path.abspath(p) == os.path.abspath(root) or (own_main and os.path.realpath(p) == own_main):
|
||||
continue
|
||||
if os.path.isdir(p) and os.path.exists(os.path.join(p, ".git")):
|
||||
sibs.append(p)
|
||||
|
||||
Reference in New Issue
Block a user