how to get project path in hook script post-commit?(git)

给你一囗甜甜゛ 提交于 2020-01-02 01:22:04

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/5248587/how-to-get-project-path-in-hook-script-post-commitgit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!