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
19 assert(@git.branches[:master].is_a?(Git::Branch))
20 assert(@git.branches.size > 5)
23 def test_branches_local
24 bs = @git.branches.local
28 def test_branches_remote
29 bs = @git.branches.remote
30 assert_equal(1, bs.size)
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)
45 def test_branch_commit
46 assert_equal(270, @git.branches[:test_branches].gcommit.size)
49 def test_branch_create_and_switch
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'))
64 g.add(['test-file1', 'test-file2'])
65 assert(!g.status.untracked.assoc('test-file1'))
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
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)
80 g.checkout('other_branch')
81 assert(g.branch('other_branch').current)
84 assert(!g.branch('other_branch').current)
86 g.checkout(g.branch('other_branch'))
87 assert(g.branch('other_branch').current)