Skip to content

Commit 9172dd3

Browse files
jawshooahsds
authored andcommitted
Don't clear working tree for only submodule changes
Change-Id: I5fd7db9a291aa87fcdf3fed860b18e7a9ac6a450 Reviewed-on: http://gerrit.causes.com/48259 Tested-by: jenkins <[email protected]> Reviewed-by: Shane da Silva <[email protected]>
1 parent 530a013 commit 9172dd3

2 files changed

Lines changed: 50 additions & 1 deletion

File tree

‎lib/overcommit/hook_context/pre_commit.rb‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ def setup_environment
3131
"\nSTDOUT:#{result.stdout}\nSTDERR:#{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

‎spec/overcommit/hook_context/pre_commit_spec.rb‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,30 @@
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
@@ -164,6 +188,30 @@
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

0 commit comments

Comments
 (0)