From d68d159befc944f832b7d3f88fed9ae0dc2d6bdf Mon Sep 17 00:00:00 2001 From: Ash Vardanian <1983160+ashvardanian@users.noreply.github.com> Date: Sat, 17 Aug 2024 19:26:09 -0700 Subject: [PATCH] Improve: Exit with code `0`, if no commits are found --- tinysemver/tinysemver.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tinysemver/tinysemver.py b/tinysemver/tinysemver.py index 7f5a8b5..41a3bf7 100755 --- a/tinysemver/tinysemver.py +++ b/tinysemver/tinysemver.py @@ -56,6 +56,12 @@ PathLike = Union[str, os.PathLike] +class NoNewCommitsError(Exception): + """Raised when no new commits are found since the last tag.""" + + pass + + def get_last_tag(repository_path: PathLike) -> str: """Retrieve the last Git tag name from the repository.""" result = subprocess.run( @@ -403,7 +409,8 @@ def normalize_path(file_path: str) -> str: print(f"Current version: {current_version[0]}.{current_version[1]}.{current_version[2]}") commits_hashes, commits_messages = get_commits_since_tag(repository_path, last_tag) - assert len(commits_hashes), f"No new commits since the last {last_tag} tag, aborting." + if not len(commits_hashes): + raise NoNewCommitsError(f"No new commits since the last {last_tag} tag") if verbose: print(f"? Commits since last tag: {len(commits_hashes)}") @@ -653,6 +660,9 @@ class Args: push=args.push, create_release=args.create_release, ) + except NoNewCommitsError as e: + print(f"! {e}") + exit(0) except AssertionError as e: print(f"! {e}") exit(1)