Skip to content

Commit 7bd8edf

Browse files
robtaylorclaude
andcommitted
Preserve local changes in vendor repos during docs build
Add check in copy_docs.py to skip git checkout when a vendor repository has uncommitted changes or is on a local branch. This prevents losing work-in-progress changes when rebuilding documentation. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 0a9f77b commit 7bd8edf

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

tools/copy_docs.py

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,31 @@
1010
from pathlib import Path
1111
from typing import List, Tuple
1212

13+
14+
def has_local_changes(repodir: Path) -> bool:
15+
"""Check if a git repository has uncommitted changes or is on a non-detached branch."""
16+
# Check for uncommitted changes
17+
status_result = subprocess.run(
18+
['git', '-C', repodir, 'status', '--porcelain'],
19+
capture_output=True,
20+
text=True
21+
)
22+
if status_result.stdout.strip():
23+
return True
24+
25+
# Check if we're on a branch (not detached HEAD)
26+
branch_result = subprocess.run(
27+
['git', '-C', repodir, 'symbolic-ref', '-q', 'HEAD'],
28+
capture_output=True,
29+
text=True
30+
)
31+
if branch_result.returncode == 0:
32+
# We're on a branch, check if it has commits ahead of origin
33+
return True
34+
35+
return False
36+
37+
1338
def copy_docs(repos: List[Tuple[str, str]]) -> List[Path]:
1439
""""
1540
Pull in docs from other repos.
@@ -43,11 +68,14 @@ def copy_docs(repos: List[Tuple[str, str]]) -> List[Path]:
4368

4469
# Check if repo already exists
4570
if repodir.exists():
46-
print(f"{repo_path} already there, updating")
47-
# Git fetch
48-
subprocess.run(['git', '-C', repodir, 'fetch'], check=True)
49-
# Checkout ref
50-
subprocess.run(['git', '-C', repodir, 'checkout', '-f', '--detach', ref], check=True)
71+
if has_local_changes(repodir):
72+
print(f"{repo_path} has local changes, skipping update")
73+
else:
74+
print(f"{repo_path} already there, updating")
75+
# Git fetch
76+
subprocess.run(['git', '-C', repodir, 'fetch'], check=True)
77+
# Checkout ref
78+
subprocess.run(['git', '-C', repodir, 'checkout', '-f', '--detach', ref], check=True)
5179
else:
5280
print(f"Cloning {repo_path} {ref} as {repodir}")
5381
# Clone the repository with gh

0 commit comments

Comments
 (0)