Skip to content

Commit d2b29b8

Browse files
committed
Ensure automerge only runs on a clean git worktree (#179)
This patch introduces an additional check at the start of the automerge script to ensure that it only runs on a clean git worktree. This check prevents issues where local changes might be included unintentionally as part of merge commits.
1 parent d4f0f12 commit d2b29b8

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

arm-software/ci/automerge.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,12 @@ def pr_exist_for_label(project_name: str, label: str) -> bool:
166166
return len(json.loads(gh_process.stdout)) > 0
167167

168168

169+
def is_worktree_clean(git_repo: Git) -> bool:
170+
# `git status --porcelain` returns an empty result if worktree is clean
171+
status_output = git_repo.run_cmd(["status", "--porcelain"]).strip()
172+
return len(status_output) == 0
173+
174+
169175
def main():
170176
arg_parser = argparse.ArgumentParser(
171177
prog="automerge",
@@ -219,6 +225,10 @@ def main():
219225

220226
git_repo = Git(args.repo_path)
221227

228+
if not is_worktree_clean(git_repo):
229+
logger.error("The repository worktree is not clean. Cannot continue.")
230+
sys.exit(1)
231+
222232
with open(MERGE_IGNORE_PATHSPEC_FILE) as ignored_paths_file:
223233
ignored_paths = ignored_paths_file.read().splitlines()
224234

0 commit comments

Comments
 (0)