有没有全功能跨平台 shebang 线的破解方法?

发布于 2024-08-22 23:32:27 字数 310 浏览 6 评论 0原文

问题:显然 .git/hooks 目录中的脚本取决于与以下之一匹配的文件名:

post-commit
pre-commit
pre-rebase

等等...

不需要“文件扩展名”的概念,因为“shebang line”指示文件的方式应该运行,只要它是可执行的并且在你的 Linux 机器上运行。

问题是当您有一些脚本想要在 Windows 机器上运行时。

问题:有没有办法执行 Windows 机器上可以理解的钩子脚本?

Problem: apparently the scripts in the .git/hooks directory depend on the filename matching one of:

post-commit
pre-commit
pre-rebase

etc ...

No concept of "file extension" is required because the "shebang line" indicates how the file should run, as long as it is executable and running on your Linux box.

The problem is when you have some scripts that you want to run on a Windows box.

Question: Is there a way to execute the hook scripts that can be understood on a Windows machine?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

意中人 2024-08-29 23:32:27

我知道我在这方面落后了很多,但我有一个解决方案给你。如果您使用的是 python,请将“.py”添加到 PATHEXT 环境变量(控制面板、系统、高级、环境变量)。对于您的特定脚本语言也是如此。然后将钩子命名为post-commit.py、pre-commit.py等。当程序要求Windows执行某个目录中的“post-commit”文件时,Windows会按顺序查找PATHEXT,直到找到匹配的文件“post-commit.extension”,然后它将执行。我很久以前在 Windows 上使用 svn hooks 做过这个。

I know I'm way behind on this, but I have a solution for you. If you're using python, add ".py" to the PATHEXT environment variable (Control Panel, System, Advanced, Environment Variables). Likewise for your specific scripting language. Then name the hooks post-commit.py, pre-commit.py, etc. When a program asks Windows to execute the "post-commit" file in a certain directory, Windows will look through PATHEXT in order until it finds a file matching "post-commit.extension", which it will then execute. I did this a long time ago with svn hooks on Windows.

天涯沦落人 2024-08-29 23:32:27

我不认为Windows有执行无扩展名文件的概念。解决方法是 1) 在 bash 下使用 Cygwin git,整个 shebang 业务都在其中工作,或者 2) Windows git 版本中的 hack,它实际上解析 shebang 行本身并加载适当的解释器。我可以看到对后者的各种哲学反对意见,所以我猜这不会发生......

I don't think Windows has the concept of executing extension-less files. Workarounds would be to 1) use Cygwin git under bash, where the whole shebang business works or 2) a hack in the Windows git version that actually parses the shebang lines itself and loads the appropriate interpreter. I can see all sorts of philosophical objections to the latter, so I would guess that's not going to happen...

决绝 2024-08-29 23:32:27

我实际上选择了选项 3):

创建一个 Windows“包装器”脚本,该脚本调用 git 并调用我想要运行的任何关联的钩子。缺点是我必须配置包装程序来执行 git 会自动执行的操作(如果我只能使用标准挂钩文件)。

I actually settled for option 3):

Create a Windows "wrapper" script that invokes git and invokes any associated hooks that I want to run. The downside is I have to configure the wrapper program to do what git would have done automatically if only I could just use the standard hook files.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文