3170
_directive_patch_type = registry.Registry()
3171
_directive_patch_type.register('bundle', 'bundle', 'Bazaar revision bundle')
3172
_directive_patch_type.register('diff', 'diff', 'Normal unified diff')
3173
_directive_patch_type.register('plain', None, 'No patch, just directive')
3169
3176
class cmd_merge_directive(Command):
3170
3177
"""Generate a merge directive auto-merge tools."""
3179
takes_args = ['submit_branch?', 'public_branch?']
3181
takes_options = [RegistryOption('patch-type',
3182
'The type of patch to include in the directive',
3183
_directive_patch_type, value_switches=True)]
3185
def run(self, submit_branch=None, public_branch=None, patch_type='bundle'):
3173
3186
branch = Branch.open('.')
3174
submit_branch = branch.get_submit_branch()
3175
public_branch = branch.get_config().get_user_option('public_branch')
3187
config_submit_branch = branch.get_submit_branch()
3188
if submit_branch is None:
3189
submit_branch = config_submit_branch
3191
if config_submit_branch is None:
3192
branch.set_submit_branch(submit_branch)
3193
if submit_branch is None:
3194
submit_branch = branch.get_parent()
3195
if submit_branch is None:
3196
raise errors.BzrCommandError('No submit branch specified or known')
3197
config_public_branch = branch.get_config().get_user_option(
3199
if public_branch is None:
3200
public_branch = config_public_branch
3201
elif config_public_branch is None:
3202
branch.get_config().set_user_option('public_branch', public_branch)
3176
3203
if public_branch is not None:
3177
3204
public_branch = Branch.open(public_branch)
3178
if submit_branch is None:
3179
submit_branch = branch.get_parent()
3205
if patch_type != "bundle" and public_branch is None:
3206
raise errors.BzrCommandError('No public branch specified or known')
3180
3207
directive = merge_directive.MergeDirective.from_objects(
3181
3208
branch.repository, branch.last_revision(), time.time(),
3182
3209
osutils.local_time_offset(), submit_branch,
3183
public_branch=public_branch)
3210
public_branch=public_branch, patch_type=patch_type)
3184
3211
self.outf.writelines(directive.to_lines())
3186
3214
# command-line interpretation helper for merge-related commands
3187
3215
def _merge_helper(other_revision, base_revision,
3188
3216
check_clean=True, ignore_zero=False,