3 require File.dirname(__FILE__) + '/../test_helper'
5 class TestBranch < Test::Unit::TestCase
10 @commit = @git.object('1cc8667014381')
11 @tree = @git.object('1cc8667014381^{tree}')
12 @blob = @git.object('v2.5:example.txt')
14 @branches = @git.branches
18 assert(@git.branches[:master].is_a?(Git::Branch))
19 assert(@git.branches.size > 5)
22 def test_branches_local
23 bs = @git.branches.local
27 def test_branches_remote
28 bs = @git.branches.remote
29 assert_equal(1, bs.size)
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)
44 def test_branch_commit
45 assert_equal(270, @git.branches[:test_branches].gcommit.size)
48 def test_branch_create_and_switch
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'))
63 g.add(['test-file1', 'test-file2'])
64 assert(!g.status.untracked.assoc('test-file1'))
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
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)
79 g.checkout('other_branch')
80 assert(g.branch('other_branch').current)
83 assert(!g.branch('other_branch').current)
85 g.checkout(g.branch('other_branch'))
86 assert(g.branch('other_branch').current)