2
# -*- coding: UTF-8 -*-
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.
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.
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
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.
28
These are run by ``bzr.doctest``.
30
>>> import bzr, bzrlib, os
31
>>> bzrlib.commands.cmd_rocks()
34
Hey, nice place to begin.
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.
40
ScratchBranches are initially empty:
42
>>> b = bzrlib.ScratchBranch()
45
New files in that directory are, it is initially unknown:
47
>>> file(b.base + '/hello.c', 'wt').write('int main() {}')
51
That's not quite true; some files (like editor backups) are ignored by
54
>>> file(b.base + '/hello.c~', 'wt').write('int main() {}')
57
>>> list(b.unknowns())
60
The ``add`` command marks a file to be added in the next revision:
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.
75
It is an error to add a file that isn't present in the working copy:
78
Traceback (most recent call last):
80
BzrError: ('cannot add: not a regular file or directory: nothere', [])
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.
87
>>> b.remove('hello.c~')
91
Now to commit, creating a new revision. (Fake the date and name for
94
>>> b.commit('start hello world', timestamp=0, committer='foo@nowhere')
96
>>> b.show_status(show_all=True)
101
We can look back at history
103
>>> r = b.get_revision(b.lookup_revision(1))
106
>>> b.write_log(show_timezone='utc')
107
----------------------------------------
109
committer: foo@nowhere
110
timestamp: Thu 1970-01-01 00:00:00 +0000
114
(The other fields will be a bit unpredictable, depending on who ran
117
As of 2005-02-21, we can also add subdirectories to the revision!
119
>>> os.mkdir(b.base + "/lib")
125
>>> b.commit('add subdir')
127
>>> b.show_status(show_all=True)
132
and we can also add files within subdirectories:
134
>>> file(b.base + '/lib/hello', 'w').write('hello!\n')
139
Tests for adding subdirectories, etc.
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())
148
Create some files, but they're not seen as unknown yet:
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()]
155
>>> list(b.working_tree().unknowns())
158
Adding a directory, and we see the file underneath:
161
>>> [v[0] for v in b.inventory.directories()]
163
>>> list(b.working_tree().unknowns())
165
>>> # d2 comes first because it's in the top directory
168
>>> b.commit('add some stuff')
169
>>> list(b.working_tree().unknowns())
170
['d1/f1', 'd2/d3', 'd2/f2', 'd2/f3']