~abentley/bzrtools/bzrtools.dev

0.1.22 by Michael Ellerman
Add __init__.py, put cmd_shelve/unshelve in there.
1
#!/usr/bin/python
0.1.24 by Michael Ellerman
Add plugin description
2
"""Shelf - temporarily set aside changes, then bring them back."""
0.1.22 by Michael Ellerman
Add __init__.py, put cmd_shelve/unshelve in there.
3
4
import bzrlib.commands
5
import bzrlib.branch
0.1.27 by Michael Ellerman
Move all shelf functions into a class. Only logic change is we save the
6
from shelf import Shelf
0.1.22 by Michael Ellerman
Add __init__.py, put cmd_shelve/unshelve in there.
7
8
class cmd_shelve(bzrlib.commands.Command):
9
    """Temporarily remove some changes from the current tree.
10
    Use 'unshelve' to restore these changes.
11
12
    If filenames are specified, only changes to those files will be unshelved.
13
    If a revision is specified, all changes since that revision will may be
14
    unshelved.
15
    """
16
    takes_args = ['file*']
17
    takes_options = ['message', 'revision']
18
    def run(self, file_list=None, message=None, revision=None):
19
        revision_list = None
20
        if revision is not None and revision:
21
            if file_list is not None and len(file_list) > 0:
22
                branchdir = file_list[0]
23
            else:
24
                branchdir = '.'
25
            b = bzrlib.branch.Branch.open_containing(branchdir)
26
            revision_list = ["revid:" + revision[0].in_history(b).rev_id]
27
0.1.27 by Michael Ellerman
Move all shelf functions into a class. Only logic change is we save the
28
        s = Shelf()
29
        return s.shelve(message=message, file_list=file_list,
0.1.22 by Michael Ellerman
Add __init__.py, put cmd_shelve/unshelve in there.
30
                      revision=revision_list)
31
32
class cmd_unshelve(bzrlib.commands.Command):
33
    """Restore previously-shelved changes to the current tree.
34
    See also 'shelve'.
35
    """
36
    def run(self):
0.1.27 by Michael Ellerman
Move all shelf functions into a class. Only logic change is we save the
37
        s = Shelf()
38
        return s.unshelve()
0.1.22 by Michael Ellerman
Add __init__.py, put cmd_shelve/unshelve in there.
39
40
bzrlib.commands.register_command(cmd_shelve)
41
bzrlib.commands.register_command(cmd_unshelve)