/brz/remove-bazaar

To get this branch, use:
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
    """
23
    takes_options = ['remove', 'dry-run', 'verbose']
24
    takes_args = ['location?']
25
    aliases = []
26
27
    def run(self, location=None, remove=False,
28
            dry_run=False, verbose=False):
29
        from bzrlib.branch import find_branch
0.3.2 by John Arbash Meinel
Updated for new log_formatter.
30
        from bzrlib.log import log_formatter
0.3.1 by John Arbash Meinel
Creating a plugin for uncommitting the last revision.
31
        import uncommit, sys
32
33
        if location is None:
34
            location = '.'
35
        b = find_branch(location)
36
37
        revno = b.revno()
38
        rev_id = b.last_patch()
39
        if rev_id is None:
40
            print 'No revisions to uncommit.'
41
0.3.2 by John Arbash Meinel
Updated for new log_formatter.
42
        lf = log_formatter('short', to_file=sys.stdout)
43
        lf.show(revno, b.get_revision(rev_id), None)
0.3.1 by John Arbash Meinel
Creating a plugin for uncommitting the last revision.
44
45
        print 'The above revision will be removed.'
46
        val = raw_input('Are you sure [y/N]? ')
47
        if val.lower() not in ('y', 'yes'):
48
            print 'Canceled'
49
            return 0
50
51
        uncommit.uncommit(b, remove_files=remove,
52
                dry_run=dry_run, verbose=verbose)
53
54
bzrlib.commands.register_command(cmd_uncommit)
55
bzrlib.commands.OPTIONS['remove'] = None
56
bzrlib.commands.OPTIONS['dry-run'] = None