Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/overcommit/hook_context/pre_commit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
48 changes: 48 additions & 0 deletions spec/overcommit/hook_context/pre_commit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sds How's this?

end
end

context 'when a broken symlink is staged' do
around do |example|
repo do
Expand Down Expand Up @@ -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
Expand Down