~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to __init__.py

  • Committer: Aaron Bentley
  • Date: 2006-03-16 14:59:04 UTC
  • mfrom: (325.1.3 bzrtools)
  • Revision ID: abentley@panoramicfeedback.com-20060316145904-c004cd0222a1f1c8
Merge shelf v2 again

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
"""
5
5
import bzrlib.commands
6
6
import push
 
7
from errors import CommandError
 
8
from patchsource import BzrPatchSource
7
9
from shelf import Shelf
8
10
import sys
9
11
import os.path
13
15
from reweave_inventory import cmd_fix
14
16
sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__), 
15
17
                                                 "external")))
 
18
from bzrlib import DEFAULT_IGNORE
 
19
 
 
20
 
 
21
DEFAULT_IGNORE.append('./.shelf')
 
22
DEFAULT_IGNORE.append('./.bzr-shelf*')
 
23
 
16
24
 
17
25
Option.OPTIONS['ignored'] = Option('ignored',
18
26
        help='delete all ignored files.')
116
124
 
117
125
        return patch(b, filename, strip, legacy= not bzrdiff)
118
126
 
119
 
 
120
127
class cmd_shelve(bzrlib.commands.Command):
121
 
    """Temporarily remove some text changes from the current tree.
122
 
    Use 'unshelve' to restore these changes.
 
128
    """Temporarily set aside some changes from the current tree.
 
129
 
 
130
    Shelve allows you to temporarily put changes you've made "on the shelf",
 
131
    ie. out of the way, until a later time when you can bring them back from
 
132
    the shelf with the 'unshelve' command.
123
133
 
124
134
    Shelve is intended to help separate several sets of text changes that have
125
135
    been inappropriately mingled.  If you just want to get rid of all changes
126
136
    (text and otherwise) and you don't need to restore them later, use revert.
127
137
    If you want to shelve all text changes at once, use shelve --all.
128
138
 
129
 
    If filenames are specified, only changes to those files will be shelved.
130
 
    If a revision is specified, all changes since that revision will may be
131
 
    shelved.
 
139
    By default shelve asks you what you want to shelve, press '?' at the
 
140
    prompt to get help. To shelve everything run shelve --all.
 
141
 
 
142
    You can put multiple items on the shelf, each time you run unshelve the
 
143
    most recently shelved changes will be reinstated.
 
144
 
 
145
    If filenames are specified, only the changes to those files will be
 
146
    shelved, other files will be left untouched.
 
147
 
 
148
    If a revision is specified, changes since that revision will be shelved.
132
149
    """
 
150
 
133
151
    takes_args = ['file*']
134
 
    takes_options = [Option('all', 
135
 
                            help='Shelve all changes without prompting'), 
136
 
                     'message', 'revision']
 
152
    takes_options = ['message', 'revision',
 
153
            Option('all', help='Shelve all changes without prompting')]
 
154
 
137
155
    def run(self, all=False, file_list=None, message=None, revision=None):
138
 
        if file_list is not None and len(file_list) > 0:
139
 
            branchdir = file_list[0]
140
 
        else:
141
 
            branchdir = '.'
142
 
 
143
156
        if revision is not None and revision:
144
157
            if len(revision) == 1:
145
158
                revision = revision[0]
146
159
            else:
