We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent caab3d2 commit dcc0787Copy full SHA for dcc0787
1 file changed
tools/precommit/normalize_yaml_ext.py
@@ -29,14 +29,23 @@
29
30
def main() -> int:
31
"""Rename .yml files to .yaml, exit 1 if any were renamed."""
32
- renamed = []
+ renamed: list[tuple[Path, Path]] = []
33
+ collisions: list[tuple[Path, Path]] = []
34
for f in sys.argv[1:]:
35
path = Path(f)
36
if path.suffix == ".yml" and path.is_file():
37
new_path = path.with_suffix(".yaml")
38
+ if new_path.exists():
39
+ collisions.append((path, new_path))
40
+ continue
41
os.rename(path, new_path)
42
renamed.append((path, new_path))
43
44
+ if collisions:
45
+ for old, new in collisions:
46
+ print(f"ERROR: Cannot rename {old} -> {new} (destination already exists)")
47
+ return 1
48
+
49
if renamed:
50
for old, new in renamed:
51
print(f"Renamed: {old} -> {new}")
0 commit comments