39
41
def set_pull_data(br, location, rev_id):
40
pull_file = file (br.controlfilename("pull-data"), "wb")
42
pull_file = file (br.controlfilename("x-pull-data"), "wb")
41
43
pull_file.write("%s\n%s\n" % (location, rev_id))
43
45
def get_pull_data(br):
50
52
('http://somewhere', '888-777')
53
filename = br.controlfilename("pull-data")
55
filename = br.controlfilename("x-pull-data")
54
56
if not os.path.exists(filename):
55
57
return (None, None)
56
58
pull_file = file (filename, "rb")
57
59
location, rev_id = [f.rstrip('\n') for f in pull_file]
58
60
return location, rev_id
60
if __name__ == "__main__":
63
>>> shell_escape('hello')
66
def shell_escape(arg):
67
return "".join(['\\'+c for c in arg])
69
def safe_system(args):
71
>>> real_system = os.system
72
>>> os.system = sys.stdout.write
73
>>> safe_system(['a', 'b', 'cd'])
75
>>> os.system = real_system
77
arg_str = " ".join([shell_escape(a) for a in args])
78
return os.system(arg_str)
80
def rsync(source, target):
82
>>> real_system = os.system
83
>>> os.system = sys.stdout.write
85
\\r\\s\\y\\n\\c \\-\\a\\v \\-\\-\\d\\e\\l\\e\\t\\e \\a \\b
86
>>> os.system = real_system
88
safe_system(("rsync", "-av", "--delete", source, target))
90
def pull(cur_branch, location=None):
91
pull_location, pull_revision = get_pull_data(cur_branch)
92
if pull_location is not None:
93
if cur_branch.last_patch() != pull_revision:
94
print "Aborting: This branch has had commits, so pull would lose data."
97
pull_location = sys.argv[1]
98
if not pull_location.endswith('/'):
99
pull_location.append('/')
101
if pull_location is None:
102
print "No pull location saved. Please specify one on the command line."
105
if not is_clean(cur_branch):
106
print "Error: This tree has uncommitted changes or unknown (?) files."
109
print "Synchronizing with %s" % pull_location
110
rsync (pull_location, cur_branch.base)
112
set_pull_data(cur_branch, pull_location, cur_branch.last_patch())
62
116
bzrlib.trace.create_tracefile([])
63
117
result = doctest.testmod()
64
if result[0] == 0 and result[1] > 0:
65
print "All tests passed"
120
print "All tests passed"
122
print "No tests to run"
123
if __name__ == "__main__":