Skip to content

Commit 25f9e62

Browse files
committed
Add test ensuring empty submodule directories are removed
This threw me for a loop for a little while because of the differences in behavior between git 1.8 and 2.3 (the versions I run on CentOS and Mac OS X, respectively). In git 1.8, you can't stash submodule changes, but you can in git 2.3. Thus there's a slight difference in what happens given the code we have now. In git 1.8, we would check to see if you had only staged submodule changes (by checking if no stash was created), and would not hard reset in that case. Since there was no hard reset, no empty submodule directory would be created, and all is well (though we don't have any stash to restore anyway). In git 2.3, a stash would be created so we would hard reset. This would create an empty submodule directory which we would then have to explicitly remove in order to restore the stash we just created. The test I've added passes for both versions of git, even though it's technically only testing git 2.3. We'll have to come up with a way of running overcommit tests against multiple versions of git in Travis so we know we're not writing version-specific implementations.
1 parent b4753e5 commit 25f9e62

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

spec/overcommit/hook_context/pre_commit_spec.rb

+20
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,26 @@
353353
`git show :tracked-file`.should == "Hello Again\n"
354354
end
355355
end
356+
357+
context 'when a submodule removal was staged' do
358+
around do |example|
359+
submodule = repo do
360+
`git commit --allow-empty -m "Initial commit"`
361+
end
362+
363+
repo do
364+
`git submodule add #{submodule} sub &>/dev/null`
365+
`git commit -m "Add submodule"`
366+
`git rm sub`
367+
example.run
368+
end
369+
end
370+
371+
it 'does not leave behind an empty submodule directory' do
372+
subject
373+
File.exist?('sub').should == false
374+
end
375+
end
356376
end
357377

358378
describe '#modified_files' do

0 commit comments

Comments
 (0)