14
14
# You should have received a copy of the GNU General Public License
15
15
# along with this program; if not, write to the Free Software
16
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
25
from subprocess import Popen, PIPE
28
from bzrlib.errors import BzrCommandError
29
from bzrlib.bzrdir import BzrDir
32
30
dirname = tempfile.mkdtemp("temp-branch")
33
return BzrDir.create_standalone_workingtree(dirname)
36
shutil.rmtree(tree.basedir)
38
def is_clean(cur_tree):
31
return bzrlib.branch.Branch.initialize(dirname)
34
shutil.rmtree(br.base)
36
def is_clean(cur_branch):
40
38
Return true if no files are modifed or unknown
41
39
>>> import bzrlib.add
42
>>> tree = temp_tree()
40
>>> br = temp_branch()
45
>>> fooname = os.path.join(tree.basedir, "foo")
43
>>> fooname = os.path.join(br.base, "foo")
46
44
>>> file(fooname, "wb").write("bar")
49
>>> bzrlib.add.smart_add_tree(tree, [tree.basedir])
47
>>> bzrlib.add.smart_add_tree(br.working_tree(), [br.base])
53
>>> tree.commit("added file")
51
>>> br.working_tree().commit("added file")
58
56
from bzrlib.diff import compare_trees
59
old_tree = cur_tree.basis_tree()
57
old_tree = cur_branch.basis_tree()
58
new_tree = cur_branch.working_tree()
62
60
for path, file_class, kind, file_id, entry in new_tree.list_files():
63
61
if file_class in ('?', 'I'):
65
63
delta = compare_trees(old_tree, new_tree, want_unchanged=False)
66
64
return not delta.has_changed(), non_source
68
def set_push_data(tree, location):
69
push_file = file (tree._control_files.controlfilename("x-push-data"), "wb")
66
def set_push_data(br, location):
67
push_file = file (br.control_files.controlfilename("x-push-data"), "wb")
70
68
push_file.write("%s\n" % location)
72
def get_push_data(tree):
70
def get_push_data(br):
74
>>> tree = temp_tree()
75
>>> get_push_data(tree) is None
72
>>> br = temp_branch()
73
>>> get_push_data(br) is None
77
>>> set_push_data(tree, 'http://somewhere')
78
>>> get_push_data(tree)
75
>>> set_push_data(br, 'http://somewhere')
82
filename = tree._control_files.controlfilename("x-push-data")
80
filename = br.control_files.controlfilename("x-push-data")
83
81
if not os.path.exists(filename):
85
83
push_file = file (filename, "rb")
115
113
def rsync(source, target, ssh=False, excludes=(), silent=False,
116
114
rsync_name="rsync"):
118
>>> new_dir = tempfile.mkdtemp()
119
>>> old_dir = os.getcwd()
120
>>> os.chdir(new_dir)
121
116
>>> rsync("a", "b", silent=True)
122
117
Traceback (most recent call last):
123
RsyncNoFile: No such file...
124
>>> rsync(new_dir + "/a", new_dir + "/b", excludes=("*.py",), silent=True)
118
RsyncNoFile: No such file a
119
>>> rsync("a", "b", excludes=("*.py",), silent=True)
125
120
Traceback (most recent call last):
126
RsyncNoFile: No such file...
127
>>> rsync(new_dir + "/a", new_dir + "/b", excludes=("*.py",), silent=True, rsync_name="rsyncc")
121
RsyncNoFile: No such file a
122
>>> rsync("a", "b", excludes=("*.py",), silent=True, rsync_name="rsyncc")
128
123
Traceback (most recent call last):
129
124
NoRsync: rsyncc not found.
130
>>> os.chdir(old_dir)
131
>>> os.rmdir(new_dir)
133
126
cmd = [rsync_name, "-av", "--delete"]
192
185
exclusions = ('.bzr/x-push-data', '.bzr/parent', '.bzr/x-pull-data',
193
186
'.bzr/x-pull', '.bzr/pull', '.bzr/stat-cache',
194
'.bzr/x-rsync-data', '.bzr/basis-inventory',
195
'.bzr/inventory.backup.weave')
198
190
def read_revision_history(fname):
235
227
except RsyncNoFile:
238
def push(tree, location=None, overwrite=False, working_tree=True):
239
push_location = get_push_data(tree)
230
def push(cur_branch, location=None, overwrite=False, working_tree=True):
231
push_location = get_push_data(cur_branch)
240
232
if location is not None:
241
233
if not location.endswith('/'):
243
235
push_location = location
245
237
if push_location is None:
246
if tree.branch.get_push_location() is None:
247
raise BzrCommandError("No push location known or specified.")
249
raise bzrlib.errors.MustUseDecorated
238
raise bzrlib.errors.MustUseDecorated
251
240
if push_location.find('://') != -1:
252
241
raise bzrlib.errors.MustUseDecorated
254
243
if push_location.find(':') == -1:
255
244
raise bzrlib.errors.MustUseDecorated
257
clean, non_source = is_clean(tree)
246
clean, non_source = is_clean(cur_branch)
259
248
print """Error: This tree has uncommitted changes or unknown (?) files.
260
249
Use "bzr status" to list them."""
263
252
final_exclusions = non_source[:]
254
wt = cur_branch.working_tree()
266
255
final_exclusions = []
267
256
for path, status, kind, file_id, entry in wt.list_files():
268
257
final_exclusions.append(path)
270
259
final_exclusions.extend(exclusions)
271
260
if not overwrite:
273
if not history_subset(push_location, tree.branch):
262
if not history_subset(push_location, cur_branch):
274
263
raise bzrlib.errors.BzrCommandError("Local branch is not a"
275
264
" newer version of remote"
284
273
" specified location. Please ensure that"
285
274
' "%s" is of the form "machine:/path".' % push_location)
286
275
print "Pushing to %s" % push_location
287
rsync(tree.basedir+'/', push_location, ssh=True,
276
rsync(cur_branch.base+'/', push_location, ssh=True,
288
277
excludes=final_exclusions)
290
set_push_data(tree, push_location)
279
set_push_data(cur_branch, push_location)
293
281
def short_committer(committer):
294
282
new_committer = re.sub('<.*>', '', committer).strip(' ')