2012-07-16 104 views
25

由於「測試」是Git鉤子的常見用法,我的問題很難搜索。如何測試git鉤子

我在寫一個相當複雜的git post-receive hook,想知道測試它的最好方法是什麼。目前,我的過程是:

  • 更改在一個虛擬的「遠程」回購對接收後
  • 進行了更改虛擬本地回購
  • 承諾在虛擬本地回購
  • 推改改dummy remote repo

有沒有更簡單的方法來測試它?理想的情況是它看起來像:

  • 做出改變(收費)虛擬回購後,收到
  • 問題的「神奇」命令來測試後收到

或許我可以「補發」先前的推送還是讓遠程回購行爲好像剛剛接收到具有特定散列的推送?

回答

13

編寫一個只記錄其參數/環境並將其轉儲到文件的鉤子。然後,您可以在相同的環境/參數下重新調用真正的鉤子,它會像您剛剛重新發出完全相同的推動一樣。

+0

這是關於我做了什麼,而是通過手動檢查(回顯)相關變量。 – Errol 2012-07-17 00:25:50

+9

這樣的「翻車機」鉤子會是什麼樣子? – 2015-11-11 22:28:26

+4

@JonWatson,我剛剛使用'echo $ @; echo; PWD;回聲; set' – Lucas 2016-01-28 17:41:01

6

回答這個四歲的問題。

如果您想在本地環境中測試鉤,我給了命令的詳細信息進行跟蹤,使用post-receive作爲樣本:

$ mkdir /tmp/hook_test 
$ cd /tmp/hook_test 

# set local git repo, where you put hooks in it. 
$ git clone --bare https://github.com/git/git.git 

# set develop environment which is cloned from the new created repo. 
$ git clone git.git repo 

# copy and rename the hook you need test to "post-receive" 
$ cd git.git/hooks 
$ cp ~/post-receive-test post-receive 

# suppose the hook script is bash script. 
# edit "post-receive" and add "set -x" to second line in it to active debug 

$ cd /tmp/hook_test/repo 
# emulate a hook trigger, do some changes, "git add" and "git commit" it 

$ git push 

# Now you should see the script "post-receive" runs automatically with debug details. 

你應該自由地運行git push,該更新僅推到當地回購/tmp/hook_test/git.git