prefs: allow opting-out of the published commit check
[git-cola.git] / test / gitcmds_test.py
blobe16655f8edece14353b5283b47a43fc3bcfe3b96
1 from __future__ import absolute_import, division, unicode_literals
2 import os
3 import unittest
5 from cola import gitcmds
7 from . import helper
10 class GitCmdsTestCase(helper.GitRepositoryTestCase):
11 """Tests the cola.gitcmds module."""
13 def test_currentbranch(self):
14 """Test current_branch()."""
15 self.assertEqual(gitcmds.current_branch(self.context), 'master')
17 def test_branch_list_local(self):
18 """Test branch_list(remote=False)."""
19 context = self.context
20 self.commit_files()
21 expect = ['master']
22 actual = gitcmds.branch_list(context, remote=False)
23 self.assertEqual(expect, actual)
25 def test_branch_list_remote(self):
26 """Test branch_list(remote=False)."""
27 context = self.context
28 expect = []
29 actual = gitcmds.branch_list(context, remote=True)
30 self.assertEqual(expect, actual)
32 self.commit_files()
33 self.run_git('remote', 'add', 'origin', '.')
34 self.run_git('fetch', 'origin')
35 expect = ['origin/master']
36 actual = gitcmds.branch_list(context, remote=True)
37 self.assertEqual(expect, actual)
39 self.run_git('remote', 'rm', 'origin')
40 expect = []
41 actual = gitcmds.branch_list(context, remote=True)
42 self.assertEqual(expect, actual)
44 def test_upstream_remote(self):
45 """Test getting the configured upstream remote"""
46 context = self.context
47 self.assertEqual(gitcmds.upstream_remote(context), None)
48 self.run_git('config', 'branch.master.remote', 'test')
49 self.cfg.reset()
50 self.assertEqual(gitcmds.upstream_remote(context), 'test')
52 def test_tracked_branch(self):
53 """Test tracked_branch()."""
54 context = self.context
55 self.assertEqual(gitcmds.tracked_branch(context), None)
56 self.run_git('config', 'branch.master.remote', 'test')
57 self.run_git('config', 'branch.master.merge', 'refs/heads/master')
58 self.cfg.reset()
59 self.assertEqual(gitcmds.tracked_branch(context), 'test/master')
61 def test_tracked_branch_other(self):
62 """Test tracked_branch('other')."""
63 context = self.context
64 self.assertEqual(gitcmds.tracked_branch(context, 'other'), None)
65 self.run_git('config', 'branch.other.remote', 'test')
66 self.run_git('config', 'branch.other.merge', 'refs/heads/other/branch')
67 self.cfg.reset()
68 self.assertEqual(gitcmds.tracked_branch(context, 'other'),
69 'test/other/branch')
71 def test_untracked_files(self):
72 """Test untracked_files()."""
73 context = self.context
74 self.touch('C', 'D', 'E')
75 self.assertEqual(gitcmds.untracked_files(context), ['C', 'D', 'E'])
77 def test_all_files(self):
78 context = self.context
79 self.touch('other-file')
80 all_files = gitcmds.all_files(context)
82 self.assertTrue('A' in all_files)
83 self.assertTrue('B' in all_files)
84 self.assertTrue('other-file' in all_files)
86 def test_tag_list(self):
87 """Test tag_list()."""
88 context = self.context
89 self.commit_files()
90 self.run_git('tag', 'a')
91 self.run_git('tag', 'b')
92 self.run_git('tag', 'c')
93 self.assertEqual(gitcmds.tag_list(context), ['c', 'b', 'a'])
95 def test_merge_message_path(self):
96 """Test merge_message_path()."""
97 context = self.context
98 self.touch('.git/SQUASH_MSG')
99 self.assertEqual(gitcmds.merge_message_path(context),
100 os.path.abspath('.git/SQUASH_MSG'))
101 self.touch('.git/MERGE_MSG')
102 self.assertEqual(gitcmds.merge_message_path(context),
103 os.path.abspath('.git/MERGE_MSG'))
104 os.unlink(gitcmds.merge_message_path(context))
105 self.assertEqual(gitcmds.merge_message_path(context),
106 os.path.abspath('.git/SQUASH_MSG'))
107 os.unlink(gitcmds.merge_message_path(context))
108 self.assertEqual(gitcmds.merge_message_path(context), None)
110 def test_all_refs(self):
111 self.commit_files()
112 self.run_git('branch', 'a')
113 self.run_git('branch', 'b')
114 self.run_git('branch', 'c')
115 self.run_git('tag', 'd')
116 self.run_git('tag', 'e')
117 self.run_git('tag', 'f')
118 self.run_git('remote', 'add', 'origin', '.')
119 self.run_git('fetch', 'origin')
120 refs = gitcmds.all_refs(self.context)
121 self.assertEqual(refs,
122 ['a', 'b', 'c', 'master',
123 'origin/a', 'origin/b', 'origin/c', 'origin/master',
124 'f', 'e', 'd'])
126 def test_all_refs_split(self):
127 self.commit_files()
128 self.run_git('branch', 'a')
129 self.run_git('branch', 'b')
130 self.run_git('branch', 'c')
131 self.run_git('tag', 'd')
132 self.run_git('tag', 'e')
133 self.run_git('tag', 'f')
134 self.run_git('remote', 'add', 'origin', '.')
135 self.run_git('fetch', 'origin')
136 local, remote, tags = gitcmds.all_refs(self.context, split=True)
137 self.assertEqual(local, ['a', 'b', 'c', 'master'])
138 self.assertEqual(remote,
139 ['origin/a', 'origin/b', 'origin/c', 'origin/master'])
140 self.assertEqual(tags, ['f', 'e', 'd'])
143 if __name__ == '__main__':
144 unittest.main()