カピバラ好きなエンジニアブログ

興味ある技術とか検証した内容を赴くままに書いていきます。カピバラの可愛さこそ至高。

git clone時に詳細なログを出力させる

これもよく忘れて毎回調べているので、書いておきます。

↓参考記事↓
stupiddog.jp

実施作業

設定内容

以下の環境変数を追加してgit cloneを実行すると、処理の詳細なログを出力することができます。

# GIT_TRACE=1
# GIT_CURL_VERBOSE=1


実行結果

実際に実行して内容を確認してみます。
実行環境はWindows Serverで、Gitの認証はcodecommitの認証ヘルパーで設定してIAMユーザのアクセスキーとシークレットキーを使用して認証するようにしています。

環境変数を未設定でgit cloneするとエラー内容は最低限しか出力されません。

# git clone https://git-codecommit.ap-northeast-1.amazonaws.com/v1/repos/TestRepoA
Cloning into 'TestRepoA'...
fatal: unable to access 'https://git-codecommit.ap-northeast-1.amazonaws.com/v1/repos/TestRepoA/': The requested URL returned error: 403

環境変数を設定します。

# $env:GIT_TRACE=1
# $env:GIT_CURL_VERBOSE=1

再度git cloneを実行すると以下のように処理の内容が詳細に出力されます。

# git clone https://git-codecommit.ap-northeast-1.amazonaws.com/v1/repos/TestRepoA
04:55:18.742846 exec-cmd.c:237          trace: resolved executable dir: C:/Program Files/Git/mingw64/bin
04:55:18.758469 git.c:442               trace: built-in: git clone https://git-codecommit.ap-northeast-1.amazonaws.com/v1/repos/TestRepoA
Cloning into 'TestRepoA'...
04:55:18.774096 run-command.c:663       trace: run_command: git remote-https origin https://git-codecommit.ap-northeast-1.amazonaws.com/v1/repos/TestRepoA
04:55:18.805361 exec-cmd.c:237          trace: resolved executable dir: C:/Program Files/Git/mingw64/libexec/git-core
04:55:18.805361 git.c:702               trace: exec: git-remote-https origin https://git-codecommit.ap-northeast-1.amazonaws.com/v1/repos/TestRepoA
04:55:18.805361 run-command.c:663       trace: run_command: git-remote-https origin https://git-codecommit.ap-northeast-1.amazonaws.com/v1/repos/TestRepoA
04:55:18.820975 exec-cmd.c:237          trace: resolved executable dir: C:/Program Files/Git/mingw64/libexec/git-core
* Couldn't find host git-codecommit.ap-northeast-1.amazonaws.com in the .netrc file; using defaults
*   Trying 10.10.2.51:443...
* Connected to git-codecommit.ap-northeast-1.amazonaws.com (10.10.2.51) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt
  CApath: none
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-SHA
* ALPN, server did not agree to a protocol
* Server certificate:
*  subject: CN=git-codecommit.ap-northeast-1.amazonaws.com
*  start date: Jul  9 00:00:00 2020 GMT
*  expire date: Jul  2 12:00:00 2021 GMT
*  subjectAltName: host "git-codecommit.ap-northeast-1.amazonaws.com" matched cert's "git-codecommit.ap-northeast-1.amazonaws.com"
*  issuer: C=US; O=Amazon; OU=Server CA 1B; CN=Amazon
*  SSL certificate verify ok.
> GET /v1/repos/TestRepoA/info/refs?service=git-upload-pack HTTP/1.1
Host: git-codecommit.ap-northeast-1.amazonaws.com
User-Agent: git/2.27.0.windows.1
Accept: */*
Accept-Encoding: deflate, gzip
Pragma: no-cache

* Mark bundle as not supporting multiuse
< HTTP/1.1 401
< x-amzn-RequestId: 625990c2-5e52-4fda-aa54-cb435de206eb
< WWW-Authenticate: Basic realm=""
< Content-Type: text/xml
< Content-Length: 95
< Date: Tue, 21 Jul 2020 04:55:18 GMT
<
* Connection #0 to host git-codecommit.ap-northeast-1.amazonaws.com left intact
04:55:18.883461 run-command.c:663       trace: run_command: ''\''C:\Users\Administrator\AppData\Roaming\GitCredStore\git-credential-AWSSV4.exe'\'' --profile=test-codecommit --region=ap-northeast-1 get'
* Found bundle for host git-codecommit.ap-northeast-1.amazonaws.com: 0x30c6b90 [serially]
* Can not multiplex, even if we wanted to!
* Re-using existing connection! (#0) with host git-codecommit.ap-northeast-1.amazonaws.com
* Connected to git-codecommit.ap-northeast-1.amazonaws.com (10.10.2.51) port 443 (#0)
* Server auth using Basic with user 'XXXXXXXXXXXXXXXXXXXXXXXXX'
> GET /v1/repos/TestRepoA/info/refs?service=git-upload-pack HTTP/1.1
Host: git-codecommit.ap-northeast-1.amazonaws.com
Authorization: Basic XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
User-Agent: git/2.27.0.windows.1
Accept: */*
Accept-Encoding: deflate, gzip
Pragma: no-cache

* Mark bundle as not supporting multiuse
< HTTP/1.1 403
< x-amzn-RequestId: 2926e914-67e4-4b71-b6c5-911d2dfa0990
< Content-Type: text/xml
< Content-Length: 266
< Date: Tue, 21 Jul 2020 04:55:18 GMT
<
* Connection #0 to host git-codecommit.ap-northeast-1.amazonaws.com left intact
fatal: unable to access 'https://git-codecommit.ap-northeast-1.amazonaws.com/v1/repos/TestRepoA/': The requested URL returned error: 403

感想及び所感

ちなみに上記エラーはログ出力してもわからなくて、別の方法で調べたら解決しました