Closed Bug 1507007 Opened 6 years ago Closed 6 years ago

Provide a script for local precommit hg/git hooks that run ./mach clang-format

Categories

(Developer Infrastructure :: Lint and Formatting, enhancement)

enhancement
Not set
normal

Tracking

(firefox66 fixed)

RESOLVED FIXED
Tracking Status
firefox66 --- fixed

People

(Reporter: ehsan.akhgari, Assigned: Sylvestre)

References

()

Details

Attachments

(1 file, 1 obsolete file)

I think I have something for that.

With my patch, I am producing the following output:

% hg commit --amend dom/ tools/
Running command: ['/usr/bin/python2.7', '/home/sylvestre/dev/mozilla/mozilla-central.hg/tools/lint/../../mach', 'clang-format', '-s']
--- dom/presentation/PresentationReceiver.cpp	(before formatting)
+++ dom/presentation/PresentationReceiver.cpp	(after formatting)
@@ -67,8 +67,7 @@
   return !mUrl.IsEmpty();
 }
 
-void PresentationReceiver::Shutdown(        )
-{
+void PresentationReceiver::Shutdown() {
   PRES_DEBUG("receiver shutdown:windowId[%" PRId64 "]\n", mWindowId);
 
   // Unregister listener for incoming sessions.

Running command: ['/usr/bin/python2.7', '/home/sylvestre/dev/mozilla/mozilla-central.hg/tools/lint/../../mach', 'lint', '--quiet', '--workdir=staged']
✖ 0 problems (0 errors, 0 warnings)
Assignee: nobody → sledru
As ride along, other changes:
1) Renamed run_mozlint =>run_linters
2) Show the command being executed (we have the mozlint output anyway)
3) Add a link to the doc on how to use it
Do the hg hooks work for mq patches?
Flags: needinfo?(sledru)
Andrew is the real expert here :)
Flags: needinfo?(sledru) → needinfo?(ahal)
I had to Google it, but looks like you can do stuff like:

[hooks]
pre-qrefresh.lint = hook.py

So I guess yes :). Though I'm also not sure how mq interacts with |mach lint|'s --workdir and --outgoing flags respectively (which is what the hooks call into). So further testing is needed to properly answer that.
Flags: needinfo?(ahal)
Also the hooks.py file looks for either "commit" or "push" in the hook name. So we'd have to teach it about 'qrefresh' (or whatever other mq commands we need).
Blocks: 1511904
Please make sure that this hook will not prevent win32 native python from landing commits. (See bug 1511594 for context.)
Attachment #9027313 - Attachment is obsolete: true
Depends on: 1514341
Pushed by sledru@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/e2b466629175
Add a clang-format hook r=ahal,Ehsan
https://hg.mozilla.org/mozilla-central/rev/e2b466629175
Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Depends on: 1514755
Here is how this can be configured:
----
[hooks]
pretxncommit.clang-format = python:./tools/lint/hooks_clang_format.py:hg
----
in .hg/hgrc
This doesn't work in git:

Traceback (most recent call last):
  File ".git/hooks/pre-commit", line 48, in <module>
    sys.exit(git())
  File ".git/hooks/pre-commit", line 44, in git
    return run_clang_format(hooktype, [])
TypeError: run_clang_format() takes exactly 3 arguments (2 given)


Also hooks_clang_format.py should be marked executable for best results.
Flags: needinfo?(sledru)
I didn't test this on git, let me fix that.
Flags: needinfo?(sledru)
Depends on: 1514770
Product: Firefox Build System → Developer Infrastructure
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: