2
2
"""Shelf - temporarily set aside changes, then bring them back."""
5
4
import bzrlib.commands
7
from bzrlib.errors import BzrCommandError
6
from errors import CommandError
8
7
from bzrlib.option import Option
8
from patchsource import BzrPatchSource
9
9
from shelf import Shelf
10
from bzrlib import DEFAULT_IGNORE
12
DEFAULT_IGNORE.append('./.shelf')
11
14
class cmd_shelve(bzrlib.commands.Command):
12
15
"""Temporarily set aside some changes to the current working tree.
29
32
takes_args = ['file*']
30
33
takes_options = [Option('pick'), 'message', 'revision']
31
34
def run(self, pick=False, file_list=None, message=None, revision=None):
32
if file_list is not None and len(file_list) > 0:
33
branchdir = file_list[0]
37
35
if revision is not None and revision:
38
36
if len(revision) == 1:
39
37
revision = revision[0]
41
raise BzrCommandError("shelve only accepts a single revision "
39
raise CommandError("shelve only accepts a single revision "
45
s.shelve(pick, message, revision, file_list)
42
source = BzrPatchSource(revision, file_list)
43
s = Shelf(source.branch.base)
44
s.shelve(source, pick, message)
47
class cmd_shelf(bzrlib.commands.Command):
48
"""Perform various operations on your shelved patches.
51
list (ls) List the patches on the current shelf.
52
delete (del) <patch> Delete a patch from the current shelf.
53
switch <shelf> Switch to the named shelf, create it if necessary.
54
show <patch> Show the contents of the specified patch.
56
takes_args = ['subcommand', 'args*']
58
def run(self, subcommand, args_list):
61
source = BzrPatchSource()
62
s = Shelf(source.branch.base)
64
if subcommand == 'ls' or subcommand == 'list':
65
self.__check_no_args(args_list, "shelf list takes no arguments!")
67
elif subcommand == 'delete' or subcommand == 'del':
68
self.__check_one_arg(args_list, "shelf delete takes one argument!")
69
s.delete(args_list[0])
70
elif subcommand == 'switch':
71
self.__check_one_arg(args_list, "shelf switch takes one argument!")
72
s = Shelf(source.branch.base, args_list[0])
74
elif subcommand == 'show':
75
self.__check_one_arg(args_list, "shelf show takes one argument!")
76
s.display(args_list[0])
78
print subcommand, args_list
79
print >>sys.stderr, "Unknown shelf subcommand '%s'" % subcommand
81
def __check_one_arg(self, args, msg):
82
if args is None or len(args) != 1:
83
raise BzrCommandError(msg)
85
def __check_no_args(self, args, msg):
87
raise BzrCommandError(msg)
48
89
class cmd_unshelve(bzrlib.commands.Command):
49
90
"""Reinstate the most recently shelved changes.
50
91
See 'shelve' for more information.
52
93
takes_options = [Option('pick')]
53
94
def run(self, pick=False):
95
source = BzrPatchSource()
96
s = Shelf(source.branch.base)
97
s.unshelve(source, pick)
100
bzrlib.commands.register_command(cmd_shelf)
58
101
bzrlib.commands.register_command(cmd_shelve)
59
102
bzrlib.commands.register_command(cmd_unshelve)