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
>>> br.working_tree().add(["foo"])
48
>>> bzrlib.add.smart_add_tree(tree, [tree.basedir])
50
>>> br.working_tree().commit("added file")
52
>>> tree.commit("added file")
55
57
from bzrlib.diff import compare_trees
56
old_tree = cur_branch.basis_tree()
57
new_tree = cur_branch.working_tree()
58
old_tree = cur_tree.basis_tree()
59
61
for path, file_class, kind, file_id, entry in new_tree.list_files():
60
62
if file_class in ('?', 'I'):
62
64
delta = compare_trees(old_tree, new_tree, want_unchanged=False)
63
65
return not delta.has_changed(), non_source
65
def set_push_data(br, location):
66
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")
67
69
push_file.write("%s\n" % location)
69
def get_push_data(br):
71
def get_push_data(tree):
71
>>> br = temp_branch()
72
>>> get_push_data(br) is None
73
>>> tree = temp_tree()
74
>>> get_push_data(tree) is None
74
>>> set_push_data(br, 'http://somewhere')
76
>>> set_push_data(tree, 'http://somewhere')
77
>>> get_push_data(tree)
79
filename = br.control_files.controlfilename("x-push-data")
81
filename = tree._control_files.controlfilename("x-push-data")
80
82
if not os.path.exists(filename):
82
84
push_file = file (filename, "rb")
112
114
def rsync(source, target, ssh=False, excludes=(), silent=False,
113
115
rsync_name="rsync"):
117
>>> new_dir = tempfile.mkdtemp()
118
>>> old_dir = os.getcwd()
119
>>> os.chdir(new_dir)
115
120
>>> rsync("a", "b", silent=True)
116
121
Traceback (most recent call last):
117
122
RsyncNoFile: No such file a
121
126
>>> rsync("a", "b", excludes=("*.py",), silent=True, rsync_name="rsyncc")
122
127
Traceback (most recent call last):
123
128
NoRsync: rsyncc not found.
129
>>> os.chdir(old_dir)
130
>>> os.rmdir(new_dir)
125
132
cmd = [rsync_name, "-av", "--delete"]
226
233
except RsyncNoFile:
229
def push(cur_branch, location=None, overwrite=False, working_tree=True):
230
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)
231
238
if location is not None:
232
239
if not location.endswith('/'):
242
249
if push_location.find(':') == -1:
243
250
raise bzrlib.errors.MustUseDecorated
245
clean, non_source = is_clean(cur_branch)
252
clean, non_source = is_clean(tree)
247
254
print """Error: This tree has uncommitted changes or unknown (?) files.
248
255
Use "bzr status" to list them."""
251
258
final_exclusions = non_source[:]
253
wt = cur_branch.working_tree()
254
261
final_exclusions = []
255
262
for path, status, kind, file_id, entry in wt.list_files():
256
263
final_exclusions.append(path)
258
265
final_exclusions.extend(exclusions)
259
266
if not overwrite:
261
if not history_subset(push_location, cur_branch):
268
if not history_subset(push_location, tree.branch):
262
269
raise bzrlib.errors.BzrCommandError("Local branch is not a"
263
270
" newer version of remote"
272
279
" specified location. Please ensure that"
273
280
' "%s" is of the form "machine:/path".' % push_location)
274
281
print "Pushing to %s" % push_location
275
rsync(cur_branch.base+'/', push_location, ssh=True,
282
rsync(tree.basedir+'/', push_location, ssh=True,
276
283
excludes=final_exclusions)
278
set_push_data(cur_branch, push_location)
285
set_push_data(tree, push_location)
280
287
def short_committer(committer):
281
288
new_committer = re.sub('<.*>', '', committer).strip(' ')