6 from cola
import gitcmds
7 from cola
import gitcfg
10 class GitCmdsTestCase(helper
.GitRepositoryTestCase
):
11 """Tests the cola.gitcmds module."""
13 helper
.GitRepositoryTestCase
.setUp(self
)
14 self
.config
= gitcfg
.GitConfig()
16 def test_currentbranch(self
):
17 """Test current_branch()."""
18 self
.assertEqual(gitcmds
.current_branch(), 'master')
20 def test_branch_list_local(self
):
21 """Test branch_list(remote=False)."""
22 self
.assertEqual(gitcmds
.branch_list(remote
=False), ['master'])
24 def test_branch_list_remote(self
):
25 """Test branch_list(remote=False)."""
26 self
.assertEqual(gitcmds
.branch_list(remote
=True), [])
28 git remote add origin . &&
29 git fetch origin > /dev/null 2>&1
31 self
.assertEqual(gitcmds
.branch_list(remote
=True), ['origin/master'])
32 self
.shell('git remote rm origin')
33 self
.assertEqual(gitcmds
.branch_list(remote
=True), [])
35 def test_default_remote(self
):
36 """Test default_remote()."""
37 self
.assertEqual(gitcmds
.default_remote(config
=self
.config
), None)
38 self
.shell('git config branch.master.remote test')
40 self
.assertEqual(gitcmds
.default_remote(config
=self
.config
), 'test')
42 def test_tracked_branch(self
):
43 """Test tracked_branch()."""
44 self
.assertEqual(gitcmds
.tracked_branch(config
=self
.config
), None)
46 git config branch.master.remote test &&
47 git config branch.master.merge refs/heads/master
50 self
.assertEqual(gitcmds
.tracked_branch(config
=self
.config
),
53 def test_tracked_branch_other(self
):
54 """Test tracked_branch('other')."""
55 self
.assertEqual(gitcmds
.tracked_branch('other', config
=self
.config
),
58 git config branch.other.remote test &&
59 git config branch.other.merge refs/heads/other/branch
62 self
.assertEqual(gitcmds
.tracked_branch('other', config
=self
.config
),
65 def test_untracked_files(self
):
66 """Test untracked_files()."""
67 self
.shell('touch C D E')
68 self
.assertEqual(gitcmds
.untracked_files(), ['C', 'D', 'E'])
70 def test_tag_list(self
):
71 """Test tag_list()."""
72 self
.shell('git tag a && git tag b && git tag c')
73 self
.assertEqual(gitcmds
.tag_list(), ['c', 'b', 'a'])
75 def test_merge_message_path(self
):
76 """Test merge_message_path()."""
77 self
.shell('touch .git/SQUASH_MSG')
78 self
.assertEqual(gitcmds
.merge_message_path(),
79 os
.path
.abspath('.git/SQUASH_MSG'))
80 self
.shell('touch .git/MERGE_MSG')
81 self
.assertEqual(gitcmds
.merge_message_path(),
82 os
.path
.abspath('.git/MERGE_MSG'))
83 os
.unlink(gitcmds
.merge_message_path())
84 self
.assertEqual(gitcmds
.merge_message_path(),
85 os
.path
.abspath('.git/SQUASH_MSG'))
86 os
.unlink(gitcmds
.merge_message_path())
87 self
.assertEqual(gitcmds
.merge_message_path(), None)
89 def test_all_refs(self
):
97 git remote add origin . &&
98 git fetch origin > /dev/null 2>&1
100 refs
= gitcmds
.all_refs()
101 self
.assertEqual(refs
,
102 ['a', 'b', 'c', 'master',
103 'origin/a', 'origin/b', 'origin/c', 'origin/master',
106 def test_all_refs_split(self
):
114 git remote add origin . &&
115 git fetch origin > /dev/null 2>&1
117 local
, remote
, tags
= gitcmds
.all_refs(split
=True)
118 self
.assertEqual(local
, ['a', 'b', 'c', 'master'])
119 self
.assertEqual(remote
, ['origin/a', 'origin/b', 'origin/c', 'origin/master'])
120 self
.assertEqual(tags
, ['d', 'e', 'f'])
123 if __name__
== '__main__':