Skip to content

Commit 5433f56

Browse files
committed
fix: warn instead of exception for nothing to commit
1 parent 583d0ed commit 5433f56

4 files changed

Lines changed: 36 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Next Release
44

55
- Adds `custom_tarball` parameter, allowing you to bundle your distributable assets however you'd like (closes #63)
6+
- Homebrew Releaser now warns instead of raising an exception and exiting with a failure if the `git commit` operation is unsuccessful due to "nothing to commit". This is useful if you want to test back to back releases or need to recreate a release but the underlying assets have not changed (closes #69)
67
- Optimizes how asset URL selection occurs when downloading assets to generate checksums for
78

89
## v3.1.0 (2025-12-26)

homebrew_releaser/app.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ def run_github_action():
227227
logger.debug("Skipping update to project README.")
228228

229229
# Although users can skip a commit, still commit (but don't push) to dry-run the commit for debugging purposes
230+
logger.info("Preparing git commit...")
230231
copy_formula_file_to_git(formula_filepath, HOMEBREW_TAP)
231232
add_git(HOMEBREW_TAP)
232233
commit_git(HOMEBREW_TAP, GITHUB_REPO, version)

homebrew_releaser/git.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,17 @@ def add_git(homebrew_tap: str):
6363

6464
def commit_git(homebrew_tap: str, repo_name: str, version: str):
6565
"""Commits git assets to the Homebrew tap repo."""
66+
logger = woodchips.get(LOGGER_NAME)
6667
# fmt: off
6768
command = ['git', '-C', build_dir_path(homebrew_tap), 'commit', '-m', f'chore: brew formula update for {repo_name} {version}'] # noqa
6869
# fmt: on
69-
_run_git_subprocess(command, "Assets committed successfully.")
70+
try:
71+
_run_git_subprocess(command, "Assets committed successfully.")
72+
except subprocess.CalledProcessError as e:
73+
if "nothing to commit" in e.output:
74+
logger.warning("No changes to commit.")
75+
else:
76+
raise
7077

7178

7279
def push_git(homebrew_tap: str, homebrew_owner: str):

test/unit/test_git.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,32 @@ def test_commit(mock_subprocess):
104104
)
105105

106106

107+
@patch("homebrew_releaser.utils.WORKING_DIR", "")
108+
@patch("logging.Logger.warning")
109+
@patch("subprocess.check_output")
110+
def test_nothing_to_commit(mock_subprocess, mock_logger):
111+
"""Tests that we call the correct git commit command."""
112+
homebrew_tap = "homebrew-formulas"
113+
repo_name = "mock-repo"
114+
version = "0.1.0"
115+
116+
error = subprocess.CalledProcessError(
117+
returncode=1,
118+
cmd=["git", "-C", homebrew_tap, "commit", "-m", f"chore: brew formula update for {repo_name} {version}"],
119+
output="On branch main\nnothing to commit, working tree clean\n",
120+
)
121+
mock_subprocess.side_effect = error
122+
123+
commit_git(homebrew_tap, repo_name, version)
124+
mock_subprocess.assert_called_once_with(
125+
["git", "-C", homebrew_tap, "commit", "-m", f"chore: brew formula update for {repo_name} {version}"],
126+
stderr=-2,
127+
text=True,
128+
timeout=TIMEOUT,
129+
)
130+
mock_logger.assert_called_once_with("No changes to commit.")
131+
132+
107133
@patch("homebrew_releaser.utils.WORKING_DIR", "")
108134
@patch("homebrew_releaser.git.GITHUB_TOKEN", "123")
109135
@patch("subprocess.check_output")

0 commit comments

Comments
 (0)