~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to bzr_shelf.py

  • Committer: Michael Ellerman
  • Date: 2006-02-06 14:04:14 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-20060206140414-11c89c99a0ec59b0
Factor out bzrisms.

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
 
 
9
class cmd_shelve(bzrlib.commands.Command):
 
10
    """Temporarily set aside some changes to the current working tree.
 
11
 
 
12
    Shelve allows you to temporarily put changes you've made "on the shelf",
 
13
    ie. out of the way, until a later time when you can bring them back from
 
14
    the shelf with the 'unshelve' command.
 
15
 
 
16
    You can put multiple items on the shelf, each time you run unshelve the
 
17
    most recently shelved changes will be reinstated.
 
18
 
 
19
    If filenames are specified, only the changes to those files will be
 
20
    shelved, other files will be left untouched.
 
21
 
 
22
    If a revision is specified, changes since that revision will be shelved.
 
23
 
 
24
    If you specifiy "--pick" you'll be prompted for each hunk of the diff as
 
25
    to whether you want to shelve it or not. Press "?" at the prompt for help.
 
26
    """
 
27
    takes_args = ['file*']
 
28
    takes_options = [Option('pick'), 'message', 'revision']
 
29
    def run(self, pick=False, file_list=None, message=None, revision=None):
 
30
        if revision is not None and revision:
 
31
            if len(revision) == 1:
 
32
                revision = revision[0]
 
33
            else:
 
34
                raise CommandError("shelve only accepts a single revision "
 
35
                                  "parameter.")
 
36
 
 
37
        source = BzrPatchSource(revision, file_list)
 
38
        s = Shelf(source.branch.base)
 
39
        s.shelve(source, pick, message)
 
40
        return 0
 
41
 
 
42
class cmd_unshelve(bzrlib.commands.Command):
 
43
    """Reinstate the most recently shelved changes.
 
44
    See 'shelve' for more information.
 
45
    """
 
46
    takes_options = [Option('pick')]
 
47
    def run(self, pick=False):
 
48
        source = BzrPatchSource()
 
49
        s = Shelf(source.branch.base)
 
50
        s.unshelve(source, pick)
 
51
        return 0
 
52
 
 
53
bzrlib.commands.register_command(cmd_shelve)
 
54
bzrlib.commands.register_command(cmd_unshelve)
 
55
 
 
56
def test_suite():
 
57
    from bzrlib.tests.TestUtil import TestLoader
 
58
    import tests
 
59
    return TestLoader().loadTestsFromModule(tests)