"Repository name" is not a well-defined idea in git, I think. Perhaps the most useful is to return whatever.git in the case of an open repository or whatever in the case of a repository with a working tree. I tested that this Bourne shell bit deals with both cases due to the post-receive hook:
if [ $(git rev-parse --is-bare-repository) = true ] then REPOSITORY_BASENAME=$(basename "$PWD") else REPOSITORY_BASENAME=$(basename $(readlink -nf "$PWD"/..)) fi echo REPOSITORY_BASENAME is $REPOSITORY_BASENAME
Update: if you want to remove the .git extension in case of open storage, you can add a line in the first case to disable it:
REPOSITORY_BASENAME=$(basename "$PWD") REPOSITORY_BASENAME=${REPOSITORY_BASENAME%.git}
Mark Longair Apr 7 2018-11-11T00: 00Z
source share