/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to tests/test_blackbox.py

Prevent accidentally removing branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2007 David Allouche <ddaa@ddaa.net>
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 
 
17
"""Black-box tests for bzr-git."""
 
18
 
 
19
from dulwich.repo import (
 
20
    Repo as GitRepo,
 
21
    )
 
22
 
 
23
import os
 
24
 
 
25
from bzrlib import (
 
26
    version_info as bzrlib_version,
 
27
    )
 
28
from bzrlib.bzrdir import (
 
29
    BzrDir,
 
30
    )
 
31
 
 
32
from bzrlib.tests.blackbox import ExternalBase
 
33
 
 
34
from bzrlib.plugins.git import (
 
35
    tests,
 
36
    )
 
37
 
 
38
 
 
39
class TestGitBlackBox(ExternalBase):
 
40
 
 
41
    def simple_commit(self):
 
42
        # Create a git repository with a revision.
 
43
        repo = GitRepo.init(self.test_dir)
 
44
        builder = tests.GitBranchBuilder()
 
45
        builder.set_file('a', 'text for a\n', False)
 
46
        r1 = builder.commit('Joe Foo <joe@foo.com>', u'<The commit message>')
 
47
        return repo, builder.finish()[r1]
 
48
 
 
49
    def test_nick(self):
 
50
        GitRepo.init(self.test_dir)
 
51
        dir = BzrDir.open(self.test_dir)
 
52
        dir.create_branch()
 
53
        output, error = self.run_bzr(['nick'])
 
54
        self.assertEquals("master\n", output)
 
55
 
 
56
    def test_info(self):
 
57
        self.simple_commit()
 
58
        output, error = self.run_bzr(['info'])
 
59
        self.assertEqual(error, '')
 
60
        self.assertTrue("Standalone tree (format: git)" in output)
 
61
 
 
62
    def test_branch(self):
 
63
        os.mkdir("gitbranch")
 
64
        GitRepo.init(os.path.join(self.test_dir, "gitbranch"))
 
65
        os.chdir('gitbranch')
 
66
        builder = tests.GitBranchBuilder()
 
67
        builder.set_file('a', 'text for a\n', False)
 
68
        builder.commit('Joe Foo <joe@foo.com>', u'<The commit message>')
 
69
        builder.finish()
 
70
        os.chdir('..')
 
71
 
 
72
        output, error = self.run_bzr(['branch', 'gitbranch', 'bzrbranch'])
 
73
        self.assertEqual(error, 'Branched 1 revision(s).\n')
 
74
 
 
75
    def test_checkout(self):
 
76
        os.mkdir("gitbranch")
 
77
        GitRepo.init(os.path.join(self.test_dir, "gitbranch"))
 
78
        os.chdir('gitbranch')
 
79
        builder = tests.GitBranchBuilder()
 
80
        builder.set_file('a', 'text for a\n', False)
 
81
        builder.commit('Joe Foo <joe@foo.com>', u'<The commit message>')
 
82
        builder.finish()
 
83
        os.chdir('..')
 
84
 
 
85
        output, error = self.run_bzr(['checkout', 'gitbranch', 'bzrbranch'])
 
86
        self.assertEqual(error, '')
 
87
        self.assertEqual(output, '')
 
88
 
 
89
    def test_branch_ls(self):
 
90
        self.simple_commit()
 
91
        output, error = self.run_bzr(['ls', '-r-1'])
 
92
        self.assertEqual(error, '')
 
93
        self.assertEqual(output, "a\n")
 
94
 
 
95
    def test_init(self):
 
96
        self.run_bzr("init --git repo")
 
97
 
 
98
    def test_info_verbose(self):
 
99
        self.simple_commit()
 
100
 
 
101
        if bzrlib_version < (2, 4):
 
102
            self.knownFailure("bzr info uses inventory on bzr < 2.4")
 
103
 
 
104
        output, error = self.run_bzr(['info', '-v'])
 
105
        self.assertEqual(error, '')
 
106
        self.assertTrue("Standalone tree (format: git)" in output)
 
107
        self.assertTrue("control: Local Git Repository" in output)
 
108
        self.assertTrue("branch: Git Branch" in output)
 
109
        self.assertTrue("repository: Git Repository" in output)
 
110
 
 
111
    def test_push_roundtripping(self):
 
112
        self.knownFailure("roundtripping is not yet supported")
 
113
        self.with_roundtripping()
 
114
        os.mkdir("bla")
 
115
        GitRepo.init(os.path.join(self.test_dir, "bla"))
 
116
        self.run_bzr(['init', 'foo'])
 
117
        self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo'])
 
118
        # when roundtripping is supported
 
119
        output, error = self.run_bzr(['push', '-d', 'foo', 'bla'])
 
120
        self.assertEquals("", output)
 
121
        self.assertTrue(error.endswith("Created new branch.\n"))
 
122
 
 
123
    def test_log(self):
 
124
        # Smoke test for "bzr log" in a git repository.
 
125
        self.simple_commit()
 
126
 
 
127
        # Check that bzr log does not fail and includes the revision.
 
128
        output, error = self.run_bzr(['log'])
 
129
        self.assertEqual(error, '')
 
130
        self.assertTrue(
 
131
            '<The commit message>' in output,
 
132
            "Commit message was not found in output:\n%s" % (output,))
 
133
 
 
134
    def test_log_verbose(self):
 
135
        # Smoke test for "bzr log -v" in a git repository.
 
136
        self.simple_commit()
 
137
 
 
138
        # Check that bzr log does not fail and includes the revision.
 
139
        output, error = self.run_bzr(['log', '-v'])
 
140
 
 
141
    def test_tags(self):
 
142
        git_repo, commit_sha1 = self.simple_commit()
 
143
        git_repo.refs["refs/tags/foo"] = commit_sha1
 
144
 
 
145
        output, error = self.run_bzr(['tags'])
 
146
        self.assertEquals(error, '')
 
147
        self.assertEquals(output, "foo                  1\n")
 
148
 
 
149
    def test_tag(self):
 
150
        self.simple_commit()
 
151
 
 
152
        output, error = self.run_bzr(["tag", "bar"])
 
153
 
 
154
        # bzr <= 2.2 emits this message in the output stream
 
155
        # bzr => 2.3 emits this message in the error stream
 
156
        self.assertEquals(error + output, 'Created tag bar.\n')
 
157
 
 
158
    def test_init_repo(self):
 
159
        output, error = self.run_bzr(["init", "--git", "bla.git"])
 
160
        self.assertEquals(error, '')
 
161
        self.assertEquals(output, 'Created a standalone tree (format: git)\n')
 
162
 
 
163
    def test_diff_format(self):
 
164
        tree = self.make_branch_and_tree('.')
 
165
        self.build_tree(['a'])
 
166
        tree.add(['a'])
 
167
        output, error = self.run_bzr(['diff', '--format=git'], retcode=1)
 
168
        self.assertEqual(error, '')
 
169
        self.assertEqual(output,
 
170
            'diff --git /dev/null b/a\n'
 
171
            'old mode 0\n'
 
172
            'new mode 100644\n'
 
173
            'index 0000000..c197bd8 100644\n'
 
174
            '--- /dev/null\n'
 
175
            '+++ b/a\n'
 
176
            '@@ -1,0 +1,1 @@\n'
 
177
            '+contents of a\n')