added merging functions
[rubygit.git] / tests / units / test_branch.rb
blobbc7d807941aa1f69edaa2f9afcec4299000f9536
1 #!/usr/bin/env ruby
3 require File.dirname(__FILE__) + '/../test_helper'
5 class TestBranch < Test::Unit::TestCase
6   def setup
7     set_file_paths
8     @git = Git.open(@wdir)
9     
10     @commit = @git.object('1cc8667014381')
11     @tree = @git.object('1cc8667014381^{tree}')
12     @blob = @git.object('v2.5:example.txt')
13     
14     @branches = @git.branches
15   end
17   
18   def test_branches_all
19     assert(@git.branches[:master].is_a?(Git::Branch))
20     assert(@git.branches.size > 5)
21   end
22   
23   def test_branches_local
24     bs = @git.branches.local
25     assert(bs.size > 4)
26   end
28   def test_branches_remote
29     bs = @git.branches.remote
30     assert_equal(1, bs.size)
31   end
32   
33   def test_branches_single
34     b = @git.branches[:test_object]
35     assert_equal('test_object', b.name)
37     b = @git.branches['working/master']
38     assert_equal('master', b.name)
39     assert_equal('working/master', b.full)
40     assert_equal('working', b.remote.name)
41     assert_equal('+refs/heads/*:refs/remotes/working/*', b.remote.fetch)
42     assert_equal('../working.git', b.remote.url)
43   end
44   
45   def test_branch_commit
46     assert_equal(270, @git.branches[:test_branches].gcommit.size)
47   end
48   
49   def test_branch_create_and_switch
50     in_temp_dir do |path|
51       g = Git.clone(@wbare, 'branch_test')
52       Dir.chdir('branch_test') do
53         assert(!g.branch('new_branch').current)
54         g.branch('other_branch').create
55         g.branch('new_branch').checkout
56         assert(g.branch('new_branch').current)
58         assert_equal(1, g.branches.select { |b| b.name == 'new_branch' }.size)
60         new_file('test-file1', 'blahblahblah1')
61         new_file('test-file2', 'blahblahblah2')
62         assert(g.status.untracked.assoc('test-file1'))
63         
64         g.add(['test-file1', 'test-file2'])
65         assert(!g.status.untracked.assoc('test-file1'))
66         
67         g.reset
68         assert(g.status.untracked.assoc('test-file1'))
69         assert(!g.status.added.assoc('test-file1'))
71         assert_raise Git::GitExecuteError do
72           g.branch('new_branch').delete 
73         end
74         assert_equal(1, g.branches.select { |b| b.name == 'new_branch' }.size)
76         g.branch('master').checkout
77         g.branch('new_branch').delete
78         assert_equal(0, g.branches.select { |b| b.name == 'new_branch' }.size)
79         
80         g.checkout('other_branch')
81         assert(g.branch('other_branch').current)
83         g.checkout('master')
84         assert(!g.branch('other_branch').current)
86         g.checkout(g.branch('other_branch'))
87         assert(g.branch('other_branch').current)
88         
89       end
90     end
91   end
92   
93 end