[libcamera-devel,v2,6/6] checkstyle: Add a pre-commit hook script

Message ID 20200117191733.198897-7-nicolas@ndufresne.ca
State Superseded
Headers show
Series
  • Add the ability to do pre-commit style check
Related show

Commit Message

Nicolas Dufresne Jan. 17, 2020, 7:17 p.m. UTC
From: Nicolas Dufresne <nicolas.dufresne@collabora.com>

This adds support for pre-commit hook workflow. In pre-commit hook we
check the style on the changes currently staged or the combination
of the index and the last commit if "git commit --amend" is being used.

Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
---
 utils/hooks/pre-commit | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
 create mode 100755 utils/hooks/pre-commit

Comments

Laurent Pinchart Jan. 17, 2020, 10:20 p.m. UTC | #1
Hi Nicolas,

Thank you for the patch.

On Fri, Jan 17, 2020 at 02:17:33PM -0500, Nicolas Dufresne wrote:
> From: Nicolas Dufresne <nicolas.dufresne@collabora.com>
> 
> This adds support for pre-commit hook workflow. In pre-commit hook we
> check the style on the changes currently staged or the combination
> of the index and the last commit if "git commit --amend" is being used.
> 
> Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
> ---
>  utils/hooks/pre-commit | 17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
>  create mode 100755 utils/hooks/pre-commit
> 
> diff --git a/utils/hooks/pre-commit b/utils/hooks/pre-commit
> new file mode 100755
> index 0000000..be2f8b3
> --- /dev/null
> +++ b/utils/hooks/pre-commit
> @@ -0,0 +1,17 @@
> +#!/bin/sh
> +
> +# Execute the checkstyle script after committing any code. This allows the
> +# commit to succeed, but ensures that the developer is aware of any potential
> +# issues immediately, and can resolve them and fix rapidly with:
> +#   git commit --amend
> +#
> +# To utilise this hook, install this file with:
> +#   cp utils/hooks/post-commit .git/hooks/post-commit
> +
> +args="--staged"
> +if ps -ocommand= -p $PPID | grep -- "--amend"
> +then
> +   commit="--amend"

commit isn't used below... Did you mean args ? Seems more testing is
needed ;-)

> +fi
> +
> +./utils/checkstyle.py $args
Nicolas Dufresne Jan. 17, 2020, 10:59 p.m. UTC | #2
Le samedi 18 janvier 2020 à 00:20 +0200, Laurent Pinchart a écrit :
> Hi Nicolas,
> 
> Thank you for the patch.
> 
> On Fri, Jan 17, 2020 at 02:17:33PM -0500, Nicolas Dufresne wrote:
> > From: Nicolas Dufresne <nicolas.dufresne@collabora.com>
> > 
> > This adds support for pre-commit hook workflow. In pre-commit hook we
> > check the style on the changes currently staged or the combination
> > of the index and the last commit if "git commit --amend" is being used.
> > 
> > Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
> > ---
> >  utils/hooks/pre-commit | 17 +++++++++++++++++
> >  1 file changed, 17 insertions(+)
> >  create mode 100755 utils/hooks/pre-commit
> > 
> > diff --git a/utils/hooks/pre-commit b/utils/hooks/pre-commit
> > new file mode 100755
> > index 0000000..be2f8b3
> > --- /dev/null
> > +++ b/utils/hooks/pre-commit
> > @@ -0,0 +1,17 @@
> > +#!/bin/sh
> > +
> > +# Execute the checkstyle script after committing any code. This allows the
> > +# commit to succeed, but ensures that the developer is aware of any
> > potential
> > +# issues immediately, and can resolve them and fix rapidly with:
> > +#   git commit --amend
> > +#
> > +# To utilise this hook, install this file with:
> > +#   cp utils/hooks/post-commit .git/hooks/post-commit
> > +
> > +args="--staged"
> > +if ps -ocommand= -p $PPID | grep -- "--amend"
> > +then
> > +   commit="--amend"
> 
> commit isn't used below... Did you mean args ? Seems more testing is
> needed ;-)

That one I didn't have locally, fixing.

> 
> > +fi
> > +
> > +./utils/checkstyle.py $args

Patch

diff --git a/utils/hooks/pre-commit b/utils/hooks/pre-commit
new file mode 100755
index 0000000..be2f8b3
--- /dev/null
+++ b/utils/hooks/pre-commit
@@ -0,0 +1,17 @@ 
+#!/bin/sh
+
+# Execute the checkstyle script after committing any code. This allows the
+# commit to succeed, but ensures that the developer is aware of any potential
+# issues immediately, and can resolve them and fix rapidly with:
+#   git commit --amend
+#
+# To utilise this hook, install this file with:
+#   cp utils/hooks/post-commit .git/hooks/post-commit
+
+args="--staged"
+if ps -ocommand= -p $PPID | grep -- "--amend"
+then
+   commit="--amend"
+fi
+
+./utils/checkstyle.py $args