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
25
23
from subprocess import Popen, PIPE
28
from bzrlib.bzrdir import BzrDir
30
31
dirname = tempfile.mkdtemp("temp-branch")
31
return bzrlib.branch.Branch.initialize(dirname)
34
shutil.rmtree(br.base)
36
def is_clean(cur_branch):
32
return BzrDir.create_standalone_workingtree(dirname)
35
shutil.rmtree(tree.basedir)
37
def is_clean(cur_tree):
38
39
Return true if no files are modifed or unknown
39
40
>>> import bzrlib.add
40
>>> br = temp_branch()
41
>>> tree = temp_tree()
43
>>> fooname = os.path.join(br.base, "foo")
44
>>> fooname = os.path.join(tree.basedir, "foo")
44
45
>>> file(fooname, "wb").write("bar")
47
>>> bzrlib.add.smart_add_tree(br.working_tree(), [br.base])
48
>>> bzrlib.add.smart_add_tree(tree, [tree.basedir])
51
>>> br.working_tree().commit("added file")
52
>>> tree.commit("added file")
56
57
from bzrlib.diff import compare_trees
57
old_tree = cur_branch.basis_tree()
58
new_tree = cur_branch.working_tree()
58
old_tree = cur_tree.basis_tree()
60
61
for path, file_class, kind, file_id, entry in new_tree.list_files():
61
62
if file_class in ('?', 'I'):
63
64
delta = compare_trees(old_tree, new_tree, want_unchanged=False)
64
65
return not delta.has_changed(), non_source
66
def set_push_data(br, location):
67
push_file = file (br.control_files.controlfilename("x-push-data"), "wb")
67
def set_push_data(tree, location):
68
push_file = file (tree._control_files.controlfilename("x-push-data"), "wb")
68
69
push_file.write("%s\n" % location)
70
def get_push_data(br):
71
def get_push_data(tree):
72
>>> br = temp_branch()
73
>>> get_push_data(br) is None
73
>>> tree = temp_tree()
74
>>> get_push_data(tree) is None
75
>>> set_push_data(br, 'http://somewhere')
76
>>> set_push_data(tree, 'http://somewhere')
77
>>> get_push_data(tree)
80
filename = br.control_files.controlfilename("x-push-data")
81
filename = tree._control_files.controlfilename("x-push-data")
81
82
if not os.path.exists(filename):
83
84
push_file = file (filename, "rb")
232
233
except RsyncNoFile:
235
def push(cur_branch, location=None, overwrite=False, working_tree=True):
236
push_location = get_push_data(cur_branch)
236
def push(tree, location=None, overwrite=False, working_tree=True):
237
push_location = get_push_data(tree)
237
238
if location is not None:
238
239
if not location.endswith('/'):
248
249
if push_location.find(':') == -1:
249
250
raise bzrlib.errors.MustUseDecorated
251
clean, non_source = is_clean(cur_branch)
252
clean, non_source = is_clean(tree)
253
254
print """Error: This tree has uncommitted changes or unknown (?) files.
254
255
Use "bzr status" to list them."""
257
258
final_exclusions = non_source[:]
259
wt = cur_branch.working_tree()
260
261
final_exclusions = []
261
262
for path, status, kind, file_id, entry in wt.list_files():
262
263
final_exclusions.append(path)
264
265
final_exclusions.extend(exclusions)
265
266
if not overwrite:
267
if not history_subset(push_location, cur_branch):
268
if not history_subset(push_location, tree.branch):
268
269
raise bzrlib.errors.BzrCommandError("Local branch is not a"
269
270
" newer version of remote"
278
279
" specified location. Please ensure that"
279
280
' "%s" is of the form "machine:/path".' % push_location)
280
281
print "Pushing to %s" % push_location
281
rsync(cur_branch.base+'/', push_location, ssh=True,
282
rsync(tree.bzrdir.transport.base+'/', push_location, ssh=True,
282
283
excludes=final_exclusions)
284
285
set_push_data(cur_branch, push_location)