2
2
"""Shelf - temporarily set aside changes, then bring them back."""
4
4
import bzrlib.commands
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
11
DEFAULT_IGNORE.append('./.shelf')
12
DEFAULT_IGNORE.append('./.bzr-shelf*')
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.
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.
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.
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.
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.
21
32
shelved, other files will be left untouched.
23
34
If a revision is specified, changes since that revision will be shelved.
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.
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]
38
takes_options = ['message', 'revision',
39
Option('all', help='Shelve all changes without prompting')]
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]
40
raise BzrCommandError("shelve only accepts a single revision "
46
raise CommandError("shelve only accepts a single revision "
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)
54
class cmd_shelf(bzrlib.commands.Command):
55
"""Perform various operations on your shelved patches. See also shelve.
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.
64
takes_args = ['subcommand', 'args*']
66
def run(self, subcommand, args_list):
69
source = BzrPatchSource()
70
s = Shelf(source.base)
72
if subcommand == 'ls' or subcommand == 'list':
73
self.__check_no_args(args_list, "shelf list takes no arguments!")
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])
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!")
89
print subcommand, args_list
90
print >>sys.stderr, "Unknown shelf subcommand '%s'" % subcommand
92
def __check_one_arg(self, args, msg):
93
if args is None or len(args) != 1:
94
raise CommandError(msg)
96
def __check_no_args(self, args, msg):
98
raise CommandError(msg)
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.
50
takes_options = [Option('pick')]
51
def run(self, pick=False):
53
return s.unshelve(pick)
105
Option('all', help='Unshelve all changes without prompting'),
106
Option('force', help='Force unshelving even if errors occur'),
108
def run(self, all=False, force=False):
109
source = BzrPatchSource()
110
s = Shelf(source.base)
111
s.unshelve(source, all, force)
114
bzrlib.commands.register_command(cmd_shelf)
55
115
bzrlib.commands.register_command(cmd_shelve)
56
116
bzrlib.commands.register_command(cmd_unshelve)