~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to __init__.py

  • Committer: Michael Ellerman
  • Date: 2006-03-22 05:23:58 UTC
  • mto: (0.3.1 shelf-dev)
  • mto: This revision was merged to the branch mainline in revision 367.
  • Revision ID: michael@ellerman.id.au-20060322052358-4a7fda32faa2c5ce
Cleanup naming. PatchSource gives us back Patches not Hunks.

Show diffs side-by-side

added added

removed removed

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