|
| 1 | +require 'test_helper' |
| 2 | + |
| 3 | +class TestPull < Test::Unit::TestCase |
| 4 | + |
| 5 | + test 'pull with branch only should raise an ArgumentError' do |
| 6 | + in_temp_dir do |path| |
| 7 | + Dir.mkdir('remote') |
| 8 | + |
| 9 | + Dir.chdir('remote') do |
| 10 | + `git init --initial-branch=branch1` |
| 11 | + File.write('README.md', 'Line 1') |
| 12 | + `git add README.md` |
| 13 | + `git commit -m "Initial commit"` |
| 14 | + end |
| 15 | + |
| 16 | + `git clone remote/.git local 2>&1` |
| 17 | + |
| 18 | + Dir.chdir('local') do |
| 19 | + git = Git.open('.') |
| 20 | + assert_raises(ArgumentError) { git.pull(nil, 'branch1') } |
| 21 | + end |
| 22 | + end |
| 23 | + end |
| 24 | + |
| 25 | + test 'pull with no args should use the default remote and current branch name' do |
| 26 | + in_temp_dir do |path| |
| 27 | + Dir.mkdir('remote') |
| 28 | + |
| 29 | + Dir.chdir('remote') do |
| 30 | + `git init --initial-branch=branch1` |
| 31 | + File.write('README.md', 'Line 1') |
| 32 | + `git add README.md` |
| 33 | + `git commit -m "Initial commit"` |
| 34 | + end |
| 35 | + |
| 36 | + `git clone remote/.git local 2>&1` |
| 37 | + |
| 38 | + Dir.chdir('remote') do |
| 39 | + File.open('README.md', 'a') { |f| f.write('Line 2') } |
| 40 | + `git add README.md` |
| 41 | + `git commit -m "Initial commit"` |
| 42 | + end |
| 43 | + |
| 44 | + Dir.chdir('local') do |
| 45 | + git = Git.open('.') |
| 46 | + assert_equal(1, git.log.size) |
| 47 | + assert_nothing_raised { git.pull } |
| 48 | + assert_equal(2, git.log.size) |
| 49 | + end |
| 50 | + end |
| 51 | + end |
| 52 | + |
| 53 | + test 'pull with one arg should use arg as remote and the current branch name' do |
| 54 | + in_temp_dir do |path| |
| 55 | + Dir.mkdir('remote') |
| 56 | + |
| 57 | + Dir.chdir('remote') do |
| 58 | + `git init --initial-branch=branch1` |
| 59 | + File.write('README.md', 'Line 1') |
| 60 | + `git add README.md` |
| 61 | + `git commit -m "Initial commit"` |
| 62 | + end |
| 63 | + |
| 64 | + `git clone remote/.git local 2>&1` |
| 65 | + |
| 66 | + Dir.chdir('remote') do |
| 67 | + File.open('README.md', 'a') { |f| f.write('Line 2') } |
| 68 | + `git add README.md` |
| 69 | + `git commit -m "Initial commit"` |
| 70 | + end |
| 71 | + |
| 72 | + Dir.chdir('local') do |
| 73 | + git = Git.open('.') |
| 74 | + assert_equal(1, git.log.size) |
| 75 | + assert_nothing_raised { git.pull('origin') } |
| 76 | + assert_equal(2, git.log.size) |
| 77 | + end |
| 78 | + end |
| 79 | + end |
| 80 | + |
| 81 | + test 'pull with both remote and branch should use both' do |
| 82 | + in_temp_dir do |path| |
| 83 | + Dir.mkdir('remote') |
| 84 | + |
| 85 | + Dir.chdir('remote') do |
| 86 | + `git init --initial-branch=master` |
| 87 | + File.write('README.md', 'Line 1') |
| 88 | + `git add README.md` |
| 89 | + `git commit -m "Initial commit"` |
| 90 | + end |
| 91 | + |
| 92 | + `git clone remote/.git local 2>&1` |
| 93 | + |
| 94 | + Dir.chdir('remote') do |
| 95 | + `git checkout -b feature1 2>&1` |
| 96 | + File.write('feature1.md', 'Line 1') |
| 97 | + `git add feature1.md` |
| 98 | + `git commit -m "Implement feature 1"` |
| 99 | + File.open('feature1.md', 'a') { |f| f.write('Line 2') } |
| 100 | + `git add feature1.md` |
| 101 | + `git commit -m "Implement feature 1, line 2"` |
| 102 | + end |
| 103 | + |
| 104 | + Dir.chdir('local') do |
| 105 | + git = Git.open('.') |
| 106 | + assert_equal(1, git.log.size) |
| 107 | + assert_nothing_raised { git.pull('origin', 'feature1') } |
| 108 | + assert_equal(3, git.log.size) |
| 109 | + end |
| 110 | + end |
| 111 | + end |
| 112 | +end |
0 commit comments