Skip to content

Commit 6434cc1

Browse files
Use git ignore to exclude files from rsync (MetOffice#170)
Instead of using a hard-coded list of ignored files when rsyncing, generate a list of ignored files using git status --ignored -s and use this instead.
1 parent 5f4146c commit 6434cc1

1 file changed

Lines changed: 9 additions & 20 deletions

File tree

github_scripts/get_git_sources.py

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -134,26 +134,15 @@ def sync_repo(repo_source: str, repo_ref: str, loc: Path) -> None:
134134
# Create a clean clone location
135135
loc.mkdir(parents=True)
136136

137-
exclude_dirs = (
138-
"applications/*/working",
139-
"applications/*/test",
140-
"applications/*/bin",
141-
"science/*/working",
142-
"science/*/test",
143-
"science/*/bin",
144-
"interfaces/*/working",
145-
"interfaces/*/test",
146-
"interfaces/*/bin",
147-
"components/*/working",
148-
"components/*/test",
149-
"components/*/bin",
150-
"infrastructure/*/working",
151-
"infrastructure/*/test",
152-
"infrastructure/*/bin",
153-
"mesh_tools/*/working",
154-
"mesh_tools/*/test",
155-
"mesh_tools/*/bin",
156-
)
137+
exclude_dirs = []
138+
host, path = repo_source.split(":", 1)
139+
result = run_command(f"ssh {host} git -C {path} status --ignored -s")
140+
for ignore_file in result.stdout.split("\n"):
141+
ignore_file = ignore_file.strip()
142+
if not ignore_file.startswith("!!"):
143+
continue
144+
ignore_file = ignore_file.removeprefix("!!").strip()
145+
exclude_dirs.append(ignore_file)
157146

158147
# Trailing slash required for rsync
159148
command = f"rsync -av {repo_source}/ {loc}"

0 commit comments

Comments
 (0)