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.

Merge commit not ignored

See original GitHub issue

Trying to integrate this into github actions to run this on pull requests but it fails to recognize the merge commit for some reason. is-merge-commit is false even though the commit message looks like a merge commit, I’ve tried to reproduce this locally but there it seems to work fine.

DEBUG: gitlint.cli To report issues, please visit https://github.com/jorisroovers/gitlint/issues
DEBUG: gitlint.cli Platform: Linux-5.3.0-1020-azure-x86_64-with-glibc2.2.5
DEBUG: gitlint.cli Python version: 3.8.3 (default, May 14 2020, 09:47:01) 
[GCC 7.5.0]
DEBUG: gitlint.cli Git version: git version 2.26.2
DEBUG: gitlint.cli Gitlint version: 0.13.1
DEBUG: gitlint.cli GITLINT_USE_SH_LIB: [NOT SET]
DEBUG: gitlint.cli Configuration
config-path: /home/runner/work/pyavanza/pyavanza/.gitlint
[GENERAL]
extra-path: None
contrib: []
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: /home/runner/work/pyavanza/pyavanza
[RULES]
  I1: ignore-by-title
     ignore=all
     regex=None
  I2: ignore-by-body
     ignore=all
     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=.*
  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=
  M1: author-valid-email
     regex=[^@ ]+@[^@ ]+\.[^@ ]+

DEBUG: gitlint.cli No --msg-filename flag, no or empty data passed to stdin. Using the local repo.
DEBUG: gitlint.cli Linting 1 commit(s)
DEBUG: gitlint.lint Linting commit abbedb4a8419a093b4891abf3a44d035d59bcf41
DEBUG: gitlint.lint Commit Object
--- Commit Message ----
Merge 779ea24323a9bc150d4590d22b2593ce0c79cd00 into 72d49cd4ec6171670b305b27c765ea532961a8d2

--- Meta info ---------
Author: Claes Hallström <hallstrom.claes@gmail.com>
Date:   2020-05-20 21:56:24 +0000
is-merge-commit:  False
is-fixup-commit:  False
is-squash-commit: False
is-revert-commit: False
Branches: ['(HEAD detached at pull/18/merge)']
Changed Files: ['.coveragerc', '.flake8', '.github/workflows/build.yaml', '.github/workflows/lint.yaml', '.github/workflows/tag.yaml', '.github/workflows/test.yaml', '.gitignore', '.gitlint', '.isort.cfg', 'LICENSE', 'README.md', 'mypy.ini', 'pyavanza/__init__.py', 'pyavanza/py.typed', 'setup.py', 'tests/__init__.py', 'tests/test_async_stock.py', 'tests/test_stock.py']
-----------------------
1: T1 Title exceeds max length (92>72): "Merge 779ea24323a9bc150d4590d22b2593ce0c79cd00 into 72d49cd4ec6171670b305b27c765ea532961a8d2"
DEBUG: gitlint.cli Exit Code = 1
##[error]Process completed with exit code 1.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
coderbyheartcommented, May 26, 2020
2reactions
jorisrooverscommented, May 22, 2020

So the way gitlint determines whether a commit is a merge commit (by default) is by looking at the number of parent commits, see SO for a bit more context: https://stackoverflow.com/questions/3824050/telling-if-a-git-commit-is-a-merge-revert-commit

This is because the commit title of a merge commit can easily be changed to remove the word “Merge”, i.e. you can’t “trust” the commit title to tell you whether a commit is a merge commit or not.

So my guess is that in your particular case, the commit doesn’t have more than 1 parent commit.

You can check whether this is the case for you by using --pretty=%P (=list parent commit SHAs).

# Example on gitlint codebase
git show b6b32b9 --pretty=%P
0427de5b532b3ee05a966209c375886592f9b871 2eb18f1bd5cf819c9dcf63a69c819346f254b96d

However, since gitlint doesn’t always operate on a git repo directly (e.g. you can tell it to lint stdin input or specific file using --msg-filename), it will actually fallback on checking for “Merge” in the title as an imperfect work-around that’s correct in the vast majority of cases.

So perhaps you can pipe your commit message to gitlint instead of having gitlint retrieve the message itself to trigger this fallback, like so:

# Specific commit
git show b6b32b9 --pretty=%B | gitlint --debug

#  Same using git log
git log -1 b6b32b9 --pretty=%B | gitlint --debug

# Lint last commit
git log -1 --pretty=%B | gitlint --debug

Hope that helps!

Read more comments on GitHub >

github_iconTop Results From Across the Web

git - skipping specific commits when merging - Stack Overflow
If you have conflicts envolving NOT ONLY the "to-ignore" commits, you should resolve them manually, and you'll probably have to resolve them ...
Read more >
git-merge Documentation - Git
With --no-commit perform the merge and stop just before creating a merge commit, to give the user a chance to inspect and further...
Read more >
ignoring an upstream commit permanently - Gitolite
“gitk –merge” tells you that commit V is “guilty” and is just a variation of, let's say, B (doesn't matter), that differs enough...
Read more >
git-merge - Join two or more development histories together
Thus, if you want to ensure your branch is not changed or updated by the merge command, use --no-ff with --no-commit. --edit, -e,...
Read more >
Git merge strategy options & examples | Atlassian Git Tutorial
Once Git finds a common base commit it will create a new "merge commit" that combines the changes of the specified merge commits....
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