~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to bzr_shelf.py

  • Committer: Michael Ellerman
  • Date: 2006-02-21 03:41:11 UTC
  • mto: (0.1.73 shelf-tmp)
  • mto: This revision was merged to the branch mainline in revision 334.
  • Revision ID: michael@ellerman.id.au-20060221034111-04574f50042ef6bf
Add switch command to switch between multiple shelves.
Add show command to show the content of a patch on the current shelf.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
 
3
import bzrlib.branch
 
4
from errors import CommandError
 
5
from bzrlib.option import Option
 
6
from patchsource import BzrPatchSource
 
7
from shelf import Shelf
 
8
from bzrlib import DEFAULT_IGNORE
 
9
 
 
10
DEFAULT_IGNORE.append('./.shelf')
 
11
 
 
12
class cmd_shelve(bzrlib.commands.Command):
 
13
    """Temporarily set aside some changes to the current working tree.
 
14
 
 
15
    Shelve allows you to temporarily put changes you've made "on the shelf",
 
16
    ie. out of the way, until a later time when you can bring them back from
 
17
    the shelf with the 'unshelve' command.
 
18
 
 
19
    You can put multiple items on the shelf, each time you run unshelve the
 
20
    most recently shelved changes will be reinstated.
 
21
 
 
22
    If filenames are specified, only the changes to those files will be
 
23
    shelved, other files will be left untouched.
 
24
 
 
25
    If a revision is specified, changes since that revision will be shelved.
 
26
 
 
27
    If you specifiy "--pick" you'll be prompted for each hunk of the diff as
 
28
    to whether you want to shelve it or not. Press "?" at the prompt for help.
 
29
    """
 
30
    takes_args = ['file*']
 
31
    takes_options = [Option('pick'), 'message', 'revision']
 
32
    def run(self, pick=False, file_list=None, message=None, revision=None):
 
33
        if revision is not None and revision:
 
34
            if len(revision) == 1:
 
35
                revision = revision[0]
 
36
            else:
 
37
                raise CommandError("shelve only accepts a single revision "
 
38
                                  "parameter.")
 
39
 
 
40
        source = BzrPatchSource(revision, file_list)
 
41
        s = Shelf(source.branch.base)
 
42
        s.shelve(source, pick, message)
 
43
        return 0
 
44
 
 
45
class cmd_shelf(bzrlib.commands.Command):
 
46
    """Perform various operations on your shelved patches.
 
47
 
 
48
    Subcommands:
 
49
        list   (ls)           List the patches on the current shelf.
 
50
        delete (del) <patch>  Delete a patch from the current shelf.
 
51
        switch       <shelf>  Switch to the named shelf, create it if necessary.
 
52
        show         <patch>  Show the contents of the specified patch.
 
53
    """
 
54
    takes_args = ['subcommand', 'args*']
 
55
 
 
56
    def run(self, subcommand, args_list):
 
57
        import sys
 
58
 
 
59
        source = BzrPatchSource()
 
60
        s = Shelf(source.branch.base)
 
61
 
 
62
        if subcommand == 'ls' or subcommand == 'list':
 
63
            self.__check_no_args(args_list, "shelf list takes no arguments!")
 
64
            s.list()
 
65
        elif subcommand == 'delete' or subcommand == 'del':
 
66
            self.__check_one_arg(args_list, "shelf delete takes one argument!")
 
67
            s.delete(args_list[0])
 
68
        elif subcommand == 'switch':
 
69
            self.__check_one_arg(args_list, "shelf switch takes one argument!")
 
70
            s = Shelf(source.branch.base, args_list[0])
 
71
            s.make_default()
 
72
        elif subcommand == 'show':
 
73
            self.__check_one_arg(args_list, "shelf show takes one argument!")
 
74
            s.display(args_list[0])
 
75
        else:
 
76
            print subcommand, args_list
 
77
            print >>sys.stderr, "Unknown shelf subcommand '%s'" % subcommand
 
78
 
 
79
    def __check_one_arg(self, args, msg):
 
80
        if args is None or len(args) != 1:
 
81
            raise BzrCommandError(msg)
 
82
 
 
83
    def __check_no_args(self, args, msg):
 
84
        if args is not None:
 
85
            raise BzrCommandError(msg)
 
86
 
 
87
class cmd_unshelve(bzrlib.commands.Command):
 
88
    """Reinstate the most recently shelved changes.
 
89
    See 'shelve' for more information.
 
90
    """
 
91
    takes_options = [Option('pick')]
 
92
    def run(self, pick=False):
 
93
        source = BzrPatchSource()
 
94
        s = Shelf(source.branch.base)
 
95
        s.unshelve(source, pick)
 
96
        return 0
 
97
 
 
98
bzrlib.commands.register_command(cmd_shelf)
 
99
bzrlib.commands.register_command(cmd_shelve)
 
100
bzrlib.commands.register_command(cmd_unshelve)
 
101
 
 
102
def test_suite():
 
103
    from bzrlib.tests.TestUtil import TestLoader
 
104
    import tests
 
105
    return TestLoader().loadTestsFromModule(tests)