1
# Copyright (C) 2009, 2010 Canonical Ltd
1
# Copyright (C) 2009 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
79
79
if mail_to is None or format is None:
80
# TODO: jam 20090716 we open the submit_branch here, but we *don't*
81
# pass it down into the format creation, so it will have to
83
80
submit_br = Branch.open(submit_branch)
84
81
submit_config = submit_br.get_config()
85
82
if mail_to is None:
110
107
if len(revision) == 2:
111
108
base_revision_id = revision[0].as_revision_id(branch)
112
109
if revision_id is None:
114
tree.check_changed_or_out_of_date(
115
strict, 'send_strict',
116
more_error='Use --no-strict to force the send.',
117
more_warning='Uncommitted changes will not be sent.')
111
strict = branch.get_config().get_user_option('send_strict')
112
if strict is not None:
113
# FIXME: This should be better supported by config
115
bools = dict(yes=True, no=False, on=True, off=False,
116
true=True, false=False)
118
strict = bools[strict.lower()]
121
if tree is not None and (strict is None or strict):
122
if (tree.has_changes(tree.basis_tree())
123
or len(tree.get_parent_ids()) > 1):
124
raise errors.UncommittedChanges(
125
tree, more='Use --no-strict to force the send.')
126
if tree.last_revision() != tree.branch.last_revision():
127
# The tree has lost sync with its branch, there is little
128
# chance that the user is aware of it but he can still force
129
# the push with --no-strict
130
raise errors.OutOfDateTree(
131
tree, more='Use --no-strict to force the send.')
118
132
revision_id = branch.last_revision()
119
133
if revision_id == NULL_REVISION:
120
134
raise errors.BzrCommandError('No revisions to submit.')
121
135
if format is None:
136
# TODO: Query submit branch for its preferred format
122
137
format = format_registry.get()
123
138
directive = format(branch, revision_id, submit_branch,
124
139
public_branch, no_patch, no_bundle, message, base_revision_id)
126
141
directive.compose_merge_request(mail_client, mail_to, body,
129
if directive.multiple_output_files:
131
raise errors.BzrCommandError('- not supported for '
132
'merge directives that use more than one output file.')
133
if not os.path.exists(output):
134
os.mkdir(output, 0755)
135
for (filename, lines) in directive.to_files():
136
path = os.path.join(output, filename)
137
outfile = open(path, 'wb')
139
outfile.writelines(lines)
146
outfile = open(output, 'wb')
148
outfile.writelines(directive.to_lines())
150
if outfile is not to_file:
147
outfile = open(output, 'wb')
149
outfile.writelines(directive.to_lines())
151
if outfile is not to_file:
156
157
def _send_4(branch, revision_id, submit_branch, public_branch,
157
158
no_patch, no_bundle, message, base_revision_id):
158
from bzrlib import merge_directive
159
159
return merge_directive.MergeDirective2.from_objects(
160
160
branch.repository, revision_id, time.time(),
161
161
osutils.local_time_offset(), submit_branch,
177
177
patch_type = 'diff'
179
179
patch_type = None
180
from bzrlib import merge_directive
181
180
return merge_directive.MergeDirective.from_objects(
182
181
branch.repository, revision_id, time.time(),
183
182
osutils.local_time_offset(), submit_branch,