3301
class cmd_merge_directive(Command):
3302
"""Generate a merge directive for auto-merge tools.
3304
A directive requests a merge to be performed, and also provides all the
3305
information necessary to do so. This means it must either include a
3306
revision bundle, or the location of a branch containing the desired
3309
A submit branch (the location to merge into) must be supplied the first
3310
time the command is issued. After it has been supplied once, it will
3311
be remembered as the default.
3313
A public branch is optional if a revision bundle is supplied, but required
3314
if --diff or --plain is specified. It will be remembered as the default
3315
after the first use.
3318
takes_args = ['submit_branch?', 'public_branch?']
3321
RegistryOption.from_kwargs('patch-type',
3322
'The type of patch to include in the directive',
3323
title='Patch type', value_switches=True, enum_switch=False,
3324
bundle='Bazaar revision bundle (default)',
3325
diff='Normal unified diff',
3326
plain='No patch, just directive'),
3327
Option('sign', help='GPG-sign the directive'), 'revision',
3328
Option('mail-to', type=str,
3329
help='Instead of printing the directive, email to this address'),
3330
Option('message', type=str, short_name='m',
3331
help='Message to use when committing this merge')
3334
def run(self, submit_branch=None, public_branch=None, patch_type='bundle',
3335
sign=False, revision=None, mail_to=None, message=None):
3336
if patch_type == 'plain':
3338
branch = Branch.open('.')
3339
stored_submit_branch = branch.get_submit_branch()
3340
if submit_branch is None:
3341
submit_branch = stored_submit_branch
3343
if stored_submit_branch is None:
3344
branch.set_submit_branch(submit_branch)
3345
if submit_branch is None:
3346
submit_branch = branch.get_parent()
3347
if submit_branch is None:
3348
raise errors.BzrCommandError('No submit branch specified or known')
3350
stored_public_branch = branch.get_public_branch()
3351
if public_branch is None:
3352
public_branch = stored_public_branch
3353
elif stored_public_branch is None:
3354
branch.set_public_branch(public_branch)
3355
if patch_type != "bundle" and public_branch is None:
3356
raise errors.BzrCommandError('No public branch specified or'
3358
if revision is not None:
3359
if len(revision) != 1:
3360
raise errors.BzrCommandError('bzr merge-directive takes '
3361
'exactly one revision identifier')
3363
revision_id = revision[0].in_history(branch).rev_id
3365
revision_id = branch.last_revision()
3366
directive = merge_directive.MergeDirective.from_objects(
3367
branch.repository, revision_id, time.time(),
3368
osutils.local_time_offset(), submit_branch,
3369
public_branch=public_branch, patch_type=patch_type,
3373
self.outf.write(directive.to_signed(branch))
3375
self.outf.writelines(directive.to_lines())
3377
message = directive.to_email(mail_to, branch, sign)
3379
server = branch.get_config().get_user_option('smtp_server')
3381
server = 'localhost'
3383
s.sendmail(message['From'], message['To'], message.as_string())
3295
3386
class cmd_tag(Command):
3296
3387
"""Create a tag naming a revision.