147
 
                raise BzrCommandError("shelve only accepts a single revision "
 
160
                raise CommandError("shelve only accepts a single revision "
148
161
                                  "parameter.")
149
162
 
150
 
        s = Shelf(branchdir)
151
 
        return s.shelve(all, message, revision, file_list)
 
163
        source = BzrPatchSource(revision, file_list)
 
164
        s = Shelf(source.base)
 
165
        s.shelve(source, all, message)
 
166
        return 0
 
167
 
 
168
class cmd_shelf(bzrlib.commands.Command):
 
169
    """Perform various operations on your shelved patches. See also shelve.
 
170
 
 
171
    Subcommands:
 
172
        list   (ls)           List the patches on the current shelf.
 
173
        delete (del) <patch>  Delete a patch from the current shelf.
 
174
        switch       <shelf>  Switch to the named shelf, create it if necessary.
 
175
        show         <patch>  Show the contents of the specified patch.
 
176
        upgrade               Upgrade old format shelves.
 
177
    """
 
178
    takes_args = ['subcommand', 'args*']
 
179
 
 
180
    def run(self, subcommand, args_list):
 
181
        import sys
 
182
 
 
183
        source = BzrPatchSource()
 
184
        s = Shelf(source.base)
 
185
 
 
186
        if subcommand == 'ls' or subcommand == 'list':
 
187
            self.__check_no_args(args_list, "shelf list takes no arguments!")
 
188
            s.list()
 
189
        elif subcommand == 'delete' or subcommand == 'del':
 
190
            self.__check_one_arg(args_list, "shelf delete takes one argument!")
 
191
            s.delete(args_list[0])
 
192
        elif subcommand == 'switch':
 
193
            self.__check_one_arg(args_list, "shelf switch takes one argument!")
 
194
            s = Shelf(source.base, args_list[0])
 
195
            s.make_default()
 
196
        elif subcommand == 'show':
 
197
            self.__check_one_arg(args_list, "shelf show takes one argument!")
 
198
            s.display(args_list[0])
 
199
        elif subcommand == 'upgrade':
 
200
            self.__check_no_args(args_list, "shelf upgrade takes no arguments!")
 
201
            s.upgrade()
 
202
        else:
 
203
            print subcommand, args_list
 
204
            print >>sys.stderr, "Unknown shelf subcommand '%s'" % subcommand
 
205
 
 
206
    def __check_one_arg(self, args, msg):
 
207
        if args is None or len(args) != 1:
 
208
            raise CommandError(msg)
 
209
 
 
210
    def __check_no_args(self, args, msg):
 
211
        if args is not None:
 
212
            raise CommandError(msg)
152
213
 
153
214
 
154
215
class cmd_unshelve(bzrlib.commands.Command):
155
 
    """Restore previously-shelved changes to the current tree.
156
 
    See also 'shelve'.
 
216
    """Restore the most recently shelved changes to the current tree.
 
217
    See 'shelve' for more information.
157
218
    """
158
 
    def run(self):
159
 
        s = Shelf('.')
160
 
        return s.unshelve()
 
219
    takes_options = [
 
220
            Option('all', help='Unshelve all changes without prompting'),
 
221
            Option('force', help='Force unshelving even if errors occur'),
 
222
    ]
 
223
    def run(self, all=False, force=False):
 
224
        source = BzrPatchSource()
 
225
        s = Shelf(source.base)
 
226
        s.unshelve(source, all, force)
 
227
        return 0
 
228
 
161
229
 
162
230
class cmd_shell(bzrlib.commands.Command):
163
231
    """Begin an interactive shell tailored for bzr.
194
262
        from branchhistory import branch_history 
195
263
        return branch_history(branch)
196
264
 
197
 
commands = [cmd_shelve, cmd_unshelve, cmd_clean_tree, cmd_graph_ancestry,
198
 
            cmd_fetch_ghosts, cmd_patch, cmd_shell, cmd_fix, cmd_branch_history]
 
265
commands = [cmd_shelve, cmd_unshelve, cmd_shelf, cmd_clean_tree,
 
266
            cmd_graph_ancestry, cmd_fetch_ghosts, cmd_patch, cmd_shell,
 
267
            cmd_fix, cmd_branch_history]
199
268
 
200
269
command_decorators = []
201
270
 
245
314
 
246
315
def test_suite():
247
316
    import baz_import
 
317
    from bzrlib.tests.TestUtil import TestLoader
248
318
    import tests
249
319
    from doctest import DocTestSuite, ELLIPSIS
250
 
    from unittest import TestSuite, TestLoader
 
320
    from unittest import TestSuite
251
321
    import clean_tree
252
322
    import blackbox
253
323
    import shelf_tests