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