在Mercurial和Git中为JSLint预先提交钩子 [英] Pre Commit Hook for JSLint in Mercurial and Git

查看:174
本文介绍了在Mercurial和Git中为JSLint预先提交钩子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在提交Mercurial或Git仓库之前运行JSLint。

I want to run JSLint before a commit into either a Mercurial or Git repo is done.

我希望这是一个自动设置的步骤,而不是依赖对开发者(主要是我)记得在手之前运行JSLint。我通常在开发过程中运行JSLint,但是希望在JS文件上指定一个合同,以便在提交到repo之前通过JSLint。

I want this as an automatic step that is set up instead of relying on the developer (mainly me) remembering to run JSLint before-hand. I normally run JSLint while developing, but want to specify a contract on JS files that they pass JSLint before being committed to the repo.

对于Mercurial,这个页面说明了预先提交的语法,但似乎可用的唯一变量是提交中涉及的parent1和parent2变更集ID。我真正想要的是与提交有关的文件名列表,以便我可以选择.js文件并在其上运行jslint。

For Mercurial, this page spells out the precommit syntax, but the only variables that seem to be available are the parent1 and parent2 changeset IDs involved in the commit. What I really want are a list of file names that are involved with the commit, so that I can then choose the .js file and run jslint over them.

GIT的类似问题,作为预提交脚本一部分提供的默认信息似乎有限。

Similar issue for GIT, the default info available as part of the precommit script seems limited.

可能的工作是调用hg status / git status作为预提交脚本的一部分,解析输出以查找JS文件,然后以此方式完成工作。尽管我希望能够更容易,但我不确定是否将状态作为预提交钩子的一部分反映了正确的信息。例如在Git中,如果尚未添加更改文件,但git commit使用-a,那么这些文件是否会在git status输出的正确部分显示为提交集的一部分?

What might work is calling hg status/git status as part of the precommit script, parse that output to find JS files then do the work that way. I was hoping for something easier though, and I am not sure if calling status as part of a precommit hook reflect the correct information. For instance in Git if the changes files have not been added yet, but the git commit uses -a, would the files show up in the correct section of the git status output as being part of the commit set?

更新:我得到了一些工作,可以在这里看到: http://github.com/jrburke/dvcs_jslint/

Update: I got something working, it is visible here: http://github.com/jrburke/dvcs_jslint/

推荐答案

对于git, .git / hooks目录。如果您只需要JSLint的文件名,您可以使用 git diff --name-only ,在我的示例中它将列出与当前不同的文件名 HEAD

For git, there are examples in the .git/hooks directory. If you just need the file names for JSLint, you could use git diff --name-only, which in my example will list the names of the files that differ from the current HEAD.

这篇关于在Mercurial和Git中为JSLint预先提交钩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