.git post-receive钩子,在终端执行时起作用;但不是在推后

时间:2018-07-30 00:08:55

标签: git hook

我正从Jekyll搬到Hugo(太棒了!)。

我的部署挂钩正常运行,但需要进行较小的更新。上一个,当前流是:

  • 在同一台计算机上创建源(裸机)存储库的新临时克隆
  • 运行发电机
  • 将文件移动到Web服务器目录
  • violà,新内容

我编写了shell脚本,并且在sevrver上的shell中执行它时,它按预期运行!是的!

但是,当我进行一些琐碎的编辑(触发钩子)并推动时,钩子运行了,但是我从git中得到了错误。我在下面的set -x中提供了最奇特的输出:

remote: + rm -rf /home/sgharms/tmp/stevengharms.com
remote: + mkdir /home/sgharms/tmp/stevengharms.com
remote: + cd /home/sgharms/tmp/stevengharms.com
remote: + echo Changing into /home/sgharms/tmp/stevengharms.com
remote: Changing into /home/sgharms/tmp/stevengharms.com
remote: + cd /home/sgharms/tmp/stevengharms.com
remote: + git init
remote: Initialized empty Git repository in /home/sgharms/tmp/stevengharms.com/
remote: + git remote add origin file:////home/sgharms/stevengharms.com.git
remote: + git fetch origin
remote: From file:////home/sgharms/stevengharms.com
remote:  * [new branch]      master     -> origin/master
remote: + echo XXXXX
remote: XXXXX
remote: + pwd
remote: /home/sgharms/tmp/stevengharms.com
remote: + git checkout master
remote: fatal: This operation must be run in a work tree

但是,如果我使用sh -x post-receive运行后接收脚本...

+ rm -rf /home/sgharms/tmp/stevengharms.com
+ mkdir /home/sgharms/tmp/stevengharms.com
+ cd /home/sgharms/tmp/stevengharms.com
+ echo Changing into /home/sgharms/tmp/stevengharms.com
Changing into /home/sgharms/tmp/stevengharms.com
+ cd /home/sgharms/tmp/stevengharms.com
+ git init
Initialized empty Git repository in /home/sgharms/tmp/stevengharms.com/.git/
+ git remote add origin file:////home/sgharms/stevengharms.com.git
+ git fetch origin
remote: Counting objects: 2304, done.
remote: Compressing objects: 100% (2222/2222), done.
remote: Total 2304 (delta 72), reused 2245 (delta 42)
Receiving objects: 100% (2304/2304), 118.65 MiB | 42.91 MiB/s, done.
Resolving deltas: 100% (72/72), done.
From file:////home/sgharms/stevengharms.com
 * [new branch]      master     -> origin/master
+ echo XXXXX
XXXXX
+ pwd
/home/sgharms/tmp/stevengharms.com
+ git checkout master
Branch master set up to track remote branch master from origin by rebasing.
+ ls .git
branches  config  description  FETCH_HEAD  HEAD  hooks  index  info  logs  objects  refs
...
...
+ git submodule update --init
Submodule 'themes/ananke' (https://github.com/budparr/gohugo-theme-ananke.git) registered for path 'themes/ananke'

好。我有一些有用的数据。但是我不确定从这里去哪里。

  1. 是git子模块吗?
  2. whoami报告在同一用户上执行

我很困惑下一步该做什么。我添加了各种ls -al .git以确保git内容始终存在,并且确实存在。当我受困时,我也很想知道我在这里缺少什么。有参加者吗?

1 个答案:

答案 0 :(得分:0)

对于未来的求职者,Torek的答复使我走上了正确的道路。最终,我像这样更新了他指向的环境变量:

GIT_DIR=$GIT_REPO # the bare-repository with the content in it `~/foo.git`
GIT_WORK_TREE=$TMP_GIT_CLONE # the "working" checkout of the bare repo