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

refactor(git-authors): add unit test for option --output #1115

Closed
wants to merge 4 commits into from

Conversation

vanpipy
Copy link
Collaborator

@vanpipy vanpipy commented Nov 19, 2023

Close #1100

    * doc(git-authors): update option `--output` usage
Copy link
Collaborator

@hyperupcall hyperupcall left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution, I have a few first comments. It would be easier to review, and less error-prone if you didn't add tests at the same time as changing the whole script. Or, if you did so, to make only the necessary changes.

bin/git-authors Outdated
no_email=1
;;
--output )
if [[ -n $2 ]] && [[ $2 =~ ^[a-zA-Z] ]]; then
Copy link
Collaborator

Choose a reason for hiding this comment

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

This validation is a breaking change since absolute paths paths and relative paths (starting with ./) will now error and fail. This includes paths like /dev/fd/30, which show up frequently in scripting.

Copy link
Collaborator Author

@vanpipy vanpipy Nov 20, 2023

Choose a reason for hiding this comment

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

Thanks, I got this error and this is a missing I did not think about. For option --output, it looks supporting the path makes sense.

Copy link
Collaborator

@hyperupcall hyperupcall Nov 26, 2023

Choose a reason for hiding this comment

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

Thank you for your modifications. But now, if the file begins with a non-ASCII character like á, the file will not be written to. I suggest removing this sort of check altogether (just keep the -z/-n, how it was before)

bin/git-authors Outdated Show resolved Hide resolved
fi
if [[ $# = 1 ]] && [[ "$1" = "--no-email" ]]; then
echo >&2 "--no-email option only can be used with --list | -l | --output"
exit 1
Copy link
Collaborator

Choose a reason for hiding this comment

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

Checks can be good, but I'm looking at a previous diff, and it seems like this is a breaking change? git authors --no-email seems to have written to file AUTHORS, excluding emails?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The previous implement did not include this feature, just dump all authors has the email into AUTHORS. There is not breaking change to previous implement I thought now cause the behavior of git authors AUTHORS did not change. This condition is to forbid using --no-email with the default behavior when invoking git authors directly.

Copy link
Collaborator

@hyperupcall hyperupcall Nov 27, 2023

Choose a reason for hiding this comment

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

I'm not sure I understand. On main:

$ ./bin/git-authors --no-email
$ # Produces AUTHORS without emails

This branch:

./bin/git-authors --no-email
--no-email option only can be used with --list | -l | --output

That is a breaking change.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, please do not mark these conversations as resolved, the CONTRIBUTING mentions that is the responsibility of the reviewer. It makes it more difficult to track the conversation

man/git-authors.md Show resolved Hide resolved
exit 0
fi

while [[ $# -gt 0 ]]; do
Copy link
Collaborator

@hyperupcall hyperupcall Nov 27, 2023

Choose a reason for hiding this comment

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

[nit] Moving big sections around like the argument parsing makes it more difficult to read the diff. Can the argument parsing be moved back to where it was - at the top of the file?

;;
--output )
if [[ -n $2 ]] && [[ $2 =~ ^(\.\/|\.\.\/|\/)?([a-zA-Z_](\/)?)+$ ]]; then
output=$2
Copy link
Collaborator

Choose a reason for hiding this comment

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

I notice the variables file and output behave and mean the same thing. Is it possible to be consistent and use the old, file variable instead of making a new one?

fi
fi

if [[ $# = 0 ]]; then
Copy link
Collaborator

Choose a reason for hiding this comment

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

There seems to be some duplication. There are two sections that have

authors >> "$somevariable"
exit 0

Can they be combined into one? If they share the same variable name, it should be relatively straightforward

@vanpipy
Copy link
Collaborator Author

vanpipy commented Sep 29, 2024

It is not the right time to do the refactor, do this again when the coverage is ok.

@vanpipy vanpipy closed this Sep 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor(git-authors): support the option --output and controlled --no-email
2 participants