49
50
from bzrlib.diff import compare_trees
50
51
old_tree = cur_branch.basis_tree()
51
52
new_tree = cur_branch.working_tree()
52
54
for path, file_class, kind, file_id in new_tree.list_files():
55
if file_class in ('?', 'I'):
56
non_source.append(path)
55
57
delta = compare_trees(old_tree, new_tree, want_unchanged=False)
56
58
if len(delta.added) > 0 or len(delta.removed) > 0 or \
57
59
len(delta.modified) > 0:
60
return False, non_source
61
return True, non_source
61
63
def set_pull_data(br, location, rev_id):
62
64
pull_file = file (br.controlfilename("x-pull-data"), "wb")
118
120
arg_str = " ".join([shell_escape(a) for a in args])
119
121
return os.system(arg_str)
121
def rsync(source, target, ssh=False, exclude_globs=()):
123
def rsync(source, target, ssh=False, excludes=()):
123
125
>>> real_system = os.system
124
126
>>> os.system = sys.stdout.write
125
127
>>> rsync("a", "b")
126
128
\\r\\s\\y\\n\\c \\-\\a\\v \\-\\-\\d\\e\\l\\e\\t\\e \\a \\b
127
>>> rsync("a", "b", exclude_globs=("*.py",))
129
>>> rsync("a", "b", excludes=("*.py",))
128
130
\\r\\s\\y\\n\\c \\-\\a\\v \\-\\-\\d\\e\\l\\e\\t\\e\
129
131
\\-\\-\\e\\x\\c\\l\\u\\d\\e \\*\\.\\p\\y \\a \\b
130
132
>>> os.system = real_system
132
134
cmd = ["rsync", "-av", "--delete"]
134
136
cmd.extend(('-e', 'ssh'))
135
for exclude in exclude_globs:
136
cmd.extend(('--exclude', exclude))
137
if len(excludes) > 0:
138
cmd.extend(('--exclude-from', '-'))
137
139
cmd.extend((source, target))
140
exclusions = ('x-push-data', 'x-pull-data')
143
def pull(cur_branch, location=None, overwrite=False):
144
pull_location, pull_revision = get_pull_data(cur_branch)
145
if pull_location is not None:
146
if not overwrite and cur_branch.last_patch() != pull_revision:
147
print "Aborting: This branch has had commits, so pull would lose data."
149
if location is not None:
150
pull_location = location
151
if not pull_location.endswith('/'):
154
if pull_location is None:
155
print "No pull location saved. Please specify one on the command line."
158
if not is_clean(cur_branch):
159
print "Error: This tree has uncommitted changes or unknown (?) files."
162
print "Synchronizing with %s" % pull_location
163
rsync (pull_location, cur_branch.base+'/', exclude_globs=exclusions)
165
set_pull_data(cur_branch, pull_location, cur_branch.last_patch())
140
proc = Popen(cmd, stdin=PIPE)
141
proc.stdin.write('\n'.join(excludes)+'\n')
145
exclusions = ('.bzr/x-push-data', '.bzr/x-pull-data', '.bzr/stat-cache')
168
148
def push(cur_branch, location=None):
176
156
print "No push location saved. Please specify one on the command line."
179
if not is_clean(cur_branch):
159
clean, non_source = is_clean(cur_branch)
180
161
print """Error: This tree has uncommitted changes or unknown (?) files.
181
162
Use "bzr status" to list them."""
164
non_source.extend(exclusions)
184
166
print "Pushing to %s" % push_location
185
rsync(cur_branch.base+'/', push_location, ssh=True,
186
exclude_globs=exclusions)
167
rsync(cur_branch.base+'/', push_location, ssh=True, excludes=non_source)
188
169
set_push_data(cur_branch, push_location)