形勢當創建工作目錄是不乾淨失敗了`git的預先收到hook`
我有一個Git倉庫的我的本地系統上的副本,以及一個遙控器上的第二個服務器(都是非裸露的)。由於環境限制,我不得不在兩者上都使用Git 1.8。
在服務器上,我有[receive] denyCurrentBranch = ignore
在.git/config
和git reset --hard
在.git/hooks/post-receive
。這允許我模擬denyCurrentBranch = updateInstead
行爲。
我試圖添加一個pre-receive
掛鉤,當我沒有清潔頭時會失敗。
嘗試
在服務器上,如果我跑git status
我有以下幾點:
[server test_app]$ git status
# On branch master
nothing to commit, working directory clean
我曾計劃在鉤添加git status
,像這樣(僞的bash):
((git status | grep "On branch master" | wc -l) == 1) && ((git status | grep "nothing to commit, working directory clean" | wc -l) == 1) && (exit 0)
exit 1
要測試這是否可能,我嘗試了以下在我的鉤
個git status
exit 1
結果
當我嘗試推,我得到如下:
Pushing to ssh://.../test_app
remote: # On branch master[K
remote: # Changes not staged for commit:[K
remote: # (use "git add/rm <file>..." to update what will be committed)[K
remote: # (use "git checkout -- <file>..." to discard changes in working directory)[K
remote: #[K
remote: # deleted: bin/README[K
remote: #[K
remote: # Untracked files:[K
remote: # (use "git add <file>..." to include in what will be committed)[K
remote: #[K
remote: # COMMIT_EDITMSG[K
remote: # HEAD[K
remote: # ORIG_HEAD[K
remote: # config[K
remote: # description[K
remote: # hooks/[K
remote: # index[K
remote: # info/[K
remote: # logs/[K
remote: # objects/[K
remote: # refs/[K
remote: no changes added to commit (use "git add" and/or "git commit -a")[K
remote: I will fail[K
To ssh://.../test_app
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'ssh://.../test_app'
結論
我想這意味着我誤解了什麼狀態混帳處於預接收鉤。在我的預接收(或其他)掛鉤中,當工作目錄不乾淨時應該如何防止更新?