~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_tags.py

  • Committer: Robert Collins
  • Date: 2007-07-04 08:08:13 UTC
  • mfrom: (2572 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2587.
  • Revision ID: robertc@robertcollins.net-20070704080813-wzebx0r88fvwj5rq
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2007 Canonical Ltd
 
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
"""Tests for commands related to tags"""
 
18
 
 
19
from bzrlib import bzrdir
 
20
from bzrlib.branch import (
 
21
    Branch,
 
22
    )
 
23
from bzrlib.bzrdir import BzrDir
 
24
from bzrlib.tests import TestCaseWithTransport
 
25
from bzrlib.repository import (
 
26
    Repository,
 
27
    )
 
28
from bzrlib.workingtree import WorkingTree
 
29
 
 
30
 
 
31
class TestTagging(TestCaseWithTransport):
 
32
 
 
33
    # as of 0.14, the default format doesn't do tags so we need to use a
 
34
    # specific format
 
35
    
 
36
    def make_branch_and_tree(self, relpath):
 
37
        format = bzrdir.format_registry.make_bzrdir('dirstate-with-subtree')
 
38
        return TestCaseWithTransport.make_branch_and_tree(self, relpath,
 
39
            format=format)
 
40
 
 
41
    def test_tag_command_help(self):
 
42
        out, err = self.run_bzr(['help', 'tag'])
 
43
        self.assertContainsRe(out, 'Create a tag')
 
44
 
 
45
    def test_cannot_tag_range(self):
 
46
        out, err = self.run_bzr('tag', '-r1..10', 'name', retcode=3)
 
47
        self.assertContainsRe(err,
 
48
            "Tags can only be placed on a single revision")
 
49
 
 
50
    def test_tag_current_rev(self):
 
51
        t = self.make_branch_and_tree('branch')
 
52
        t.commit(allow_pointless=True, message='initial commit',
 
53
            rev_id='first-revid')
 
54
        # make a tag through the command line
 
55
        out, err = self.run_bzr('tag', '-d', 'branch', 'NEWTAG')
 
56
        self.assertContainsRe(out, 'Created tag NEWTAG.')
 
57
        # tag should be observable through the api
 
58
        self.assertEquals(t.branch.tags.get_tag_dict(),
 
59
                dict(NEWTAG='first-revid'))
 
60
        # can also create tags using -r
 
61
        self.run_bzr('tag', '-d', 'branch', 'tag2', '-r1')
 
62
        self.assertEquals(t.branch.tags.lookup_tag('tag2'), 'first-revid')
 
63
        # regression test: make sure a unicode revision from the user
 
64
        # gets turned into a str object properly. The use of a unicode
 
65
        # object for the revid is intentional.
 
66
        self.run_bzr('tag', '-d', 'branch', 'tag3', u'-rrevid:first-revid')
 
67
        self.assertEquals(t.branch.tags.lookup_tag('tag3'), 'first-revid')
 
68
        # can also delete an existing tag
 
69
        out, err = self.run_bzr('tag', '--delete', '-d', 'branch', 'tag2')
 
70
        # cannot replace an existing tag normally
 
71
        out, err = self.run_bzr('tag', '-d', 'branch', 'NEWTAG', retcode=3)
 
72
        self.assertContainsRe(err, 'Tag NEWTAG already exists\\.')
 
73
        # ... but can if you use --force
 
74
        out, err = self.run_bzr('tag', '-d', 'branch', 'NEWTAG', '--force')
 
75
 
 
76
    def test_branch_push_pull_merge_copies_tags(self):
 
77
        t = self.make_branch_and_tree('branch1')
 
78
        t.commit(allow_pointless=True, message='initial commit',
 
79
            rev_id='first-revid')
 
80
        b1 = t.branch
 
81
        b1.tags.set_tag('tag1', 'first-revid')
 
82
        # branching copies the tag across
 
83
        self.run_bzr('branch', 'branch1', 'branch2')
 
84
        b2 = Branch.open('branch2')
 
85
        self.assertEquals(b2.tags.lookup_tag('tag1'), 'first-revid')
 
86
        # make a new tag and pull it
 
87
        b1.tags.set_tag('tag2', 'twa')
 
88
        self.run_bzr('pull', '-d', 'branch2', 'branch1')
 
89
        self.assertEquals(b2.tags.lookup_tag('tag2'), 'twa')
 
90
        # make a new tag and push it
 
91
        b1.tags.set_tag('tag3', 'san')
 
92
        self.run_bzr('push', '-d', 'branch1', 'branch2')
 
93
        self.assertEquals(b2.tags.lookup_tag('tag3'), 'san')
 
94
        # make a new tag and merge it
 
95
        t.commit(allow_pointless=True, message='second commit',
 
96
            rev_id='second-revid')
 
97
        t2 = WorkingTree.open('branch2')
 
98
        t2.commit(allow_pointless=True, message='commit in second')
 
99
        b1.tags.set_tag('tag4', 'second-revid')
 
100
        self.run_bzr('merge', '-d', 'branch2', 'branch1')
 
101
        self.assertEquals(b2.tags.lookup_tag('tag4'), 'second-revid')
 
102
        # pushing to a new location copies the tag across
 
103
        self.run_bzr('push', '-d', 'branch1', 'branch3')
 
104
        b3 = Branch.open('branch3')
 
105
        self.assertEquals(b3.tags.lookup_tag('tag1'), 'first-revid')
 
106
 
 
107
    def test_list_tags(self):
 
108
        t = self.make_branch_and_tree('branch1')
 
109
        b1 = t.branch
 
110
        tagname = u'\u30d0zaar'
 
111
        b1.tags.set_tag(tagname, 'revid-1')
 
112
        out, err = self.run_bzr('tags', '-d', 'branch1', encoding='utf-8')
 
113
        self.assertEquals(err, '')
 
114
        self.assertContainsRe(out,
 
115
            u'^\u30d0zaar  *revid-1\n'.encode('utf-8'))
 
116
 
 
117
    def test_conflicting_tags(self):
 
118
        # setup two empty branches with different tags
 
119
        t1 = self.make_branch_and_tree('one')
 
120
        t2 = self.make_branch_and_tree('two')
 
121
        b1 = t1.branch
 
122
        b2 = t2.branch
 
123
        tagname = u'\u30d0zaar'
 
124
        b1.tags.set_tag(tagname, 'revid1')
 
125
        b2.tags.set_tag(tagname, 'revid2')
 
126
        # push should give a warning about the tags
 
127
        out, err = self.run_bzr('push', '-d', 'one', 'two', encoding='utf-8')
 
128
        self.assertContainsRe(out,
 
129
                'Conflicting tags:\n.*' + tagname.encode('utf-8'))
 
130
        # pull should give a warning about the tags
 
131
        out, err = self.run_bzr('pull', '-d', 'one', 'two', encoding='utf-8')
 
132
        self.assertContainsRe(out,
 
133
                'Conflicting tags:\n.*' + tagname.encode('utf-8'))
 
134
        # merge should give a warning about the tags -- not implemented yet
 
135
        ## out, err = self.run_bzr('merge', '-d', 'one', 'two', encoding='utf-8')
 
136
        ## self.assertContainsRe(out,
 
137
        ##         'Conflicting tags:\n.*' + tagname.encode('utf-8'))