Analyzing projects before creating pull requests —10 November 2016
I’m not the best user of SonarLint (yet). For example, it’s not my habit yet to verify using SonarLint my changes before every commit. And sure enough, I tend to add new issues, which will end up in SonarQube later, and eventually I’ll have to fix them before the project can be released (must pass the Quality Gate).
So I came up with a crutch, or rather, a stick,
a Git pre-push hook to slap my wrists if I try to push something prematurely.
That is, before every
it would be great to analyze all the files I touched in my branch,
and prevent the push if there are issues.
The key pieces to this:
sonarlintcommand line tool
- The pre-push hook in
.git/hooksin the work tree
git diff --name-only origin/master... --diff-filter=AMcommand to get the list of changed files: file names added or modified since
origin/master. Notice the
origin/master, it’s important, to only include files by the new commits in the current branch.
Highly experimental, but in any case, the hook is on GitHub. The readme explains how to use it, and the many limitations.