1
by mbp at sourcefrog
import from baz patch-364 |
1 |
#! /usr/bin/env python
|
2 |
# -*- coding: UTF-8 -*-
|
|
3 |
||
4 |
# This program is free software; you can redistribute it and/or modify
|
|
5 |
# it under the terms of the GNU General Public License as published by
|
|
6 |
# the Free Software Foundation; either version 2 of the License, or
|
|
7 |
# (at your option) any later version.
|
|
8 |
||
9 |
# This program is distributed in the hope that it will be useful,
|
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
# GNU General Public License for more details.
|
|
13 |
||
14 |
# You should have received a copy of the GNU General Public License
|
|
15 |
# along with this program; if not, write to the Free Software
|
|
16 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
17 |
||
18 |
||
19 |
||
20 |
# XXX: We might prefer these to be in a text file rather than Python
|
|
21 |
# source, but that only works in doctest from Python 2.4 and later,
|
|
22 |
# which is not present in Warty.
|
|
23 |
||
24 |
r""" |
|
25 |
Bazaar-NG test cases
|
|
26 |
********************
|
|
27 |
||
28 |
These are run by ``bzr.doctest``.
|
|
29 |
||
30 |
>>> import bzr, bzrlib, os
|
|
31 |
>>> bzr.cmd_rocks()
|
|
32 |
it sure does!
|
|
33 |
||
34 |
Hey, nice place to begin.
|
|
35 |
||
36 |
The basic object is a Branch. We have a special helper class
|
|
37 |
ScratchBranch that automatically makes a directory and cleans itself
|
|
38 |
up, but is in other respects identical.
|
|
39 |
||
40 |
ScratchBranches are initially empty:
|
|
41 |
||
42 |
>>> b = bzr.ScratchBranch()
|
|
43 |
>>> b.show_status()
|
|
44 |
||
45 |
New files in that directory are, it is initially unknown:
|
|
46 |
||
47 |
>>> file(b.base + '/hello.c', 'wt').write('int main() {}')
|
|
48 |
>>> b.show_status()
|
|
49 |
? hello.c
|
|
50 |
||
51 |
That's not quite true; some files (like editor backups) are ignored by
|
|
52 |
default:
|
|
53 |
||
54 |
>>> file(b.base + '/hello.c~', 'wt').write('int main() {}')
|
|
55 |
>>> b.show_status()
|
|
56 |
? hello.c
|
|
57 |
>>> list(b.unknowns())
|
|
58 |
['hello.c']
|
|
59 |
||
60 |
The ``add`` command marks a file to be added in the next revision:
|
|
61 |
||
62 |
>>> b.add('hello.c')
|
|
63 |
>>> b.show_status()
|
|
64 |
A hello.c
|
|
65 |
||
66 |
You can also add files that otherwise would be ignored. The ignore
|
|
67 |
patterns only apply to files that would be otherwise unknown, so they
|
|
68 |
have no effect once it's added.
|
|
69 |
||
70 |
>>> b.add('hello.c~')
|
|
71 |
>>> b.show_status()
|
|
72 |
A hello.c
|
|
73 |
A hello.c~
|
|
74 |
||
75 |
It is an error to add a file that isn't present in the working copy:
|
|
76 |
||
77 |
>>> b.add('nothere')
|
|
78 |
Traceback (most recent call last):
|
|
79 |
...
|
|
80 |
BzrError: ('cannot add: not a regular file or directory: nothere', [])
|
|
81 |
||
82 |
If we add a file and then change our mind, we can either revert it or
|
|
83 |
remove the file. If we revert, we are left with the working copy (in
|
|
84 |
either I or ? state). If we remove, the working copy is gone. Let's
|
|
85 |
do that to the backup, presumably added accidentally.
|
|
86 |
||
87 |
>>> b.remove('hello.c~')
|
|
88 |
>>> b.show_status()
|
|
89 |
A hello.c
|
|
90 |
||
91 |
Now to commit, creating a new revision. (Fake the date and name for
|
|
92 |
reproducibility.)
|
|
93 |
||
94 |
>>> b.commit('start hello world', timestamp=0, committer='foo@nowhere')
|
|
95 |
>>> b.show_status()
|
|
96 |
>>> b.show_status(show_all=True)
|
|
97 |
. hello.c
|
|
98 |
I hello.c~
|
|
99 |
||
100 |
||
101 |
We can look back at history
|
|
102 |
||
103 |
>>> r = b.get_revision(b.lookup_revision(1))
|
|
104 |
>>> r.message
|
|
105 |
'start hello world'
|
|
106 |
>>> b.write_log(utc=True)
|
|
107 |
----------------------------------------
|
|
108 |
revno: 1
|
|
109 |
committer: foo@nowhere
|
|
110 |
timestamp: Thu 1970-01-01 00:00:00 UTC +0000
|
|
111 |
message:
|
|
112 |
start hello world
|
|
113 |
||
114 |
(The other fields will be a bit unpredictable, depending on who ran
|
|
115 |
this test and when.)
|
|
116 |
||
117 |
As of 2005-02-21, we can also add subdirectories to the revision!
|
|
118 |
||
119 |
>>> os.mkdir(b.base + "/lib")
|
|
120 |
>>> b.show_status()
|
|
121 |
? lib/
|
|
122 |
>>> b.add('lib')
|
|
123 |
>>> b.show_status()
|
|
124 |
A lib/
|
|
125 |
>>> b.commit('add subdir')
|
|
126 |
>>> b.show_status()
|
|
127 |
>>> b.show_status(show_all=True)
|
|
128 |
. hello.c
|
|
129 |
I hello.c~
|
|
130 |
. lib/
|
|
131 |
||
132 |
and we can also add files within subdirectories:
|
|
133 |
||
134 |
>>> file(b.base + '/lib/hello', 'w').write('hello!\n')
|
|
135 |
>>> b.show_status()
|
|
136 |
? lib/hello
|
|
137 |
|
|
138 |
|
|
139 |
Tests for adding subdirectories, etc.
|
|
140 |
||
141 |
>>> b = bzrlib.branch.ScratchBranch()
|
|
142 |
>>> os.mkdir(b._rel('d1'))
|
|
143 |
>>> os.mkdir(b._rel('d2'))
|
|
144 |
>>> os.mkdir(b._rel('d2/d3'))
|
|
145 |
>>> list(b.working_tree().unknowns())
|
|
146 |
['d1', 'd2']
|
|
147 |
||
148 |
Create some files, but they're not seen as unknown yet:
|
|
149 |
||
150 |
>>> file(b._rel('d1/f1'), 'w').close()
|
|
151 |
>>> file(b._rel('d2/f2'), 'w').close()
|
|
152 |
>>> file(b._rel('d2/f3'), 'w').close()
|
|
153 |
>>> [v[0] for v in b.inventory.directories()]
|
|
154 |
['']
|
|
155 |
>>> list(b.working_tree().unknowns())
|
|
156 |
['d1', 'd2']
|
|
157 |
||
158 |
Adding a directory, and we see the file underneath:
|
|
159 |
|
|
160 |
>>> b.add('d1')
|
|
161 |
>>> [v[0] for v in b.inventory.directories()]
|
|
162 |
['', 'd1']
|
|
163 |
>>> list(b.working_tree().unknowns())
|
|
164 |
['d1/f1', 'd2']
|
|
165 |
>>> # d2 comes first because it's in the top directory
|
|
166 |
||
167 |
>>> b.add('d2')
|
|
168 |
>>> b.commit('add some stuff')
|
|
169 |
>>> list(b.working_tree().unknowns())
|
|
170 |
['d1/f1', 'd2/d3', 'd2/f2', 'd2/f3']
|
|
171 |
||
172 |
"""
|