diff --git a/lib/overcommit/hook_context/pre_commit.rb b/lib/overcommit/hook_context/pre_commit.rb index ef0733c1..094bba2a 100644 --- a/lib/overcommit/hook_context/pre_commit.rb +++ b/lib/overcommit/hook_context/pre_commit.rb @@ -31,7 +31,8 @@ def setup_environment "\nSTDOUT:#{result.stdout}\nSTDERR:#{result.stderr}" end - @changes_stashed = true + # False if only submodule references were changed + @changes_stashed = modified_files.any? end # While running the hooks make it appear as if nothing changed diff --git a/spec/overcommit/hook_context/pre_commit_spec.rb b/spec/overcommit/hook_context/pre_commit_spec.rb index e498290e..4a640a93 100644 --- a/spec/overcommit/hook_context/pre_commit_spec.rb +++ b/spec/overcommit/hook_context/pre_commit_spec.rb @@ -66,6 +66,30 @@ end end + context 'when only a submodule change is staged' do + around do |example| + submodule = repo do + `git commit --allow-empty -m "Initial commit"` + end + + repo do + `git submodule add #{submodule} sub &>/dev/null` + `git commit -m "Add submodule"` + `echo "Hello World" > sub/submodule-file` + `git submodule foreach 'git add submodule-file'` + `git submodule foreach 'git commit -m "Another commit"'` + `git add sub` + example.run + end + end + + it 'keeps staged submodule change' do + expect { subject }.to_not change { + (`git diff --cached` =~ /-Subproject commit[\s\S]*\+Subproject commit/).nil? + }.from(false) + end + end + context 'when a broken symlink is staged' do around do |example| repo do @@ -164,6 +188,30 @@ File.exist?('tracked-file').should == false end end + + context 'when only a submodule change was staged' do + around do |example| + submodule = repo do + `git commit --allow-empty -m "Initial commit"` + end + + repo do + `git submodule add #{submodule} sub &>/dev/null` + `git commit -m "Add submodule"` + `echo "Hello World" > sub/submodule-file` + `git submodule foreach 'git add submodule-file'` + `git submodule foreach 'git commit -m "Another commit"'` + `git add sub` + example.run + end + end + + it 'keeps staged submodule change' do + expect { subject }.to_not change { + (`git diff --cached` =~ /-Subproject commit[\s\S]*\+Subproject commit/).nil? + }.from(false) + end + end end describe '#modified_files' do