Skip to content

Silent false success when git is not present #2136

Open
@thesmiley1

Description

@thesmiley1

When git cannot be found in PATH and the user runs commitlint with parameters to read from the git log, commitlint exits with status 0 and no output.

Expected Behavior

When git is needed and cannot be found, commitlint should exit with a non-zero status and print an error.

Current Behavior

When git cannot be found in PATH, commitlint exits with status 0 and no output.

Affected packages

  • cli
  • core
  • prompt
  • config-angular

Possible Solution

Checking the exit status of git would be a good idea. That takes place in git-raw-commits; I will open a PR there soon.

Steps to Reproduce (for bugs)

  1. Go to repo
    cd /path/to/repo
  2. Add a commit with a bad message
    touch foo && git add foo && git commit --no-verify -m 'Bad Commit Msg'
  3. Remove git from PATH somehow, e.g.
    sudo mv /usr/bin/git /usr/bin/git.bak
  4. Run commitlint; note zero exit status and no output
    commitlint --from HEAD~1
  5. Don't forget to put git back if needed, e.g.
    sudo mv /usr/bin/git.bak /usr/bin/git

Context

The reproduction steps above may make this seem like a convoluted edge case, but it is not too difficult to run into.

I encountered this bug when setting up CI jobs to run in an alpine linux container. The repository is made available to the container via a bind mount and git is not installed by default. I didn't realize at first that git was missing and was confused by commitlint succeeding when it should not.

Another way a dev could be affected by this is if git is uninstalled for some reason (accidental, troubleshooting, etc).

Your Environment

Executable Version
commitlint --version @commitlint/[email protected]
git --version git version 2.28.0
node --version v14.11.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions