如何获得钩子脚本post-commit中的项目路径?(git) [英] how to get project path in hook script post-commit?(git)

查看:449
本文介绍了如何获得钩子脚本post-commit中的项目路径?(git)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想调用位于存储库中的脚本。



我当然可以这样做:

 #!/ bin / sh 
../../myscript.sh

但我认为那不是很好;)



所以我怎么在post-commit脚本中得到我的项目的路径?

解决方案

在处理非裸仓库时,运行提交后 1 钩子与存储库工作树的当前工作目录。因此,您不需要 ../../



如果您想要完整路径脚本,你总是可以这样做:

  SCRIPT = $(readlink -nf myscript.sh)

...或者您可以使用 git rev-parse --show-toplevel 获得工作目录的绝对路径:

  SCRIPT = $(git rev-parse --show-toplevel)/ myscript.sh 

1 ...但请注意,这不是真的一些其他的钩子,例如在非裸仓库的 post-receive 钩子中,当前工作目录是 .git 目录。 / p>

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?

解决方案

When you're dealing with a non-bare repository, the post-commit1 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:

SCRIPT=$(readlink -nf myscript.sh)

... or you could use git rev-parse --show-toplevel to get an absolute path to the working directory:

SCRIPT=$(git rev-parse --show-toplevel)/myscript.sh

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.

这篇关于如何获得钩子脚本post-commit中的项目路径?(git)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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