Use git to check for empty index.

This commit is contained in:
Sven Weidauer 2022-06-06 11:27:39 +02:00
parent 47363ad14b
commit 2e59062454
3 changed files with 65 additions and 3 deletions

View file

@ -57,7 +57,7 @@ describe FormatStaged do
expect(repo.get_content('test.other')).to eq('x=y')
end
it 'fails if files are changed to already comitted version' do
it 'fails if all files are changed to already comitted version' do
repo.file_in_tree 'test.test', 'x = y'
repo.set_content 'test.test', 'x=y'
repo.stage 'test.test'
@ -68,7 +68,55 @@ describe FormatStaged do
expect(repo.get_content('test.test')).to eq('x = y')
end
it 'succeeds if there are excluded files to commit' do
repo.file_in_tree 'test.test', 'x = y'
repo.set_content 'test.test', 'x=y'
repo.stage 'test.test'
repo.set_content 'test.other', 'abc'
repo.stage 'test.other'
success = repo.run_formatter
expect(success).to be_truthy
expect(repo.get_content('test.test')).to eq('x = y')
end
it 'succeeds if there are no staged files' do
expect(repo.run_formatter).to be_truthy
end
it 'succeeds if only excluded files are changed' do
repo.set_content 'test.other', 'abc'
repo.stage 'test.other'
expect(repo.run_formatter).to be_truthy
end
it 'succeeds if one file is changed' do
repo.file_in_tree 'test.test', 'x = y'
repo.set_content 'test.test', 'x=y'
repo.stage 'test.test'
repo.set_content 'other.test', 'a=b'
repo.stage 'other.test'
success = repo.run_formatter
expect(success).to be_truthy
expect(repo.get_content('test.test')).to eq('x = y')
expect(repo.get_content('other.test')).to eq('a = b')
end
it 'fails if a single file becomes empty' do
repo.file_in_tree 'test.test', 'x = y'
repo.set_content 'test.test', '#clear'
repo.stage 'test.test'
repo.set_content 'other.test', 'a=b'
repo.stage 'other.test'
success = repo.run_formatter
expect(success).to be_falsy
expect(repo.get_content('test.test')).to eq('#clear')
expect(repo.get_content('other.test')).to eq('a = b')
end
end