7
from bzrlib.commands import Command
10
if len(args) == 2 and args[1] == '--bzr-usage':
13
elif len(args) == 2 and args[1] == '--bzr-help':
14
print 'Shelve a patch, you can get it back later with unshelve.'
19
raise Exception("Don't understand args %s" % args)
24
root = run_bzr('root')[0].strip()
25
shelf = os.path.join(root, '.bzr-shelf')
27
if not os.path.exists(shelf):
28
raise Exception("No shelf found in '%s'" % shelf)
30
patch = open(shelf, 'r').read()
32
print >>sys.stderr, "Reapplying shelved patches"
33
pipe = os.popen('patch -d %s -s -p0' % root, 'w')
37
if pipe.close() is not None:
38
raise Exception("Failed running patch!")
41
print 'Diff status is now:'
42
os.system('bzr diff | diffstat')
47
diff_lines = run_bzr('diff')
48
patch_list = patches.parse_patches(diff_lines.__iter__())
49
to_shelve = prompt_user(patch_list)
51
if len(to_shelve) == 0:
52
print >>sys.stderr, 'Nothing to shelve'
55
root = run_bzr('root')[0].strip()
56
shelf = os.path.join(root, '.bzr-shelf')
57
print >>sys.stderr, "Saving shelved patches to", shelf
58
shelf = open(shelf, 'a')
60
for patch in to_shelve:
61
shelf.write(str(patch))
64
os.fsync(shelf.fileno())
67
print >>sys.stderr, "Reverting shelved patches"
68
pipe = os.popen('patch -d %s -sR -p0' % root, 'w')
69
for patch in to_shelve:
70
pipe.write(str(patch))
73
if pipe.close() is not None:
74
raise Exception("Failed running patch!")
76
print 'Diff status is now:'
77
os.system('bzr diff | diffstat')
84
pipe = os.popen('bzr %s' % string.join(args, ' '), 'r')
85
lines = pipe.readlines()
86
if pipe.close() is not None:
87
raise Exception("Failed running bzr")
90
def prompt_user(patch_list):
92
for patch in patch_list:
93
total += len(patch.hunks)
100
for patch in patch_list:
101
if patch.oldname != patch.newname:
102
name = "%s -> %s" % (patch.oldname, patch.newname)
106
hunks = patch.hunks[:]
111
out.write('Shelve this change? (%d of %d) [yn] ' % (i, total))
112
line = inp.readline().strip().lower()
113
if line == 'y' or line == 'yes':
115
elif line == 'n' or line == 'no':
116
patch.hunks.remove(hunk)
121
if len(patch.hunks) > 0:
122
to_shelve.append(patch)
126
class cmd_shelve(Command):
127
"""Temporarily remove some changes from the current tree.
128
Use 'unshelve' to restore these changes.
134
class cmd_unshelve(Command):
135
"""Restore previously-shelved changes to the current tree.