-
-
Notifications
You must be signed in to change notification settings - Fork 301
Feat 451 add commit args #621
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
Changes from all commits
adfdfb1
5888f37
142094e
081332d
0abb01e
8df5c94
4baecd6
5159a62
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
CommitizenException, | ||
ExitCode, | ||
ExpectedExit, | ||
InvalidCommandArgumentError, | ||
NoCommandFoundError, | ||
) | ||
|
||
|
@@ -441,7 +442,7 @@ def main(): | |
|
||
# This is for the command required constraint in 2.0 | ||
try: | ||
args= parser.parse_args() | ||
args, unknown_args = parser.parse_known_args() | ||
except (TypeError, SystemExit) as e: | ||
# https://github.com/commitizen-tools/commitizen/issues/429 | ||
# argparse raises TypeError when non exist command is provided on Python < 3.9 | ||
|
@@ -450,6 +451,28 @@ def main(): | |
raise NoCommandFoundError() | ||
raise e | ||
|
||
arguments = vars(args) | ||
if unknown_args: | ||
# Raise error for extra-args without -- separation | ||
if "--" not in unknown_args: | ||
raise InvalidCommandArgumentError( | ||
f"Invalid commitizen arguments were found: `{' '.join(unknown_args)}`. " | ||
"Please use -- separator for extra git args" | ||
) | ||
# Raise error for extra-args before -- | ||
elif unknown_args[0] != "--": | ||
pos = unknown_args.index("--") | ||
raise InvalidCommandArgumentError( | ||
f"Invalid commitizen arguments were found before -- separator: `{' '.join(unknown_args[:pos])}`. " | ||
) | ||
# Log warning for -- without any extra args | ||
elif len(unknown_args) == 1: | ||
logger.warning( | ||
"\nWARN: Incomplete commit command: received -- separator without any following git arguments\n" | ||
) | ||
extra_args = " ".join(unknown_args[1:]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We might need to handle the case that the user use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, how should we deal with it? Warning or error? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Warning should be enough in this case 👍 |
||
arguments["extra_cli_args"] = extra_args | ||
|
||
if args.name: | ||
conf.update({"name": args.name}) | ||
elif not args.name and not conf.path: | ||
|
@@ -465,7 +488,7 @@ def main(): | |
) | ||
sys.excepthook = no_raise_debug_excepthook | ||
|
||
args.func(conf, vars(args))() | ||
args.func(conf, arguments)() | ||
|
||
|
||
if __name__ == "__main__": | ||
|