aider: Added check=True parameter to subprocess.run() calls in scripts/versionbump.py to raise CalledProcessError exception if any of the git commands fail.

# Context:
USER: will those `subprocess` calls raise exceptions if the git commands error?
ASSISTANT: Yes, by default, the `subprocess.run()` function will not raise an exception if the command returns a non-zero exit code. However, you can add the `check=True` parameter to the `subprocess.run()` calls to make them raise a `CalledProcessError` exception if the command returns a non-zero exit code. Here's the updated `scripts/versionbump.py` with the `check=True` parameter added:

```python
scripts/versionbump.py
<<<<<<< ORIGINAL
    subprocess.run(["git", "add", "aider/__init__.py"])
    subprocess.run(["git", "commit", "-m", f"version bump to {new_version}"])
    subprocess.run(["git", "tag", f"v{new_version}"])
    subprocess.run(["git", "push", "origin"])
    subprocess.run(["git", "push", "origin", f"v{new_version}"])
=======
    subprocess.run(["git", "add", "aider/__init__.py"], check=True)
    subprocess.run(["git", "commit", "-m", f"version bump to {new_version}"], check=True)
    subprocess.run(["git", "tag", f"v{new_version}"], check=True)
    subprocess.run(["git", "push", "origin"], check=True)
    subprocess.run(["git", "push", "origin", f"v{new_version}"], check=True)
>>>>>>> UPDATED
```

With these changes, if any of the git commands fail, the script will raise a `CalledProcessError` exception and terminate.
This commit is contained in:
Paul Gauthier 2023-06-17 07:20:58 -07:00
parent 25ae54f6bf
commit 2181923859

View file

@ -25,11 +25,11 @@ def main():
with open("aider/__init__.py", "w") as f:
f.write(updated_content)
subprocess.run(["git", "add", "aider/__init__.py"])
subprocess.run(["git", "commit", "-m", f"version bump to {new_version}"])
subprocess.run(["git", "tag", f"v{new_version}"])
subprocess.run(["git", "push", "origin"])
subprocess.run(["git", "push", "origin", f"v{new_version}"])
subprocess.run(["git", "add", "aider/__init__.py"], check=True)
subprocess.run(["git", "commit", "-m", f"version bump to {new_version}"], check=True)
subprocess.run(["git", "tag", f"v{new_version}"], check=True)
subprocess.run(["git", "push", "origin"], check=True)
subprocess.run(["git", "push", "origin", f"v{new_version}"], check=True)
if __name__ == "__main__":
main()