|
| 1 | +require 'test_helper' |
| 2 | + |
| 3 | +class TestPush < Test::Unit::TestCase |
| 4 | + test 'push with no args' do |
| 5 | + expected_command_line = ['push'] |
| 6 | + git_cmd = :push |
| 7 | + git_cmd_args = [] |
| 8 | + assert_command_line(expected_command_line, git_cmd, git_cmd_args) |
| 9 | + end |
| 10 | + |
| 11 | + test 'push with no args and options' do |
| 12 | + expected_command_line = ['push', '--force'] |
| 13 | + git_cmd = :push |
| 14 | + git_cmd_args = [force: true] |
| 15 | + assert_command_line(expected_command_line, git_cmd, git_cmd_args) |
| 16 | + end |
| 17 | + |
| 18 | + test 'push with only a remote name' do |
| 19 | + expected_command_line = ['push', 'origin'] |
| 20 | + git_cmd = :push |
| 21 | + git_cmd_args = ['origin'] |
| 22 | + assert_command_line(expected_command_line, git_cmd, git_cmd_args) |
| 23 | + end |
| 24 | + |
| 25 | + test 'push with only a remote name and options' do |
| 26 | + expected_command_line = ['push', '--force', 'origin'] |
| 27 | + git_cmd = :push |
| 28 | + git_cmd_args = ['origin', force: true] |
| 29 | + assert_command_line(expected_command_line, git_cmd, git_cmd_args) |
| 30 | + end |
| 31 | + |
| 32 | + test 'push with only a branch name' do |
| 33 | + expected_command_line = ['push', 'master'] |
| 34 | + git_cmd = :push |
| 35 | + git_cmd_args = [nil, 'origin'] |
| 36 | + |
| 37 | + in_temp_dir do |
| 38 | + git = Git.init('.', initial_branch: 'master') |
| 39 | + assert_raises(ArgumentError) { git.push(nil, 'master') } |
| 40 | + end |
| 41 | + end |
| 42 | + |
| 43 | + test 'push with both remote and branch name' do |
| 44 | + expected_command_line = ['push', 'origin', 'master'] |
| 45 | + git_cmd = :push |
| 46 | + git_cmd_args = ['origin', 'master'] |
| 47 | + assert_command_line(expected_command_line, git_cmd, git_cmd_args) |
| 48 | + end |
| 49 | + |
| 50 | + test 'push with force: true' do |
| 51 | + expected_command_line = ['push', '--force', 'origin', 'master'] |
| 52 | + git_cmd = :push |
| 53 | + git_cmd_args = ['origin', 'master', force: true] |
| 54 | + assert_command_line(expected_command_line, git_cmd, git_cmd_args) |
| 55 | + end |
| 56 | + |
| 57 | + test 'push with f: true' do |
| 58 | + expected_command_line = ['push', '--force', 'origin', 'master'] |
| 59 | + git_cmd = :push |
| 60 | + git_cmd_args = ['origin', 'master', f: true] |
| 61 | + assert_command_line(expected_command_line, git_cmd, git_cmd_args) |
| 62 | + end |
| 63 | + |
| 64 | + test 'push with mirror: true' do |
| 65 | + expected_command_line = ['push', '--force', 'origin', 'master'] |
| 66 | + git_cmd = :push |
| 67 | + git_cmd_args = ['origin', 'master', f: true] |
| 68 | + assert_command_line(expected_command_line, git_cmd, git_cmd_args) |
| 69 | + end |
| 70 | + |
| 71 | + test 'push with delete: true' do |
| 72 | + expected_command_line = ['push', '--delete', 'origin', 'master'] |
| 73 | + git_cmd = :push |
| 74 | + git_cmd_args = ['origin', 'master', delete: true] |
| 75 | + assert_command_line(expected_command_line, git_cmd, git_cmd_args) |
| 76 | + end |
| 77 | + |
| 78 | + test 'push with tags: true' do |
| 79 | + expected_command_line = ['push', '--tags', 'origin'] |
| 80 | + git_cmd = :push |
| 81 | + git_cmd_args = ['origin', nil, tags: true] |
| 82 | + assert_command_line(expected_command_line, git_cmd, git_cmd_args) |
| 83 | + end |
| 84 | + |
| 85 | + test 'when push succeeds an error should not be raised' do |
| 86 | + in_temp_dir do |
| 87 | + Git.init('remote.git', initial_branch: 'master', bare: true) |
| 88 | + |
| 89 | + git = Git.clone('remote.git', 'local') |
| 90 | + Dir.chdir 'local' do |
| 91 | + File.write('File2.txt', 'hello world') |
| 92 | + git.add('File2.txt') |
| 93 | + git.commit('Second commit') |
| 94 | + assert_nothing_raised { git.push } |
| 95 | + end |
| 96 | + end |
| 97 | + end |
| 98 | + |
| 99 | + test 'when push fails a Git::FailedError should be raised' do |
| 100 | + in_temp_dir do |
| 101 | + Git.init('remote.git', initial_branch: 'master', bare: true) |
| 102 | + |
| 103 | + git = Git.clone('remote.git', 'local') |
| 104 | + Dir.chdir 'local' do |
| 105 | + # Pushing when there is nothing to push fails |
| 106 | + assert_raises(Git::FailedError) { git.push } |
| 107 | + end |
| 108 | + end |
| 109 | + end |
| 110 | +end |
0 commit comments