このパスが時々gitリポジトリではないのはなぜですか?

このパスが時々gitリポジトリではないのはなぜですか?

ドキュメントを更新し、単体テストを実行するなどのタスクを実行するgit Hook()がありますが、post-receive時には正しく動作しません。

フックの内容は次のとおりですpost-receive

#!/usr/bin/bash
~/bubblegum_ci > /tmp/bubblegum_ci_log 2>&1 &

これは理解するのが難しくありません。バックグラウンドでスクリプトを起動し、stdoutとstderrをログファイルにパイプするだけです。

以下はbubblegum_ciの内容です。

#!/usr/bin/bash
id
cd /home/git/bubblegum
pwd
GIT_CURL_VERBOSE=1 GIT_TRACE=1 git pull -v .
make genhtml doxygen

これも簡単です。別のリポジトリに移動して変更をインポートし、呼び出してmake実際の操作を実行します。時にはうまくいきます。時々、スクリプトは次の出力を提供します。

uid=1001(git) gid=1001(git) groups=1001(git),1002(www)
/home/git/bubblegum
fatal: not a git repository: '.'
make genhtml doxygen
<the output from make showing that the commits I just pushed have not been pulled>

最初の行/home/git/bubblegumは明らかに出力pwdですが、gitはgitリポジトリではないのでインポートできません。私はこれが時々動作し、時には動作しないという事実のために混乱しています。ここで誰でもこの問題を説明できますか?私が知らない競争条件はありますか?そうでなければ、この種の仕事を処理するより良い方法があるかどうかを知りたいです。

/home/git/bubblegum/.git の権限は次のとおりです。

git@fancy-server:~$ ls /home/git/bubblegum -al | grep \\.git
drwxr-xr-x  8 git git   4096 Sep  2 09:58 .git

出力は次のとおりですls -l /home/git/bubblegum/.git/

$ ls -l .git
total 52
-rw-r--r--   1 git git   84 Sep  2 09:58 FETCH_HEAD
-rw-r--r--   1 git git   23 Aug 31 15:42 HEAD
-rw-r--r--   1 git git   41 Sep  2 09:58 ORIG_HEAD
drwxr-xr-x   2 git git 4096 Aug 31 15:42 branches
-rw-r--r--   1 git git  251 Aug 31 15:42 config
-rw-r--r--   1 git git   73 Aug 31 15:42 description
drwxr-xr-x   2 git git 4096 Aug 31 15:42 hooks
-rw-r--r--   1 git git 1875 Sep  2 09:52 index
drwxr-xr-x   2 git git 4096 Aug 31 15:42 info
drwxr-xr-x   3 git git 4096 Aug 31 15:42 logs
drwxr-xr-x 151 git git 4096 Sep  2 09:52 objects
-rw-r--r--   1 git git  114 Aug 31 15:42 packed-refs
drwxr-xr-x   5 git git 4096 Aug 31 15:42 refs

siの出力は次のとおりですmount | grep home

/dev/sda6 on /home type ext4 (rw,relatime) 

ベストアンサー1

問題は環境変数に関連しています。ここの手がかりは、gitフックが実行される環境ではなくコマンドラインで動作することです。

envだから私はスクリプトにコマンドを入れて気づきましたGIT_DIR="."。これは不思議なエラーメッセージを説明しますfatal: not a git repository: '.'。本当に、GIT_DIR設定は1つあり、環境変数をオーバーライドするコマンドラインオプションがあります。

コメントで、コマンドの最後に間違ったピリオドを指摘したRaphael Ahrensにも感謝しますgit pull .。これで、Pullを実行するコマンドがこのようになり、うまくいってgit --git-dir="/home/git/bubblegum/.git/" pull -vいるようです。

おすすめ記事