1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
import bzrlib
import os.path
import tempfile
import shutil
def temp_branch():
dirname = tempfile.mkdtemp("temp-branch")
return bzrlib.Branch(dirname, init=True)
def rm_branch(br):
shutil.rmtree(br.base)
def is_clean(cur_branch):
"""
Return true if no files are modifed or unknown
>>> br = temp_branch()
>>> is_clean(br)
True
>>> fooname = os.path.join(br.base, "foo")
>>> file(fooname, "wb").write("bar")
>>> is_clean(br)
False
>>> bzrlib.add.smart_add([fooname])
>>> is_clean(br)
False
>>> br.commit("added file")
>>> is_clean(br)
True
>>> rm_branch(br)
"""
old_tree = cur_branch.basis_tree()
new_tree = cur_branch.working_tree()
for file_state, fid, old_name, new_name, kind in \
bzrlib.diff_trees(old_tree, new_tree):
if file_state not in ('I', '.'):
return False
return True
def set_pull_data(br, location, rev_id):
pull_file = file (br.controlfilename("pull-data"), "wb")
pull_file.write("%s\n%s\n" % (location, rev_id))
def get_pull_data(br):
"""
>>> br = temp_branch()
>>> get_pull_data(br)
(None, None)
>>> set_pull_data(br, 'http://somewhere', '888-777')
>>> get_pull_data(br)
('http://somewhere', '888-777')
>>> rm_branch(br)
"""
filename = br.controlfilename("pull-data")
if not os.path.exists(filename):
return (None, None)
pull_file = file (filename, "rb")
location, rev_id = [f.rstrip('\n') for f in pull_file]
return location, rev_id
if __name__ == "__main__":
import doctest
bzrlib.trace.create_tracefile([])
result = doctest.testmod()
if result[0] == 0 and result[1] > 0:
print "All tests passed"
|