~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Martin Pool
  • Date: 2007-02-26 05:29:05 UTC
  • mto: This revision was merged to the branch mainline in revision 2309.
  • Revision ID: mbp@sourcefrog.net-20070226052905-7mt8m6871e9dym8e
Tag command refuses to replace existing tags unless you force it.

Add Tags.has_tag.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3181
3181
 
3182
3182
    Tags are stored in the branch.  Tags are copied from one branch to another
3183
3183
    along when you branch, push, pull or merge.
 
3184
 
 
3185
    It is an error to give a tag name that already exists unless you pass 
 
3186
    --force, in which case the tag is moved to point to the new revision.
3184
3187
    """
3185
3188
 
3186
3189
    takes_args = ['tag_name']
3187
3190
    takes_options = [
3188
 
        Option('directory',
3189
 
            help='branch in which to place the tag',
3190
 
            short_name='d',
3191
 
            type=unicode,
3192
 
            ),
3193
3191
        Option('delete',
3194
 
            help='Delete this tag rather than placing it',
 
3192
            help='Delete this tag rather than placing it.',
 
3193
            ),
 
3194
        Option('directory',
 
3195
            help='Branch in which to place the tag.',
 
3196
            short_name='d',
 
3197
            type=unicode,
 
3198
            ),
 
3199
        Option('force',
 
3200
            help='Replace existing tags',
3195
3201
            ),
3196
3202
        'revision',
3197
3203
        ]
3198
3204
 
3199
 
    def run(self, tag_name, directory='.',
 
3205
    def run(self, tag_name,
 
3206
            delete=None,
 
3207
            directory='.',
 
3208
            force=None,
3200
3209
            revision=None,
3201
 
            delete=None):
 
3210
            ):
3202
3211
        branch, relpath = Branch.open_containing(directory)
3203
 
        if delete:
3204
 
            branch.tags.delete_tag(tag_name)
3205
 
            self.outf.write('deleted tag %s' % tag_name)
3206
 
        else:
3207
 
            if revision:
3208
 
                if len(revision) != 1:
3209
 
                    raise errors.BzrCommandError(
3210
 
                        "Tags can only be placed on a single revision, "
3211
 
                        "not on a range")
3212
 
                revision_id = revision[0].in_history(branch).rev_id
 
3212
        branch.lock_write()
 
3213
        try:
 
3214
            if delete:
 
3215
                branch.tags.delete_tag(tag_name)
 
3216
                self.outf.write('Deleted tag %s.\n' % tag_name)
3213
3217
            else:
3214
 
                revision_id = branch.last_revision()
3215
 
            branch.tags.set_tag(tag_name, revision_id)
3216
 
            self.outf.write('created tag %s' % tag_name)
 
3218
                if revision:
 
3219
                    if len(revision) != 1:
 
3220
                        raise errors.BzrCommandError(
 
3221
                            "Tags can only be placed on a single revision, "
 
3222
                            "not on a range")
 
3223
                    revision_id = revision[0].in_history(branch).rev_id
 
3224
                else:
 
3225
                    revision_id = branch.last_revision()
 
3226
                if (not force) and branch.tags.has_tag(tag_name):
 
3227
                    raise errors.TagAlreadyExists(tag_name)
 
3228
                branch.tags.set_tag(tag_name, revision_id)
 
3229
                self.outf.write('Created tag %s.\n' % tag_name)
 
3230
        finally:
 
3231
            branch.unlock()
3217
3232
 
3218
3233
 
3219
3234
class cmd_tags(Command):