50
52
mail_client = config.get_mail_client()
51
53
if (not getattr(mail_client, 'supports_body', False)
52
54
and body is not None):
53
raise errors.BzrCommandError(
54
'Mail client "%s" does not support specifying body' %
55
raise errors.BzrCommandError(gettext(
56
'Mail client "%s" does not support specifying body') %
55
57
mail_client.__class__.__name__)
56
58
if remember and submit_branch is None:
57
raise errors.BzrCommandError(
58
'--remember requires a branch to be specified.')
59
raise errors.BzrCommandError(gettext(
60
'--remember requires a branch to be specified.'))
59
61
stored_submit_branch = branch.get_submit_branch()
60
62
remembered_submit_branch = None
61
63
if submit_branch is None:
62
64
submit_branch = stored_submit_branch
63
65
remembered_submit_branch = "submit"
65
if stored_submit_branch is None or remember:
67
# Remembers if asked explicitly or no previous location is set
68
if remember or (remember is None and stored_submit_branch is None):
66
69
branch.set_submit_branch(submit_branch)
67
70
if submit_branch is None:
68
71
submit_branch = branch.get_parent()
69
72
remembered_submit_branch = "parent"
70
73
if submit_branch is None:
71
raise errors.BzrCommandError('No submit branch known or'
74
raise errors.BzrCommandError(gettext('No submit branch known or'
73
76
if remembered_submit_branch is not None:
74
trace.note('Using saved %s location "%s" to determine what '
75
'changes to submit.', remembered_submit_branch,
77
trace.note(gettext('Using saved {0} location "{1}" to determine '
78
'what changes to submit.').format(
79
remembered_submit_branch, submit_branch))
78
81
if mail_to is None or format is None:
79
82
# TODO: jam 20090716 we open the submit_branch here, but we *don't*
89
92
format = format_registry.get(formatname)
91
raise errors.BzrCommandError("No such send format '%s'." %
94
raise errors.BzrCommandError(gettext("No such send format '%s'.") %
94
97
stored_public_branch = branch.get_public_branch()
95
98
if public_branch is None:
96
99
public_branch = stored_public_branch
97
elif stored_public_branch is None or remember:
100
# Remembers if asked explicitly or no previous location is set
102
or (remember is None and stored_public_branch is None)):
98
103
branch.set_public_branch(public_branch)
99
104
if no_bundle and public_branch is None:
100
raise errors.BzrCommandError('No public branch specified or'
105
raise errors.BzrCommandError(gettext('No public branch specified or'
102
107
base_revision_id = None
103
108
revision_id = None
104
109
if revision is not None:
105
110
if len(revision) > 2:
106
raise errors.BzrCommandError('bzr send takes '
107
'at most two one revision identifiers')
111
raise errors.BzrCommandError(gettext('bzr send takes '
112
'at most two one revision identifiers'))
108
113
revision_id = revision[-1].as_revision_id(branch)
109
114
if len(revision) == 2:
110
115
base_revision_id = revision[0].as_revision_id(branch)
111
116
if revision_id is None:
113
strict = branch.get_config(
114
).get_user_option_as_bool('send_strict')
115
if strict is None: strict = True # default value
116
if strict and tree is not None:
117
if (tree.has_changes()):
118
raise errors.UncommittedChanges(
119
tree, more='Use --no-strict to force the send.')
120
if tree.last_revision() != tree.branch.last_revision():
121
# The tree has lost sync with its branch, there is little
122
# chance that the user is aware of it but he can still force
123
# the send with --no-strict
124
raise errors.OutOfDateTree(
125
tree, more='Use --no-strict to force the send.')
118
tree.check_changed_or_out_of_date(
119
strict, 'send_strict',
120
more_error='Use --no-strict to force the send.',
121
more_warning='Uncommitted changes will not be sent.')
126
122
revision_id = branch.last_revision()
127
123
if revision_id == NULL_REVISION:
128
raise errors.BzrCommandError('No revisions to submit.')
124
raise errors.BzrCommandError(gettext('No revisions to submit.'))
129
125
if format is None:
130
126
format = format_registry.get()
131
127
directive = format(branch, revision_id, submit_branch,
134
130
directive.compose_merge_request(mail_client, mail_to, body,
133
if directive.multiple_output_files:
135
raise errors.BzrCommandError(gettext('- not supported for '
136
'merge directives that use more than one output file.'))
137
if not os.path.exists(output):
138
os.mkdir(output, 0755)
139
for (filename, lines) in directive.to_files():
140
path = os.path.join(output, filename)
141
outfile = open(path, 'wb')
143
outfile.writelines(lines)
140
outfile = open(output, 'wb')
142
outfile.writelines(directive.to_lines())
144
if outfile is not to_file:
150
outfile = open(output, 'wb')
152
outfile.writelines(directive.to_lines())
154
if outfile is not to_file: