Skip to content
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

Feat 451 add commit args #621

Merged
merged 8 commits into from
Oct 17, 2023

Conversation

SCrocky
Copy link
Contributor

@SCrocky SCrocky commented Nov 26, 2022

Description

Added extra argument mechanic for cz commit command so that all arguments after a -- will be treated as extra args.
Example: You can now sign commits with cz c -- -S

Checklist

  • Add test cases to all the changes you introduce
  • Run ./scripts/format and ./scripts/test locally to ensure this change passes linter check and test
  • Test the changes on the local machine manually
  • Update the documentation for the changes

Steps to Test This Pull Request

Additional context

This PR should close issue 451

Copy link
Member

@Lee-W Lee-W left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for late reviewing. The overall idea looks good to me! But we'll need doc and unit test for this one. After this is merged, I think we can have one branch removing the original signoff and send that PR to v3 branch

@SCrocky
Copy link
Contributor Author

SCrocky commented Dec 17, 2022

Sorry for late reviewing. The overall idea looks good to me! But we'll need doc and unit test for this one. After this is merged, I think we can have one branch removing the original signoff and send that PR to v3 branch

Sounds good, I'll get on the tests next.

@woile
Copy link
Member

woile commented Apr 28, 2023

Any update on this? We'd appreciate having the tests and rebasing 🙏🏻

@SCrocky
Copy link
Contributor Author

SCrocky commented Apr 28, 2023

I have some time this weekend. I'll try to finish it then.

@SCrocky
Copy link
Contributor Author

SCrocky commented May 15, 2023

Done rebasing, added both tests and doc.

@SCrocky
Copy link
Contributor Author

SCrocky commented May 15, 2023

Done reading, added both tests and doc.
@woile @Lee-W

Copy link
Member

@Lee-W Lee-W left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am thrilled about this wonderful feature! I was able to spare some time to examine it. I have just provided a few comments and suggestions.

@@ -91,7 +91,11 @@ def __call__(self):
signoff: bool = self.arguments.get("signoff")

