bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
0.3.1
by John Arbash Meinel
Creating a plugin for uncommitting the last revision. |
1 |
#!/usr/bin/env python
|
2 |
"""\
|
|
3 |
Remove the last committed revision.
|
|
4 |
Does not modify the working tree, use 'bzr revert' for that.
|
|
5 |
"""
|
|
6 |
||
7 |
import bzrlib, bzrlib.commands |
|
8 |
||
9 |
class cmd_uncommit(bzrlib.commands.Command): |
|
10 |
"""Remove the last committed revision. |
|
11 |
||
12 |
By supplying the --remove flag, it will not only remove the entry
|
|
13 |
from revision_history, but also remove all of the entries in the
|
|
14 |
stores.
|
|
15 |
||
16 |
--verbose will print out what is being removed.
|
|
17 |
--dry-run will go through all the motions, but not actually
|
|
18 |
remove anything.
|
|
19 |
|
|
20 |
In the future, uncommit will create a changeset, which can then
|
|
21 |
be re-applied.
|
|
22 |
"""
|
|
|
0.3.6
by John Arbash Meinel
Adding ability to revert back to earlier revisions. |
23 |
takes_options = ['remove', 'dry-run', 'verbose', 'revision'] |
|
0.3.1
by John Arbash Meinel
Creating a plugin for uncommitting the last revision. |
24 |
takes_args = ['location?'] |
25 |
aliases = [] |
|
26 |
||
27 |
def run(self, location=None, remove=False, |
|
|
0.3.6
by John Arbash Meinel
Adding ability to revert back to earlier revisions. |
28 |
dry_run=False, verbose=False, |
29 |
revision=None): |
|
|
0.3.5
by John Arbash Meinel
Updated to not use find_branch. |
30 |
from bzrlib.branch import Branch |
|
0.3.2
by John Arbash Meinel
Updated for new log_formatter. |
31 |
from bzrlib.log import log_formatter |
|
0.3.1
by John Arbash Meinel
Creating a plugin for uncommitting the last revision. |
32 |
import uncommit, sys |
33 |
||
34 |
if location is None: |
|
35 |
location = '.' |
|
|
0.3.5
by John Arbash Meinel
Updated to not use find_branch. |
36 |
b = Branch.open_containing(location) |
|
0.3.1
by John Arbash Meinel
Creating a plugin for uncommitting the last revision. |
37 |
|
|
0.3.6
by John Arbash Meinel
Adding ability to revert back to earlier revisions. |
38 |
if revision is None: |
39 |
revno = b.revno() |
|
40 |
rev_id = b.last_patch() |
|
41 |
else: |
|
42 |
revno, rev_id = revision[0].in_history(b) |
|
|
0.3.1
by John Arbash Meinel
Creating a plugin for uncommitting the last revision. |
43 |
if rev_id is None: |
44 |
print 'No revisions to uncommit.' |
|
45 |
||
|
0.3.6
by John Arbash Meinel
Adding ability to revert back to earlier revisions. |
46 |
for r in range(revno, b.revno()+1): |
47 |
rev_id = b.get_rev_id(revno) |
|
48 |
lf = log_formatter('short', to_file=sys.stdout,show_timezone='original') |
|
49 |
lf.show(r, b.get_revision(rev_id), None) |
|
|
0.3.1
by John Arbash Meinel
Creating a plugin for uncommitting the last revision. |
50 |
|
|
0.3.6
by John Arbash Meinel
Adding ability to revert back to earlier revisions. |
51 |
print 'The above revision(s) will be removed.' |
|
0.3.1
by John Arbash Meinel
Creating a plugin for uncommitting the last revision. |
52 |
val = raw_input('Are you sure [y/N]? ') |
53 |
if val.lower() not in ('y', 'yes'): |
|
54 |
print 'Canceled' |
|
55 |
return 0 |
|
56 |
||
57 |
uncommit.uncommit(b, remove_files=remove, |
|
|
0.3.6
by John Arbash Meinel
Adding ability to revert back to earlier revisions. |
58 |
dry_run=dry_run, verbose=verbose, |
59 |
revno=revno) |
|
|
0.3.1
by John Arbash Meinel
Creating a plugin for uncommitting the last revision. |
60 |
|
61 |
bzrlib.commands.register_command(cmd_uncommit) |
|
62 |
bzrlib.commands.OPTIONS['remove'] = None |
|
63 |
bzrlib.commands.OPTIONS['dry-run'] = None |