|
7 | 7 | let(:input) { double('input') }
|
8 | 8 | let(:context) { described_class.new(config, args, input) }
|
9 | 9 |
|
10 |
| - describe '#amend?' do |
11 |
| - subject { context.amend? } |
| 10 | + describe '#amendment?' do |
| 11 | + subject { context.amendment? } |
| 12 | + |
| 13 | + before do |
| 14 | + Overcommit::Utils.stub(:parent_command).and_return(command) |
| 15 | + end |
12 | 16 |
|
13 | 17 | context 'when amending a commit using `git commit --amend`' do
|
14 |
| - before do |
15 |
| - Overcommit::Utils.stub(:parent_command).and_return('git commit --amend') |
16 |
| - end |
| 18 | + let(:command) { 'git commit --amend' } |
17 | 19 |
|
18 | 20 | it { should == true }
|
19 | 21 | end
|
|
22 | 24 | around do |example|
|
23 | 25 | repo do
|
24 | 26 | `git config alias.amend 'commit --amend'`
|
| 27 | + `git config alias.other-amend 'commit --amend'` |
25 | 28 | example.run
|
26 | 29 | end
|
27 | 30 | end
|
28 | 31 |
|
29 |
| - before do |
30 |
| - Overcommit::Utils.stub(:parent_command).and_return('git amend') |
| 32 | + context 'when using one of multiple aliases' do |
| 33 | + let(:command) { 'git amend' } |
| 34 | + |
| 35 | + it { should == true } |
31 | 36 | end
|
32 | 37 |
|
33 |
| - it { should == true } |
| 38 | + context 'when using another of multiple aliases' do |
| 39 | + let(:command) { 'git other-amend' } |
| 40 | + |
| 41 | + it { should == true } |
| 42 | + end |
34 | 43 | end
|
35 | 44 |
|
36 | 45 | context 'when not amending a commit' do
|
37 |
| - before do |
38 |
| - Overcommit::Utils.stub(:parent_command).and_return('git commit') |
| 46 | + context 'using `git commit`' do |
| 47 | + let(:command) { 'git commit' } |
| 48 | + |
| 49 | + it { should == false } |
39 | 50 | end
|
40 | 51 |
|
41 |
| - it { should == false } |
| 52 | + context 'using a git alias containing "--amend"' do |
| 53 | + let(:command) { 'git no--amend' } |
| 54 | + |
| 55 | + around do |example| |
| 56 | + repo do |
| 57 | + `git config alias.no--amend commit` |
| 58 | + example.run |
| 59 | + end |
| 60 | + end |
| 61 | + |
| 62 | + it { should == false } |
| 63 | + end |
42 | 64 | end
|
43 | 65 | end
|
44 | 66 |
|
|
296 | 318 | describe '#modified_files' do
|
297 | 319 | subject { context.modified_files }
|
298 | 320 |
|
| 321 | + before do |
| 322 | + context.stub(:amendment?).and_return(false) |
| 323 | + end |
| 324 | + |
299 | 325 | it 'does not include submodules' do
|
300 | 326 | submodule = repo do
|
301 | 327 | `touch foo`
|
|
359 | 385 |
|
360 | 386 | it { should be_empty }
|
361 | 387 | end
|
| 388 | + |
| 389 | + context 'when amending last commit' do |
| 390 | + around do |example| |
| 391 | + repo do |
| 392 | + FileUtils.touch('some-file') |
| 393 | + `git add some-file` |
| 394 | + `git commit -m 'Initial commit'` |
| 395 | + FileUtils.touch('other-file') |
| 396 | + `git add other-file` |
| 397 | + example.run |
| 398 | + end |
| 399 | + end |
| 400 | + |
| 401 | + before do |
| 402 | + context.stub(:amendment?).and_return(true) |
| 403 | + end |
| 404 | + |
| 405 | + it { should =~ [File.expand_path('some-file'), File.expand_path('other-file')] } |
| 406 | + end |
| 407 | + end |
| 408 | + |
| 409 | + describe '#modified_lines_in_file' do |
| 410 | + let(:modified_file) { 'some-file' } |
| 411 | + subject { context.modified_lines_in_file(modified_file) } |
| 412 | + |
| 413 | + before do |
| 414 | + context.stub(:amendment?).and_return(false) |
| 415 | + end |
| 416 | + |
| 417 | + context 'when file contains a trailing newline' do |
| 418 | + around do |example| |
| 419 | + repo do |
| 420 | + File.open(modified_file, 'w') { |f| (1..3).each { |i| f.write("#{i}\n") } } |
| 421 | + `git add #{modified_file}` |
| 422 | + example.run |
| 423 | + end |
| 424 | + end |
| 425 | + |
| 426 | + it { should == Set.new(1..3) } |
| 427 | + end |
| 428 | + |
| 429 | + context 'when file does not contain a trailing newline' do |
| 430 | + around do |example| |
| 431 | + repo do |
| 432 | + File.open(modified_file, 'w') do |f| |
| 433 | + (1..2).each { |i| f.write("#{i}\n") } |
| 434 | + f.write(3) |
| 435 | + end |
| 436 | + |
| 437 | + `git add #{modified_file}` |
| 438 | + example.run |
| 439 | + end |
| 440 | + end |
| 441 | + |
| 442 | + it { should == Set.new(1..3) } |
| 443 | + end |
| 444 | + |
| 445 | + context 'when amending last commit' do |
| 446 | + around do |example| |
| 447 | + repo do |
| 448 | + File.open(modified_file, 'w') { |f| (1..3).each { |i| f.write("#{i}\n") } } |
| 449 | + `git add #{modified_file}` |
| 450 | + `git commit -m "Add files"` |
| 451 | + File.open(modified_file, 'a') { |f| f.puts 4 } |
| 452 | + `git add #{modified_file}` |
| 453 | + example.run |
| 454 | + end |
| 455 | + end |
| 456 | + |
| 457 | + before do |
| 458 | + context.stub(:amendment?).and_return(true) |
| 459 | + end |
| 460 | + |
| 461 | + it { should == Set.new(1..4) } |
| 462 | + end |
362 | 463 | end
|
363 | 464 | end
|
0 commit comments