Skip to content

add ability to pass arbitrary git log arguments #3331

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

Closed
2 tasks done
morriswinkler opened this issue Aug 23, 2022 · 7 comments · Fixed by #3334
Closed
2 tasks done

add ability to pass arbitrary git log arguments #3331

morriswinkler opened this issue Aug 23, 2022 · 7 comments · Fixed by #3334

Comments

@morriswinkler
Copy link
Contributor

morriswinkler commented Aug 23, 2022

Issue

Currently it is impossible to add any additional parameters to git log when using commitlint cli parameter --from.

I am sure you are aware of the need to be able to modify the git log behaviour, there are many corner cases that can be tackled by adding additional arguments to git.

My specific case is based on merging unrelated history, in which case git log traverses through all the merged in dangling branches, which ends up in a lot of commits being validated.

To fix it I needed to add --first-parent to git log so it doesn't traverse into the merged history.

My current fix is to pass the commit messages one by one to commitlint via a for loop that exits on error.

for sha in $(git log --first-parent --format='%H' master..HEAD);do git log -1 --format='%B' $sha | npx commitlint || ! break; done

An alternative could be to allow a list of commits via the stdin, I guess you would have to add a delimiter option, similar how the
--from option splits messages into an array. As far as I can see you log with the option:

--format='%B%n------------------------ >8 ------------------------'

and split the messages by ------------------------ >8 ------------------------ since commit messages can't be split by new lines.

Affected packages

  • cli
  • core
Executable Version
commitlint --version @commitlint/[email protected]
git --version git version 2.36.1
node --version v16.16.0
@escapedcat
Copy link
Member

Thanks for opening this. Are you motivated to look into this? I.e. to find the root cause of this?

@morriswinkler
Copy link
Contributor Author

morriswinkler commented Aug 23, 2022

it is a feature request not a bug

the feature is:
add a command line switch to add additional git arguments when calling git log
see:

export default async function getCommitMessages(

return streamToPromise(gitRawCommits(options, {cwd: opts.cwd}));

@escapedcat
Copy link
Member

Wanna create a PR?

@morriswinkler
Copy link
Contributor Author

I pushed an PR,

adds git-log-args parameter.
example:

commitlint --from=master --git-log-args='--first-parent --skip 2' 

@escapedcat
Copy link
Member

Thanks for you PR! Merged it. Will try to push out a new release soon.

@escapedcat
Copy link
Member

Released, please give it a try

@morriswinkler
Copy link
Contributor Author

Gave it a try works very well thanks for that uncomplicated process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants