故事背景,svn與git各有長處,不過git大勢所趨吧,那就搞搞。git的服務端,是基於phabricator搭建的,關於它的資料自行google就行了。其實以前運維已經搭好了phabricator了,也給過我叫作test的帳號去試過了,只不過還有些問題沒處理好,拖了一段時間後,我着手來弄一下。
1. 建diffusion
詳細就很少說,diffusion名字叫swallowframework,很簡單,也有教程。
第一次,沒有分權限,全部人均可以visit, push
```
git clone http://phabricator.eelly.test/diffusion/SWALLOWFRAMEWORK/swallowframework.git eelly_swallow
```
代碼能夠正常拉取,沒問題php
第二次,將用戶按項目分了組,只有php項目的人才能visit, push,將我本身加入到php項目裏面去
```
git clone http://phabricator.eelly.test/diffusion/SWALLOWFRAMEWORK/swallowframework.git eelly_swallow
```
報錯了!
```
fatal: unable to access 'http://phabricator.eelly.test/diffusion/SWALLOWFRAMEWORK/swallowframework.git/': The requested URL returned error: 403
```
一看這提示就是權限問題。固然是google啦,找來找去,phabricator上面的設置都是正常的。
又叫了在php項目的同事去拉代碼。臥槽,他們是正常的,並且拉取的時候,會提示讓他輸入帳號,密碼,而個人拉取過程,根本就沒有提示我去輸入帳號密碼!
只能經過輸出拉取的調試信息來看看問題在哪裏了,使用的是GIT_CURL_VERBOSE=1
```
GIT_CURL_VERBOSE=1 git clone http://phabricator.eelly.test/diffusion/SWALLOWFRAMEWORK/swallowframework.git eelly_swallow
```
輸出的詳細信息以下
```
Cloning into 'eelly_swallow'...
* Couldn't find host phabricator.eelly.test in the .netrc file; using defaults
* Trying 172.18.107.96...
* TCP_NODELAY set
* Connected to phabricator.eelly.test (172.18.107.96) port 80 (#0)
> GET /diffusion/SWALLOWFRAMEWORK/swallowframework.git/info/refs?service=git-upload-pack HTTP/1.1
Host: phabricator.eelly.test
User-Agent: git/2.10.1 (Apple Git-78)
Accept: */*
Accept-Encoding: gzip
Pragma: no-cachehtml
< HTTP/1.1 401 You must log in to access repositories.
< Server: nginx
< Date: Thu, 09 Mar 2017 13:59:26 GMT
< Content-Type: text/html; charset=utf-8
< Transfer-Encoding: chunked
< Connection: keep-alive
< WWW-Authenticate: Basic realm="Phabricator Repositories"
<
* Curl_http_done: called premature == 0
* Connection #0 to host phabricator.eelly.test left intact
* Couldn't find host phabricator.eelly.test in the .netrc file; using defaults
* Found bundle for host phabricator.eelly.test: 0x7ff01250c7c0 [can pipeline]
* Hostname phabricator.eelly.test was found in DNS cache
* Trying 172.18.107.96...
* TCP_NODELAY set
* Connected to phabricator.eelly.test (172.18.107.96) port 80 (#1)
> GET /diffusion/SWALLOWFRAMEWORK/swallowframework.git/info/refs?service=git-upload-pack HTTP/1.1
Host: phabricator.eelly.test
User-Agent: git/2.10.1 (Apple Git-78)
Accept: */*
Accept-Encoding: gzip
Pragma: no-cachenginx
< HTTP/1.1 401 You must log in to access repositories.
< Server: nginx
< Date: Thu, 09 Mar 2017 13:59:26 GMT
< Content-Type: text/html; charset=utf-8
< Transfer-Encoding: chunked
< Connection: keep-alive
< WWW-Authenticate: Basic realm="Phabricator Repositories"
<
* Ignoring the response-body
* Curl_http_done: called premature == 0
* Connection #1 to host phabricator.eelly.test left intact
* Issue another request to this URL: 'http://phabricator.eelly.test/diffusion/SWALLOWFRAMEWORK/swallowframework.git/info/refs?service=git-upload-pack'
* Couldn't find host phabricator.eelly.test in the .netrc file; using defaults
* Found bundle for host phabricator.eelly.test: 0x7ff01250c7c0 [can pipeline]
* Re-using existing connection! (#1) with host phabricator.eelly.test
* Connected to phabricator.eelly.test (172.18.107.96) port 80 (#1)
* Server auth using Basic with user 'test'
> GET /diffusion/SWALLOWFRAMEWORK/swallowframework.git/info/refs?service=git-upload-pack HTTP/1.1
Host: phabricator.eelly.test
Authorization: Basic dGVzdDp0MTIzNDU2Nzg=
User-Agent: git/2.10.1 (Apple Git-78)
Accept: */*
Accept-Encoding: gzip
Pragma: no-cachegit
< HTTP/1.1 403 You do not have permission to access this repository.
< Server: nginx
< Date: Thu, 09 Mar 2017 13:59:26 GMT
< Content-Type: text/html; charset=utf-8
< Transfer-Encoding: chunked
< Connection: keep-alive
< Vary: Accept-Encoding
< Content-Encoding: gzip
<
* Curl_http_done: called premature == 0
* Connection #1 to host phabricator.eelly.test left intact
fatal: unable to access 'http://phabricator.eelly.test/diffusion/SWALLOWFRAMEWORK/swallowframework.git/': The requested URL returned error: 403
```
這裏涉及的幾回握手的過程就不詳細解釋了,你們用心看一下仍是能夠明白的。
重點關注這幾行代碼
```
* Ignoring the response-body
* Curl_http_done: called premature == 0
* Connection #1 to host phabricator.eelly.test left intact
* Issue another request to this URL: 'http://phabricator.eelly.test/diffusion/SWALLOWFRAMEWORK/swallowframework.git/info/refs?service=git-upload-pack'
* Couldn't find host phabricator.eelly.test in the .netrc file; using defaults
* Found bundle for host phabricator.eelly.test: 0x7ff01250c7c0 [can pipeline]
* Re-using existing connection! (#1) with host phabricator.eelly.test
* Connected to phabricator.eelly.test (172.18.107.96) port 80 (#1)
* Server auth using Basic with user 'test'
> GET /diffusion/SWALLOWFRAMEWORK/swallowframework.git/info/refs?service=git-upload-pack HTTP/1.1
Host: phabricator.eelly.test
Authorization: Basic dGVzdDp0MTIzNDU2Nzg=
User-Agent: git/2.10.1 (Apple Git-78)
Accept: */*
Accept-Encoding: gzip
Pragma: no-cache
```
這裏的意思是,Ignoring the response-body,忽略響應的內容,Server auth using Basic with user 'test',直接用test這個帳號去嘗試登陸。我在其它同事debug這個clone的過程,是沒有這些步驟的,他們是,去到 WWW-Authenticate: Basic realm="Phabricator Repositories" 這一步的時候,就會顯示輸入帳號密碼的過程,怎麼回事呢?爲何一直都是用test這個帳號去嘗試登陸呢?
過程是很複雜的,反正也花了兩個小時去找解決方案,也嘗試了不一樣方法。最後在這裏找到了頭緒,http://git.vger.kernel.narkive.com/iW0NHyKd/git-https-transport-and-wrong-password
這文章裏面關鍵點在於這些對話
```
1. Using a credential helper that supports secure long-term storage
(osxkeychain, wincred, etc).vim
2. Specifying the username to the credential subsystem explicitly, by
putting something like:運維
[credential "https://yourhost/"]
username = yourusernamesvn
in your git config.
```
意思是說,在你的git config裏面,直接針對某個遠程地址,設置帳號,因而我改了一下本身的git配置
```
vim ~/.gitconfig
```
在後面加入
```
[credential "http://phabricator.eelly.test"]
username = xxxxxxx
```
再次進行拉取
```
GIT_CURL_VERBOSE=1 git clone http://phabricator.eelly.test/diffusion/SWALLOWFRAMEWORK/swallowframework.git eelly_swallow
```
此次就正常了,提示我輸入密碼,搞掂!從以上文章,大概聯想了一下,應該是macOS的keychain保存了一些帳號致使在clone的時候,默認使用了test這個帳號去進行登陸的,因而再看了下keychain裏面的東西。真是無語了,果真是這樣子this
乾脆一作二不休,直接將keychain對應的帳號密碼,由test改成我本身的帳號密碼,完成!google
have fun with macOS & git!url