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

"No commits in range" should be an error #193

Closed
l0b0 opened this issue Jul 26, 2021 · 2 comments
Closed

"No commits in range" should be an error #193

l0b0 opened this issue Jul 26, 2021 · 2 comments
Labels
enhancement User-facing feature enhancements
Milestone

Comments

@l0b0
Copy link
Contributor

l0b0 commented Jul 26, 2021

First, thank you for this excellent tool!

GitLab CI pipelines for "ordinary" merge requests do not include a variable with the name of the target branch, which I only realised after running gitlint --commits "${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}..HEAD" --debug and seeing it print 'DEBUG: gitlint.cli No commits in range "..HEAD"'. I suspect this is a common mistake, and that it should by default be treated as an error. There should probably also be a flag to override this, in case someone is running gitlint against references which could legitimately refer to an empty commit range.

As a workaround I'm going to keep running this tool in debug mode for now.

I might have time (as part of work, where we use this tool extensively) to implement the change, but I first want to make sure you agree whether this is an issue and whether it should be solved in this or some other way.

The full output:

$ gitlint --commits "${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}..HEAD" --debug
DEBUG: gitlint.cli To report issues, please visit https://github.com/jorisroovers/gitlint/issues
DEBUG: gitlint.cli Platform: Linux-5.4.109+-x86_64-with-debian-10.10
DEBUG: gitlint.cli Python version: 3.7.3 (default, Jan 22 2021, 20:04:44) 
[GCC 8.3.0]
DEBUG: gitlint.git ('--version',)
DEBUG: gitlint.cli Git version: git version 2.20.1
DEBUG: gitlint.cli Gitlint version: 0.15.0
DEBUG: gitlint.cli GITLINT_USE_SH_LIB: [NOT SET]
DEBUG: gitlint.cli DEFAULT_ENCODING: UTF-8
DEBUG: gitlint.cli Configuration
config-path: /builds/victor-engmark/root/.gitlint
[GENERAL]
extra-path: None
contrib: ['contrib-title-conventional-commits']
ignore: body-is-missing
ignore-merge-commits: True
ignore-fixup-commits: True
ignore-squash-commits: True
ignore-revert-commits: True
ignore-stdin: False
staged: False
verbosity: 3
debug: True
target: /builds/victor-engmark/root
[RULES]
  I1: ignore-by-title
     ignore=all
     regex=None
  I2: ignore-by-body
     ignore=all
     regex=None
  I3: ignore-body-lines
     regex=None
  T1: title-max-length
     line-length=72
  T2: title-trailing-whitespace
  T6: title-leading-whitespace
  T3: title-trailing-punctuation
  T4: title-hard-tab
  T5: title-must-not-contain-word
     words=WIP
  T7: title-match-regex
     regex=None
  T8: title-min-length
     min-length=5
  B1: body-max-line-length
     line-length=80
  B5: body-min-length
     min-length=20
  B6: body-is-missing
     ignore-merge-commits=True
  B2: body-trailing-whitespace
  B3: body-hard-tab
  B4: body-first-line-empty
  B7: body-changed-file-mention
     files=
  B8: body-match-regex
     regex=None
  M1: author-valid-email
     regex=[^@ ]+@[^@ ]+\.[^@ ]+
  CT1: contrib-title-conventional-commits
     types=build,chore,ci,docs,feat,fix,perf,refactor,revert,style,test
DEBUG: gitlint.cli No --msg-filename flag, no or empty data passed to stdin. Using the local repo.
DEBUG: gitlint.git ('rev-list', '..HEAD')
DEBUG: gitlint.cli No commits in range "..HEAD"
@sigmavirus24
Copy link
Collaborator

Not the maintainer, but I could see that this would be helpful to have as an flag, e.g., --require-commits or --fail-without-commits. I'm not certain this should fail always. (Just trying to point out another path to your goal)

@jorisroovers
Copy link
Owner

I'm always hesitant to change default behavior, as it tends to break gitlint for others.
I like @sigmavirus24's suggestion to add a flag for this. My preference goes towards --fail-without-commits, as this allows for more such flags in the future that follow the same --fail-<condition> pattern.

Appreciate your help :-) Please do take a moment to read through the contributing docs before you start. Thanks!

@jorisroovers jorisroovers added the enhancement User-facing feature enhancements label Jul 26, 2021
@jorisroovers jorisroovers added this to the 0.15.2 milestone Sep 27, 2021
jorisroovers added a commit that referenced this issue Sep 27, 2021
This only introduces the feature flag in the lint config, the actual
functionally still needs to be implemented.
Relates to #193
jorisroovers added a commit that referenced this issue Sep 27, 2021
Not actually functional yet, this commit only introduces the CLI flag.

Relates to #193
jorisroovers added a commit that referenced this issue Sep 27, 2021
Gitlint will now hard fail when passing an empty commit range via
--commits and specifying the --fail-without-commits option.

Fixes #193
jorisroovers added a commit that referenced this issue Sep 27, 2021
This only introduces the feature flag in the lint config, the actual
functionally still needs to be implemented.
Relates to #193
jorisroovers added a commit that referenced this issue Sep 27, 2021
Not actually functional yet, this commit only introduces the CLI flag.

Relates to #193
@jorisroovers jorisroovers modified the milestones: 0.15.2, 0.16.0 Sep 27, 2021
jorisroovers added a commit that referenced this issue Oct 8, 2021
- Python 3.10 support
- New Rule: ignore-by-author-name allows users to skip linting commit messages
  made by specific authors
- --commit <SHA> flag to more easily lint a single commit message (#141)
- --fail-without-commits flag will force gitlint to fail (exit code 253) when
  the target commit range is empty (typically when using --commits) (#193)
- Bugfixes:
  - contrib-title-conventional-commits (CT1) now properly enforces the commit
    type (#185)
  - contrib-title-conventional-commits (CT1) now supports the BREAKING CHANGE
    symbol "!" (#186)
- Under-the-hood: dependencies updated, test and github action improvements.

Full Release details in CHANGELOG.md.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement User-facing feature enhancements
Projects
None yet
Development

No branches or pull requests

3 participants