File tree Expand file tree Collapse file tree
lib/overcommit/hook_context
spec/overcommit/hook_context Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -31,7 +31,8 @@ def setup_environment
3131 "\n STDOUT:#{ result . stdout } \n STDERR:#{ result . stderr } "
3232 end
3333
34- @changes_stashed = true
34+ # False if only submodule references were changed
35+ @changes_stashed = modified_files . any?
3536 end
3637
3738 # While running the hooks make it appear as if nothing changed
Original file line number Diff line number Diff line change 6666 end
6767 end
6868
69+ context 'when only a submodule change is staged' do
70+ around do |example |
71+ submodule = repo do
72+ `git commit --allow-empty -m "Initial commit"`
73+ end
74+
75+ repo do
76+ `git submodule add #{ submodule } sub &>/dev/null`
77+ `git commit -m "Add submodule"`
78+ `echo "Hello World" > sub/submodule-file`
79+ `git submodule foreach 'git add submodule-file'`
80+ `git submodule foreach 'git commit -m "Another commit"'`
81+ `git add sub`
82+ example . run
83+ end
84+ end
85+
86+ it 'keeps staged submodule change' do
87+ expect { subject } . to_not change {
88+ ( `git diff --cached` =~ /-Subproject commit[\s \S ]*\+ Subproject commit/ ) . nil?
89+ } . from ( false )
90+ end
91+ end
92+
6993 context 'when a broken symlink is staged' do
7094 around do |example |
7195 repo do
164188 File . exist? ( 'tracked-file' ) . should == false
165189 end
166190 end
191+
192+ context 'when only a submodule change was staged' do
193+ around do |example |
194+ submodule = repo do
195+ `git commit --allow-empty -m "Initial commit"`
196+ end
197+
198+ repo do
199+ `git submodule add #{ submodule } sub &>/dev/null`
200+ `git commit -m "Add submodule"`
201+ `echo "Hello World" > sub/submodule-file`
202+ `git submodule foreach 'git add submodule-file'`
203+ `git submodule foreach 'git commit -m "Another commit"'`
204+ `git add sub`
205+ example . run
206+ end
207+ end
208+
209+ it 'keeps staged submodule change' do
210+ expect { subject } . to_not change {
211+ ( `git diff --cached` =~ /-Subproject commit[\s \S ]*\+ Subproject commit/ ) . nil?
212+ } . from ( false )
213+ end
214+ end
167215 end
168216
169217 describe '#modified_files' do
You can’t perform that action at this time.
0 commit comments