1
# Copyright (C) 2008-2012 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""Upload a working tree, incrementally.
22
To get started, it's as simple as running::
24
brz upload sftp://user@host/location/on/webserver
26
This will initially upload the whole working tree, and leave a file on the
27
remote location indicating the last revision that was uploaded
28
(.bzr-upload.revid), in order to avoid uploading unnecessary information the
31
If you would like to upload a specific revision, you just do:
33
brz upload -r X sftp://user@host/location/on/webserver
35
bzr-upload, just as brz does, will remember the location where you upload the
36
first time, so you don't need to specify it every time.
38
If you need to re-upload the whole working tree for some reason, you can:
40
brz upload --full sftp://user@host/location/on/webserver
42
This command only works on the revision beening uploaded is a decendent of the
43
revision that was previously uploaded, and that they are hence from branches
44
that have not diverged. Branches are considered diverged if the destination
45
branch's most recent commit is one that has not been merged (directly or
46
indirectly) by the source branch.
48
If branches have diverged, you can use 'brz upload --overwrite' to replace
49
the other branch completely, discarding its unmerged changes.
52
Automatically Uploading
53
-----------------------
55
bzr-upload comes with a hook that can be used to trigger an upload whenever
56
the tip of the branch changes, including on commit, push, uncommit etc. This
57
would allow you to keep the code on the target up to date automatically.
59
The easiest way to enable this is to run upload with the --auto option.
63
will enable the hook for this branch. If you were to do a commit in this branch
64
now you would see it trigger the upload automatically.
66
If you wish to disable this for a branch again then you can use the --no-auto
71
will disable the feature for that branch.
73
Since the auto hook is triggered automatically, you can't use the --quiet
74
option available for the upload command. Instead, you can set the
75
'upload_auto_quiet' configuration variable to True or False in either
76
bazaar.conf, locations.conf or branch.conf.
79
Storing the '.bzr-upload.revid' file
80
------------------------------------
82
The only bzr-related info uploaded with the working tree is the corresponding
83
revision id. The uploaded working tree is not linked to any other brz data.
85
If the layout of your remote server is such that you can't write in the
86
root directory but only in the directories inside that root, you will need
87
to use the 'upload_revid_location' configuration variable to specify the
88
relative path to be used. That configuration variable can be specified in
89
locations.conf or branch.conf.
91
For example, given the following layout:
97
you may have write access in 'private' and 'public' but in 'Project'
98
itself. In that case, you can add the following in your locations.conf or
101
upload_revid_location = private/.bzr-upload.revid
104
Upload from Remote Location
105
---------------------------
107
It is possible to upload to a remote location from another remote location by
108
specifying it with the --directory option:
110
brz upload ftp://public.example.com --directory sftp://private.example.com
112
This, together with --auto, can be used to upload when you push to your
113
central branch, rather than when you commit to your local branch.
115
Note that you will consume more bandwith this way than uploading from a local
118
Ignoring certain files
119
-----------------------
121
If you want to version a file, but not upload it, you can create a file called
122
.bzrignore-upload, which works in the same way as the regular .bzrignore file,
123
but only applies to bzr-upload.
129
While we don't have any platform setup, you can branch from trunk:
131
brz branch lp:bzr-upload
133
And change anything you'd like, and file a merge proposal on Launchpad.
139
* Symlinks are not supported (warnings are emitted when they are encountered).
144
from __future__ import absolute_import
146
# TODO: the chmod bits *can* be supported via the upload protocols
147
# (i.e. poorly), but since the web developers use these protocols to upload
148
# manually, it is expected that the associated web server is coherent with
149
# their presence/absence. In other words, if a web hosting provider requires
150
# chmod bits but don't provide an ftp server that support them, well, better
151
# find another provider ;-)
153
# TODO: The message emitted in verbose mode displays local paths. That may be
154
# scary for the user when we say 'Deleting <path>' and are referring to
165
from ...hooks import install_lazy_named_hook
167
from ... import version_info
170
def register_option(key, member):
171
"""Lazily register an option."""
172
config.option_registry.register_lazy(
173
key, 'breezy.plugins.upload.cmds', member)
176
register_option('upload_auto', 'auto_option')
177
register_option('upload_auto_quiet', 'auto_quiet_option')
178
register_option('upload_location', 'location_option')
179
register_option('upload_revid_location', 'revid_location_option')
182
commands.plugin_cmds.register_lazy(
183
'cmd_upload', [], 'breezy.plugins.upload.cmds')
186
def auto_upload_hook(params):
197
source_branch = params.branch
198
conf = source_branch.get_config_stack()
199
destination = conf.get('upload_location')
200
if destination is None:
202
auto_upload = conf.get('upload_auto')
205
quiet = conf.get('upload_auto_quiet')
207
display_url = urlutils.unescape_for_display(
208
destination, osutils.get_terminal_encoding())
209
trace.note('Automatically uploading to %s', display_url)
210
to_transport = transport.get_transport(destination)
211
last_revision = source_branch.last_revision()
212
last_tree = source_branch.repository.revision_tree(last_revision)
213
uploader = BzrUploader(source_branch, to_transport, sys.stdout,
214
last_tree, last_revision, quiet=quiet)
215
uploader.upload_tree()
218
def install_auto_upload_hook():
219
hooks.install_lazy_named_hook(
220
'breezy.branch', 'Branch.hooks',
221
'post_change_branch_tip', auto_upload_hook,
222
'Auto upload code from a branch when it is changed.')
225
install_auto_upload_hook()
228
def load_tests(loader, basic_tests, pattern):
229
# This module shouldn't define any tests but I don't know how to report
230
# that. I prefer to update basic_tests with the other tests to detect
231
# unwanted tests and I think that's sufficient.
236
basic_tests.addTest(loader.loadTestsFromModuleNames(
237
["%s.%s" % (__name__, tmn) for tmn in testmod_names]))