git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [RFC] Add basic syntax check on shell scripts

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 5, 2012, 06:02 UTC
Message-ID
<7vobi9kpda.fsf@alter.siamese.dyndns.org>
In-Reply-To
<CACsJy8BtX9fMkGDoVGKzgz7SSinbt0561B1ZKHu6fs+n8ewKGg@mail.gmail.com>
Nguyen Thai Ngoc Duy <pclouds@gmail.com> writes:
Show 10 quoted lines
> On Wed, Dec 5, 2012 at 2:39 AM, Junio C Hamano <gitster@pobox.com> wrote:
>>> Or a project commit hook?
>>
>> Surely.  It is OK to have "cd t && make test-lint" in your
>> pre-commit hook.
>
> No, what I meant is a shared pre-commit script that all git devs are
> encouraged (or forced) to install so bugs are found locally rather
> than after patches are sent to you. The hook content does not really
> matter.

Honestly, I do not really care (yet); what you are talkng about is merely an addition to Documentation/SubmittingPatches, which is trivial.

The content of the hook is much more important.

If it has too many false positives, it is not worth even encouraging its use to less experienced ones, as they will have hard time to figure out which errors matter and which erros can be ignored. It will make contributing to the project harder, not easier.

As I do not think (1) we would be able to do a good job reducing false positives without writing a full POSIX shell parser, and (2) we would want to be in the business of writing POSIX shell parser [*1*], I am somewhat skeptical.

And if we cannot come up with a reliable hook in the first place, there isn't much point in discussing a policy to encourage such a hook, is it?

[Footnote]

*1* Is there a free one that is portable, perhaps written in either Perl or Python, to which we can easily plug our own logic? In order to catch basic errors, I think it is sufficient to tokenize the script into independent series of simple commands, even ignoring variable substitutions and evals, and just have a bunch of "we do not allow option X to command Y" rules (e.g. "no -i to sed", "the first argument must be 'git' for "test_must_fail").

Previous: Nguyen Thai Ngoc DuyNext: Jeff King
Message 7 of 11 in “[RFC] Add basic syntax check on shell scripts”
  1. Torsten BögershausenDec 2, 2012
  2. Stefano LattariniDec 2, 2012
  3. Junio C HamanoDec 3, 2012
  4. Nguyen Thai Ngoc DuyDec 4, 2012
  5. Junio C HamanoDec 4, 2012
  6. Nguyen Thai Ngoc DuyDec 5, 2012
  7. Junio C HamanoDec 5, 2012
  8. Jeff KingDec 5, 2012
  9. Jeff KingDec 5, 2012
  10. Junio C HamanoDec 5, 2012
  11. Sebastian SchuberthDec 5, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.