<html><head><meta http-equiv="content-type" content="text/html; charset=us-ascii"></head><body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div><br></div>  Urgg, precommit does not appear to play well with git gui. I am getting git gui hanging on call pre-commit hook<div><br><div><br><blockquote type="cite"><div>On Jun 19, 2023, at 9:17 AM, Barry Smith <bsmith@petsc.dev> wrote:</div><br class="Apple-interchange-newline"><div><meta http-equiv="content-type" content="text/html; charset=us-ascii"><div style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div><br></div>  I just found out my script was woefully incomplete. It is probably still wrong even with this change but needs<div><br></div><div><div>current_source=$(git diff --staged --name-only | egrep "(\.[chF]'|\.F90|\.hpp|\.cpp|\.cxx|\.cu)" | tr '\n' ' ')</div></div><div><br></div><div><br></div><div><br></div><div><br><div><br><blockquote type="cite"><div>On Jun 18, 2023, at 7:51 PM, Barry Smith <bsmith@petsc.dev> wrote:</div><br class="Apple-interchange-newline"><div><meta http-equiv="content-type" content="text/html; charset=us-ascii"><div style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div><br></div><div>  Jacobi,</div><div><br></div>  Thanks for the reminder about using hooks for this purpose. Perhaps git hooks are not understood well enough at the time by the masses (that is, me), or perhaps hooks were presented as THE solution, not as a tool for helping users to get to the solution?  That is, git-hooks as a way to enforce rules on the pushed code versus git hooks used by individuals to make their workflow easier or less bug-prone?<div><br></div><div>  I found your <a href="https://gitlab.com/petsc/petsc/-/merge_requests/4063">https://gitlab.com/petsc/petsc/-/merge_requests/4063</a> but couldn't find any discussion of pre-commits for clang-format in my mail searches.</div><div><br></div><div>   I discovered a .git/hooks/pre-commit~ which presumably you sent around (listed at the bottom of this email).  It seems to work as advertised, warns me, and prevents my commit of badly formatted code. </div><div><br></div><div>   I modified it to </div><div><br></div><div><div>/bin/bash</div><div><br></div><div>current_source=$(git diff --staged --name-only)</div><div>badsource=$(make -e GITSRC="${current_source}" checkbadSource 2>&1)</div><div><br></div><div>if [ "$badsource" != "" ]</div><div>then</div><div>    echo "git commit aborted due to violations of basic source code formatting"</div><div>    make -e GITSRC="${current_source}" checkbadSource</div><div>    exit 1</div><div>fi</div><div><br></div><div>clangformatout=$(git clang-format --diff --staged -q)</div><div><br></div><div>if [ "$clangformatout" != "" ]</div><div>then</div><div>    echo "git commit aborted. Use 'git add -u ; git clang-format --staged' to fix source code formatting"</div><div>    exit 1</div><div>fi</div></div><div><br></div><div>and it seems to suit my needs.</div><div><br></div><div>Thanks again for the suggestion</div><div><br></div><div><span style="font-family: Menlo; font-size: 14px;">/bin/bash</span></div><div><div style="margin: 0px; font-style: normal; font-variant-caps: normal; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; font-size-adjust: none; font-kerning: auto; font-variant-alternates: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-position: normal; font-feature-settings: normal; font-optical-sizing: auto; font-variation-settings: normal; min-height: 16px;"><span style="font-variant-ligatures: no-common-ligatures">  </span><br class="webkit-block-placeholder"></div><div style="margin: 0px; font-style: normal; font-variant-caps: normal; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; font-size-adjust: none; font-kerning: auto; font-variant-alternates: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-position: normal; font-feature-settings: normal; font-optical-sizing: auto; font-variation-settings: normal;"><span style="font-variant-ligatures: no-common-ligatures">if git rev-parse --verify HEAD >/dev/null 2>&1  </span></div><div style="margin: 0px; font-style: normal; font-variant-caps: normal; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; font-size-adjust: none; font-kerning: auto; font-variant-alternates: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-position: normal; font-feature-settings: normal; font-optical-sizing: auto; font-variation-settings: normal;"><span style="font-variant-ligatures: no-common-ligatures">then  </span></div><div style="margin: 0px; font-style: normal; font-variant-caps: normal; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; font-size-adjust: none; font-kerning: auto; font-variant-alternates: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-position: normal; font-feature-settings: normal; font-optical-sizing: auto; font-variation-settings: normal;"><span style="font-variant-ligatures: no-common-ligatures">against=HEAD  </span></div><div style="margin: 0px; font-style: normal; font-variant-caps: normal; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; font-size-adjust: none; font-kerning: auto; font-variant-alternates: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-position: normal; font-feature-settings: normal; font-optical-sizing: auto; font-variation-settings: normal;"><span style="font-variant-ligatures: no-common-ligatures">else  </span></div><div style="margin: 0px; font-style: normal; font-variant-caps: normal; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; font-size-adjust: none; font-kerning: auto; font-variant-alternates: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-position: normal; font-feature-settings: normal; font-optical-sizing: auto; font-variation-settings: normal;"><span style="font-variant-ligatures: no-common-ligatures"># Initial commit: diff against an empty tree object  </span></div><div style="margin: 0px; font-style: normal; font-variant-caps: normal; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; font-size-adjust: none; font-kerning: auto; font-variant-alternates: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-position: normal; font-feature-settings: normal; font-optical-sizing: auto; font-variation-settings: normal;"><span style="font-variant-ligatures: no-common-ligatures">against=4b825dc642cb6eb9a060e54bf8d69288fbee4904  </span></div><div style="margin: 0px; font-style: normal; font-variant-caps: normal; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; font-size-adjust: none; font-kerning: auto; font-variant-alternates: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-position: normal; font-feature-settings: normal; font-optical-sizing: auto; font-variation-settings: normal;"><span style="font-variant-ligatures: no-common-ligatures">fi  </span></div><div style="margin: 0px; font-style: normal; font-variant-caps: normal; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; font-size-adjust: none; font-kerning: auto; font-variant-alternates: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-position: normal; font-feature-settings: normal; font-optical-sizing: auto; font-variation-settings: normal; min-height: 16px;"><span style="font-variant-ligatures: no-common-ligatures">  </span><br class="webkit-block-placeholder"></div><div style="margin: 0px; font-style: normal; font-variant-caps: normal; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; font-size-adjust: none; font-kerning: auto; font-variant-alternates: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-position: normal; font-feature-settings: normal; font-optical-sizing: auto; font-variation-settings: normal;"><span style="font-variant-ligatures: no-common-ligatures"># Test clang-format  </span></div><div style="margin: 0px; font-style: normal; font-variant-caps: normal; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; font-size-adjust: none; font-kerning: auto; font-variant-alternates: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-position: normal; font-feature-settings: normal; font-optical-sizing: auto; font-variation-settings: normal;"><span style="font-variant-ligatures: no-common-ligatures">clangformatout=$(git clang-format --diff --staged -q)  </span></div><div style="margin: 0px; font-style: normal; font-variant-caps: normal; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; font-size-adjust: none; font-kerning: auto; font-variant-alternates: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-position: normal; font-feature-settings: normal; font-optical-sizing: auto; font-variation-settings: normal; min-height: 16px;"><span style="font-variant-ligatures: no-common-ligatures">  </span><br class="webkit-block-placeholder"></div><div style="margin: 0px; font-style: normal; font-variant-caps: normal; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; font-size-adjust: none; font-kerning: auto; font-variant-alternates: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-position: normal; font-feature-settings: normal; font-optical-sizing: auto; font-variation-settings: normal;"><span style="font-variant-ligatures: no-common-ligatures"># Redirect output to stderr.  </span></div><div style="margin: 0px; font-style: normal; font-variant-caps: normal; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; font-size-adjust: none; font-kerning: auto; font-variant-alternates: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-position: normal; font-feature-settings: normal; font-optical-sizing: auto; font-variation-settings: normal;"><span style="font-variant-ligatures: no-common-ligatures">exec 1>&2  </span></div><div style="margin: 0px; font-style: normal; font-variant-caps: normal; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; font-size-adjust: none; font-kerning: auto; font-variant-alternates: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-position: normal; font-feature-settings: normal; font-optical-sizing: auto; font-variation-settings: normal; min-height: 16px;"><span style="font-variant-ligatures: no-common-ligatures">  </span><br class="webkit-block-placeholder"></div><div style="margin: 0px; font-style: normal; font-variant-caps: normal; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; font-size-adjust: none; font-kerning: auto; font-variant-alternates: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-position: normal; font-feature-settings: normal; font-optical-sizing: auto; font-variation-settings: normal;"><span style="font-variant-ligatures: no-common-ligatures">if [ "$clangformatout" != "" ]  </span></div><div style="margin: 0px; font-style: normal; font-variant-caps: normal; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; font-size-adjust: none; font-kerning: auto; font-variant-alternates: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-position: normal; font-feature-settings: normal; font-optical-sizing: auto; font-variation-settings: normal;"><span style="font-variant-ligatures: no-common-ligatures">then</span></div><div style="margin: 0px; font-style: normal; font-variant-caps: normal; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; font-size-adjust: none; font-kerning: auto; font-variant-alternates: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-position: normal; font-feature-settings: normal; font-optical-sizing: auto; font-variation-settings: normal;"><span style="font-variant-ligatures: no-common-ligatures">    echo "Format error!"</span></div><div style="margin: 0px; font-style: normal; font-variant-caps: normal; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; font-size-adjust: none; font-kerning: auto; font-variant-alternates: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-position: normal; font-feature-settings: normal; font-optical-sizing: auto; font-variation-settings: normal;"><span style="font-variant-ligatures: no-common-ligatures">    echo "Use git clang-format"</span></div><div style="margin: 0px; font-style: normal; font-variant-caps: normal; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; font-size-adjust: none; font-kerning: auto; font-variant-alternates: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-position: normal; font-feature-settings: normal; font-optical-sizing: auto; font-variation-settings: normal;"><span style="font-variant-ligatures: no-common-ligatures">    exit 1</span></div><div style="margin: 0px; font-style: normal; font-variant-caps: normal; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; font-size-adjust: none; font-kerning: auto; font-variant-alternates: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-position: normal; font-feature-settings: normal; font-optical-sizing: auto; font-variation-settings: normal;"><span style="font-variant-ligatures: no-common-ligatures">fi</span></div></div><div><span style="font-variant-ligatures: no-common-ligatures"><br></span></div><div><br></div><div><div><div><blockquote type="cite"><div>On Jun 18, 2023, at 4:37 PM, Jacob Faibussowitsch <jacob.fai@gmail.com> wrote:</div><br class="Apple-interchange-newline"><div><div><blockquote type="cite">I want to automatically run make checkclangformat checkbadSource before every git push (because I am an idiot and have too many silly failed CIs due to bad source). <br></blockquote><br>What you *actually* want are git hooks (https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks) combined with clang-format-diff (https://clang.llvm.org/docs/ClangFormat.html#script-for-patch-reformatting).<br><br>I floated the idea of adding git hooks ages ago, but it was shot down for some reason.<br><br>Best regards,<br><br>Jacob Faibussowitsch<br>(Jacob Fai - booss - oh - vitch)<br><br><blockquote type="cite">On Jun 18, 2023, at 16:33, Barry Smith <bsmith@petsc.dev> wrote:<br><br><br> I have never understood how to do make rule dependencies when one is not explicitly generating new files from old ones. For example, .o from .c<br><br>I want to automatically run make checkclangformat checkbadSource before every git push (because I am an idiot and have too many silly failed CIs due to bad source). <br><br>Currently, we use git ls-files and check every single file each time, even though I have not changed all 5,000 source files in PETSc before a push.<br>Is there someone who understands make dependencies when no files are generated who could reduce make checkclangformat and checkbadSource to under a second?<br><br><br> Thanks<br><br> Barry<br><br></blockquote><br></div></div></blockquote></div><br></div></div></div></div></blockquote></div><br></div></div></div></blockquote></div><br></div></body></html>