Skip to content

Commit d486c4c

Browse files
committed
Abort bump_version.py script if README.md contains uncommitted changes.
1 parent f458945 commit d486c4c

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

scripts/bump_version.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,25 @@ def run(cmd: List[str]) -> None:
4242
subprocess.run(cmd).check_returncode()
4343

4444

45+
def contains_uncommitted_change(filepath: str):
46+
# Add non-existent file check/guard, because `git status --porcelain` has
47+
# similar output for both unmodified file and non-existent file
48+
if not os.path.exists(filepath):
49+
raise FileNotFoundError(f"Can't get status of non-existent file: {filepath}")
50+
51+
cmpl_proc = subprocess.run(
52+
["git", "status", "--porcelain", "--no-renames", "--", filepath],
53+
capture_output=True,
54+
text=True,
55+
encoding="utf-8",
56+
)
57+
58+
if cmpl_proc.returncode != 0:
59+
raise RuntimeError(f"Error getting status of {filepath}")
60+
61+
return cmpl_proc.stdout[:2] != " "
62+
63+
4564
@click.command()
4665
@click.argument("component")
4766
@click.option("--no-release", is_flag=True)
@@ -67,8 +86,12 @@ def main(component: str, no_release: bool) -> None:
6786
bump_file_README(new_version)
6887

6988
run(["git", "add", "fetcher/__version__.py"])
70-
# FIXME what if README contains some local changes that we don't
71-
# want to commit yet?
89+
90+
if contains_uncommitted_change("README.md"):
91+
raise RuntimeError(
92+
"README.md contains uncommitted change. "
93+
"Please clean it up before rerun the script."
94+
)
7295
run(["git", "add", "README.md"])
7396

7497
print("Committing the special commit for bumping version......")

0 commit comments

Comments
 (0)