2012-09-28 32 views
2

有沒有一種內置的方式(或簡單的腳本),不會讓我檢查,如果任何子模塊有修改文件?就目前而言,我有無用的提交,因爲我無法返回到子模塊的狀態。Git不應該簽入如果子模塊有修改文件

+1

當然,+1爲你的好問題;)(http://meta.stackexchange.com/questions/139/爲什麼要我應該提問/ 149#comment427433_149) – VonC

回答

2

感謝VonC解釋我需要做什麼。對不起,我不知道Bash,所以這裏是Ruby版本。作品完美(迄今爲止,所有情況下,使用git 1.7.9.4版進行測試):

#!/usr/bin/env ruby 
# http://stackoverflow.com/questions/12648585/git-should-not-checkin-if-submodule-has-modified-files 
# October 1, 2012 
# call this file pre-commit, make it executable and put it in .git/hooks 
puts "Git pre-commit hook by Dan Rosenstark (yar)" 
gitDiff = `git diff` 
gitDiffWithSubmodules = `git diff --ignore-submodules` 
if (gitDiff.length == gitDiffWithSubmodules.length) 
    puts "Submodules are clean, going right ahead!" 
else 
    puts "One or more submodules are dirty, can't commit.'" 
    exit 1 
end 
+0

優秀的反饋。 +1 – VonC

3

看起來像預提交鉤子「script for submodule hygiene」用於:
如果子模塊有未決的更改,則阻止提交。

該腳本在4年前寫的(也是patch/script見),所以也許git的差異現在包括檢測「髒」子模塊簡單的方法。

+0

一如既往地感謝,我會檢查一下。我希望我不必做任何實際的腳本:) –

+0

@Yar腳本需要聲明爲預提交鉤子,這意味着它將在每次提交時運行,但會阻止實際發生的提交,如果它返回錯誤(例如,在這裏,如果子模塊有未提交的更改)。另見https://github.com/chaitanyagupta/gitutils – VonC

+0

是的,這些都很棒,特別是這個https://github.com/chaitanyagupta/gitutils/blob/master/submodule-hooks/pre-commit ...但是這行'git diff --cached --name-only | grep -F mySubmodule不起作用 –