adding my testing git directory
[rubygit.git] / tests / units / test_branch.rb
blobd54b5260ada8960293a7577d29acbd0c28cce882
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
16   
17   def test_branches_all
18     assert(@git.branches[:master].is_a?(Git::Branch))
19     assert(@git.branches.size > 5)
20   end
21   
22   def test_branches_local
23     bs = @git.branches.local
24     assert(bs.size > 4)
25   end
27   def test_branches_remote
28     bs = @git.branches.remote
29     assert_equal(1, bs.size)
30   end
31   
32   def test_branches_single
33     b = @git.branches[:test_object]
34     assert_equal('test_object', b.name)
36     b = @git.branches['working/master']
37     assert_equal('master', b.name)
38     assert_equal('working/master', b.full)
39     assert_equal('working', b.remote.name)
40     assert_equal('+refs/heads/*:refs/remotes/working/*', b.remote.fetch_opts)
41     assert_equal('../working.git', b.remote.url)
42   end
43   
44   def test_branch_commit
45     assert_equal(270, @git.branches[:test_branches].gcommit.size)
46   end
47   
48   def test_branch_create_and_switch
49     in_temp_dir do |path|
50       g = Git.clone(@wbare, 'branch_test')
51       Dir.chdir('branch_test') do
52         assert(!g.branch('new_branch').current)
53         g.branch('other_branch').create
54         g.branch('new_branch').checkout
55         assert(g.branch('new_branch').current)
57         assert_equal(1, g.branches.select { |b| b.name == 'new_branch' }.size)
59         new_file('test-file1', 'blahblahblah1')
60         new_file('test-file2', 'blahblahblah2')
61         assert(g.status.untracked.assoc('test-file1'))
62         
63         g.add(['test-file1', 'test-file2'])
64         assert(!g.status.untracked.assoc('test-file1'))
65         
66         g.reset
67         assert(g.status.untracked.assoc('test-file1'))
68         assert(!g.status.added.assoc('test-file1'))
70         assert_raise Git::GitExecuteError do
71           g.branch('new_branch').delete 
72         end
73         assert_equal(1, g.branches.select { |b| b.name == 'new_branch' }.size)
75         g.branch('master').checkout
76         g.branch('new_branch').delete
77         assert_equal(0, g.branches.select { |b| b.name == 'new_branch' }.size)
78         
79         g.checkout('other_branch')
80         assert(g.branch('other_branch').current)
82         g.checkout('master')
83         assert(!g.branch('other_branch').current)
85         g.checkout(g.branch('other_branch'))
86         assert(g.branch('other_branch').current)
87         
88       end
89     end
90   end
91   
92 end