if signoff:
out.warn("signoff mechanic is deprecated, please use `cz commit -- -s` instead.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@woile Do you think we should add a list somewhere so we won't forget to deprecate stuff in the next release?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SCrocky In this implementation, if we're using the original signoff feature, we won't be able to use extra_cli_args.. Should we implement it as something like the following? (the warning is still needed)

extra_cli_args = ""

if signoff:
    extra_cli_args = "-s "

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see it. Thanks for that.

Would this work for you?

        if signoff:
            out.warn("signoff mechanic is deprecated, please use `cz commit -- -s` instead.")
            extra_args = "-s " + self.arguments.get("extra_cli_args")
        else:
            extra_args = self.arguments.get("extra_cli_args")

        c = git.commit(m, extra_args=extra_args)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might try something like

        extra_args = self.arguments.get("extra_cli_args", "")
        if signoff:
            out.warn("signoff mechanic is deprecated, please use `cz commit -- -s` instead.")
            extra_args += " -s"

        c = git.commit(m, extra_args=extra_args)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But one thing I'm thinking is whether we should handle cz commit -s -- -s

Copy link
Contributor Author

@SCrocky SCrocky Jun 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested it and doesn't seem to be an issue with the git command:

>>> git commit -s -s -m "test commit" 
[master (root-commit) b864659] test commit
 1 file changed, 0 insertions(+), 0 deletions(-)

But it is a bit messy. Warning or error?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it doesn't cause an error, I'm good with either silently passing or warning.

c = git.commit(m, "-s")

if self.arguments.get("extra_cli_args"):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this if-else block? Could we handle the case in git.commit() when extra_cli_args is not provided?

docs/commit.md Outdated
Comment on lines 22 to 26
```
cz commit -commitizen-args -- -git-cli-args
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
```
cz commit -commitizen-args -- -git-cli-args
```
```sh
cz commit -- <git-cli-args>
# e.g., cz commit --dry-run -- -a -S

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we keep commitizen-args ? It provides clarity IMO.

cz commit <commitizen-args> -- <git-cli-args>

# e.g., cz commit --dry-run -- -a -S

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure 🙂 Looks better 👍

raise InvalidCommandArgumentError(
f"Invalid commitizen arguments were found before -- separator: `{' '.join(unknown_args[:pos])}`. "
)
extra_args = " ".join(unknown_args[1:])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might need to handle the case that the user use -- without actually providing an argument. e.g., cz commit --

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, how should we deal with it?

Warning or error?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning should be enough in this case 👍

@mesaglio
Copy link

mesaglio commented Sep 23, 2023

Is this wait something? I think -S flag its good to use for security reasons.

@SCrocky
Copy link
Contributor Author

SCrocky commented Sep 24, 2023

I've fixed rebased to master, fixed all the previous issues, added/edited tests and added some documentation.

@Lee-W ready for Round 2?

@codecov
Copy link

codecov bot commented Sep 24, 2023

Codecov Report

Attention: 9 lines in your changes are missing coverage. Please review.

Files Coverage Δ
commitizen/__version__.py 100.00% <100.00%> (ø)
commitizen/commands/bump.py 97.66% <100.00%> (+0.01%) ⬆️
commitizen/commands/commit.py 98.68% <100.00%> (+0.09%) ⬆️
commitizen/config/json_config.py 100.00% <100.00%> (+6.45%) ⬆️
commitizen/config/toml_config.py 100.00% <100.00%> (ø)
commitizen/config/yaml_config.py 100.00% <100.00%> (ø)
commitizen/defaults.py 98.38% <100.00%> (-1.62%) ⬇️
commitizen/providers/__init__.py 100.00% <100.00%> (ø)
commitizen/providers/base_provider.py 100.00% <100.00%> (ø)
commitizen/providers/cargo_provider.py 100.00% <100.00%> (ø)
... and 8 more

... and 1 file with indirect coverage changes

📢 Thoughts on this report? Let us know!.

Copy link
Member

@Lee-W Lee-W left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@woile @noirbizarre Might need some time to take a deeper look, but I think most of the parts are good.

Comment on lines 102 to 103
args: str = "",
extra_args: str = "",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible for us to combine these 2? Not sure what's the difference between them

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra_args are arguments that we just want to pass to git transparently (like -S).

Having the extra_args argument separate helps with testing and clarity.

For example:extra_args has to start with "--" and contain at least one flag behind it. (e.g. "-- -S").

If this is contained within the args argument, then it becomes a little harder to know whether or not any extra args were passed.

Would it be possible for us to combine these 2?

git.commit is only called with extra_args in commands/commit.py __call__ method where it doesn't have any args.

So technically, if I'm not missing anything, I could just use the args argument to pass the extra_args.

Not sure what's the difference between them

I'll add a Docstring

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So technically, if I'm not missing anything, I could just use the args argument to pass the extra_args.

Yep, I think that's what we should do. Thanks for clarifying!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Sebastien Crocquevieille and others added 8 commits October 3, 2023 02:41
… for `cz commit` command

Additional edits were made in class `commitizen.commands.Commit` and `commit` func from `commitizen.git`

Closes commitizen-tools#451
Signoff dedicated code is no longer necessary & removed #TODO as tests show identical args and extra-args are not an issue.
… commitizen args from git commit cli args
Copy link
Member

@Lee-W Lee-W left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @SCrocky, for your contribution! This really helps a lot. Could you please make it ready for review?

@woile @noirbizarre I'm planning on merging it these days. Please let me know if you want to take a look

@Lee-W Lee-W added pr-status: ready-to-merge almost ready to merge. just keep it for a few days for others to check and removed pr-status: wait-for-review pr-status: wait-for-modification labels Oct 3, 2023
@SCrocky
Copy link
Contributor Author

SCrocky commented Oct 3, 2023

Thanks, @SCrocky, for your contribution! This really helps a lot.

No problem! I'm really glad to have finally finished it. 🙏

Could you please make it ready for review?

Is this addressed to me? I'm sorry, I'm not sure what the remaining steps are. Is there anything else I need to do?

@Lee-W Lee-W marked this pull request as ready for review October 3, 2023 14:34
@Lee-W
Copy link
Member

Lee-W commented Oct 3, 2023

Thanks, @SCrocky, for your contribution! This really helps a lot.

No problem! I'm really glad to have finally finished it. 🙏

Could you please make it ready for review?

Is this addressed to me? I'm sorry, I'm not sure what the remaining steps are. Is there anything else I need to do?

Ah, just found out I can do it as well

@Lee-W Lee-W merged commit 12b214e into commitizen-tools:master Oct 17, 2023
14 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-status: ready-to-merge almost ready to merge. just keep it for a few days for others to check
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add --commit-args command line option to cz commit
4 participants