Question

Our company is divided in teams and we perform code reviews before sending our code to the QA guys.

Usually, any code we touch is reviewed by someone inside the same team (A), but in some cases we also need to touch code from another team (B).

For those cases, the code review should be two-fold: one part reviewed by team A, and another part reviewed by team B.

Our problem is that many times the team A does not send the code to be reviewed by team B and this causes team B to be ignorant of this new code.

What I'd like to do is to periodically run a script to find commits inside certain parts of the code (usually subdirectories with modules our team handles) made by any person not belonging to our team, but unfortunately the --not argument in git log does not seem to work with --author so I cannot happily run git log --not --author "John" --author "Paul" --author "Ringo" module/A module/B module/C

My requirement translates to something like "list all commits touching module/A, module/B or module/C done by someone that's not John, Paul or Ringo"

Is there any way to do this using "official" tools? I would be interested in an open-source script too if it means doing this results in a one-liner or close to that.

Was it helpful?

Solution

EDIT: This should show commits with author names that do not contain "John" "Paul" or "Ringo". Requires git to be built with PCRE.

git log --perl-regexp --author='^(?!(.*(John|Paul|Ringo)))'

I'll leave previous variants below as they still may be of some use:


You should be able to do it using negative look-behind assertion, if your git is compiled with PCRE support. Something like this should do what you want:

git log --perl-regexp --author='(?<!(john|paul|ringo))@'

Note that the regex is actually looking for @ not preceded by john|paul|ringo. Getting this to work with names will be tricker as there may not be a convenient way to find an 'anchor' that's not preceded by the name you want to exclude.

You can try anchoring off beginning of the author line and show only commits that do not start with John|Paul|Ringo (i.e commits with John as the middle name would still be shown):

git log --perl-regexp --author='^(?!(John|Paul|Ringo))'

OTHER TIPS

Though this question has been answered 7 years ago, it's worth sharing another solution, that became feasible roughly a year later (with git 2.4, in 2015).

As mentioned in the answer to a similar question and the answer to a slightly different problem still involving regexes, it is possible to invert a regex pattern by specifying --invert-grep.

So, to address the specific situation you mention, you'll need to run:

git log --perl-regexp --invert-grep --author='(John|Paul|Ringo)'

The solution by @ArtemB is of course still valid. The only benefit I can see in this solution is increased readability (by ditching the ?! construct).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top