如何在提交后的钩子脚本中获取项目路径?(git)
我想调用位于存储库中的脚本。
我当然可以执行以下操作:
#!/bin/sh
../../myscript.sh
但我认为这不太好;)
那么如何在提交后脚本中获取项目的路径呢?
I want to call a Script that is located in the repository.
I could of course do the following:
#!/bin/sh
../../myscript.sh
but I think thats not nice ;)
so how do I get the path of my project within the post-commit script?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您处理非裸存储库时,
post-commit
1 挂钩将使用存储库工作树的当前工作目录运行。因此,您不需要../../
。如果您想要脚本的完整路径,您可以随时执行以下操作:
... 或者您可以使用 git rev-parse --show-toplevel 来获取工作目录的绝对路径:
1 ...但请注意,其他一些钩子并非如此,例如在非裸存储库中的
post-receive
钩子中,当前工作目录是.git
目录。When you're dealing with a non-bare repository, the
post-commit
1 hook is run with a current working directory of the working tree of the repository. So, you don't need the../../
.If you want the full path of the script, you could always do:
... or you could use
git rev-parse --show-toplevel
to get an absolute path to the working directory:1 ... but note that this is not true of some other hooks, e.g. in a
post-receive
hook in a non-bare repository, the current working directory is the.git
directory.这仍然有效吗?
我的
提交后
包含并有效。
仅使用
exec myscript.sh
或myscript.sh
不起作用。此外,如果要求输入密码,即使 myscript.sh 也会返回 /.git/hooks 文件夹。
使用 $GIT_WORK_TREE 指向 ~.我目前没有看到任何指向存储库根的可靠方法。
Is this still vaild?
my
post-commit
containsand works.
Using just
exec myscript.sh
ormyscript.sh
doesn't work.Moreover, even myscript.sh returns the /.git/hooks folder if asked for pwd.
Using $GIT_WORK_TREE points to ~. I currently see no robust way pointing to the repo root.