question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

gitlint is showing all files as changed in github CI

See original GitHub issue

Gitlint is incorrectly listing all files as changed in CI, not only those that have changed: https://github.com/jorisroovers/gitlint/actions/runs/3014300199/jobs/4935936697#step:14:104

Is this perhaps due to a misuse of refspec? Should we be passing a -1 argument like we do with log?

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
jorisrooverscommented, Nov 25, 2022

I realize I didn’t mention earlier that there’s really 2 parts to this.

Initial Commits and the git diff-tree --root flag

An important detail worth repeating is that git itself doesn’t consider files of the initial commit as “changed files” when you do git diff-tree, i.e. for the initial commit, git won’t show you the added files unless you specifically tell it to with the --root flag.

I had added the --root flag to the git diff-tree command that gitlint calls to deal with this, but hadn’t consider the shallow clone scenario.

Since I’ve now discovered that it’s not possible for gitlint to (easily + accurately) determine whether a commit is root commit, I believe gitlint should align with git’s behavior and not show files for initial/root commits unless you explicitly tell it to, with a config option like:

[general]
# consider files of root/initial commits as changed files
# (option name subject to change) 
diff-tree-root=False # disabled by default

You don’t actually have to use a .gitlint file for this, rather you can use the -c commandline flag to specify the same: gitlint -c general.diff-tree-root=True. Gitlint will still read the .gitlint file, but apply this config on top.

By using this construct, you can have an if/else statement in CI that deals with the initial commit separately if you really want it to. I think most users won’t actually care for the initial commit. We could documenting and/or provide templates on how to do this in various CI systems.

Fetch depth

However, this diff-tree-root option still doesn’t correctly solve the fetch-depth=1 challenge in CI, it just provides and all-or-nothing alternative to it. Setting diff-tree-root=True will end up showing all files, setting diff-tree-root=False will show none if fetch-depth is only 1.

The only way to resolve this AFAICT, is to increase the fetch-depth, which is CI specific. I don’t want to include CI specific customizations in gitlint itself, but perhaps we can also make this better using documentation and/or templates.

To reproduce this locally:

# Fetch depth of 1
$ git clone --depth 1 https://github.com/jorisroovers/gitlint.git /tmp/gitlint
$ cd /tmp/gitlint
$ git diff-tree --no-commit-id --numstat -r 01f2fa0
# No output :(
$ git diff-tree --no-commit-id --numstat -r --root 01f2fa0
# All files are listed :(
$ rm -rf /tmp/gitlint

# Fetch depth to 2(or more): fixes this issue
# Whether you use --root or not, only matters for the initial commit (not shown here)
$ git clone --depth 2 https://github.com/jorisroovers/gitlint.git /tmp/gitlint
$ cd /tmp/gitlint
$ git diff-tree --no-commit-id --numstat -r 01f2fa0
1	1	gitlint-core/setup.py
$ git diff-tree --no-commit-id --numstat -r --root 01f2fa0
1	1	gitlint-core/setup.py
$ rm -rf /tmp/gitlint
0reactions
chbndrhnnscommented, Nov 21, 2022

So there are some bits that won’t work w/o certain pre-setup.

I get that now thanks to your explanation, so thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issues · jorisroovers/gitlint - GitHub
Linting for your git commit messages. Contribute to jorisroovers/gitlint development by creating an account on GitHub.
Read more >
Git status shows files as changed even though contents are ...
I have resolved this problem using following steps. Remove every file from Git's index. git rm --cached -r . Rewrite the Git index...
Read more >
Configuration - Gitlint - Joris Roovers
Configuration. Gitlint can be configured through different means. The .gitlint file. You can modify gitlint's behavior by adding a .gitlint file to your...
Read more >
File: README — Documentation for git-lint (2.1.0)
cd example git checkout -b test touch text.txt git add --all . git commit ... As shown above, the --commit-message option accepts a...
Read more >
Supported hooks - pre-commit
php-lint-all - Check PHP Syntax on ALL PHP staged files with user friendly ... gitlint - Checks your git commit messages for style....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found