Skip to content

git.get_commits error check #540

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Aug 21, 2022
Next Next commit
fix(git): improves git error checking in get_commits
older version of git did not have the --author-date-order argument so it is best to report that kind of error.
  • Loading branch information
bhelgs committed Aug 14, 2022
commit d36c0c2ed0095c75cbb3a5349a0adf58a88df621
5 changes: 5 additions & 0 deletions commitizen/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class ExitCode(enum.IntEnum):
NOT_ALLOWED = 20
NO_INCREMENT = 21
UNRECOGNIZED_CHARACTERSET_ENCODING = 22
GIT_COMMAND_ERROR = 23


class CommitizenException(Exception):
Expand Down Expand Up @@ -153,3 +154,7 @@ class NotAllowed(CommitizenException):

class CharacterSetDecodeError(CommitizenException):
exit_code = ExitCode.UNRECOGNIZED_CHARACTERSET_ENCODING


class GitCommandError(CommitizenException):
exit_code = ExitCode.GIT_COMMAND_ERROR
3 changes: 3 additions & 0 deletions commitizen/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import List, Optional

from commitizen import cmd
from commitizen.exceptions import GitCommandError

UNIX_EOL = "\n"
WINDOWS_EOL = "\r\n"
Expand Down Expand Up @@ -118,6 +119,8 @@ def get_commits(
else:
command = f"{git_log_cmd} {end}"
c = cmd.run(command)
if c.return_code != 0:
raise GitCommandError(c.err)
if not c.out:
return []

Expand Down
1 change: 1 addition & 0 deletions docs/exit_codes.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ These exit codes can be found in `commitizen/exceptions.py::ExitCode`.
| NotAllowed | 20 | `--incremental` cannot be combined with a `rev_range` |
| NoneIncrementExit | 21 | The commits found are not eligible to be bumped |
| CharacterSetDecodeError | 22 | The character encoding of the command output could not be determined |
| GitCommandError | 23 | Unexpected failure while calling a git command |