chiark / gitweb /
Infrastructure for current directory handling
[stgit] / stgit / commands / refresh.py
CommitLineData
fcee87cf
CM
1
2__copyright__ = """
3Copyright (C) 2005, Catalin Marinas <catalin.marinas@gmail.com>
4
5This program is free software; you can redistribute it and/or modify
6it under the terms of the GNU General Public License version 2 as
7published by the Free Software Foundation.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program; if not, write to the Free Software
16Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17"""
18
19import sys, os
20from optparse import OptionParser, make_option
21
22from stgit.commands.common import *
23from stgit.utils import *
5e888f30 24from stgit.out import *
fcee87cf
CM
25from stgit import stack, git
26from stgit.config import config
27
28
29help = 'generate a new commit for the current patch'
026c0689 30usage = """%prog [options] [<files...>]
26aab5b0
CM
31
32Include the latest tree changes in the current patch. This command
33generates a new GIT commit object with the patch details, the previous
34one no longer being visible. The patch attributes like author,
35committer and description can be changed with the command line
36options. The '--force' option is useful when a commit object was
37created with a different tool but the changes need to be included in
38the current patch."""
fcee87cf 39
6dd8fafa 40directory = DirectoryHasRepository()
fcee87cf
CM
41options = [make_option('-f', '--force',
42 help = 'force the refresh even if HEAD and '\
43 'top differ',
44 action = 'store_true'),
6ee70d6b
CM
45 make_option('--update',
46 help = 'only update the current patch files',
47 action = 'store_true'),
f80bef49
CM
48 make_option('--undo',
49 help = 'revert the commit generated by the last refresh',
50 action = 'store_true'),
eff17c6b
CM
51 make_option('-a', '--annotate', metavar = 'NOTE',
52 help = 'annotate the patch log entry'),
42fc7623 53 make_option('-p', '--patch',
130df01a 54 help = 'refresh (applied) PATCH instead of the top one')
ed60fdae 55 ]
fcee87cf
CM
56
57def func(parser, options, args):
c73e63b7 58 autoresolved = config.get('stgit.autoresolved')
fcee87cf
CM
59
60 if autoresolved != 'yes':
61 check_conflicts()
62
42fc7623 63 if options.patch:
6ee70d6b 64 if args or options.update:
42fc7623
YD
65 raise CmdException, \
66 'Only full refresh is available with the --patch option'
67 patch = options.patch
68 if not crt_series.patch_applied(patch):
69 raise CmdException, 'Patches "%s" not applied' % patch
70 else:
71 patch = crt_series.get_current()
72 if not patch:
73 raise CmdException, 'No patches applied'
fcee87cf
CM
74
75 if not options.force:
76 check_head_top_equal()
77
f80bef49 78 if options.undo:
27ac2b7e 79 out.start('Undoing the refresh of "%s"' % patch)
f80bef49 80 crt_series.undo_refresh()
27ac2b7e 81 out.done()
f80bef49
CM
82 return
83
14c88aa0 84 files = [path for (stat,path) in git.tree_status(verbose = True)]
6ee70d6b
CM
85 if args:
86 files = [f for f in files if f in args]
87
ed60fdae 88 if files or not crt_series.head_top_equal():
42fc7623
YD
89 if options.patch:
90 applied = crt_series.get_applied()
91 between = applied[:applied.index(patch):-1]
92 pop_patches(between, keep = True)
6ee70d6b
CM
93 elif options.update:
94 rev1 = git_id('//bottom')
95 rev2 = git_id('//top')
96 patch_files = git.barefiles(rev1, rev2).split('\n')
97 files = [f for f in files if f in patch_files]
98 if not files:
99 out.info('No modified files for updating patch "%s"' % patch)
100 return
42fc7623 101
27ac2b7e 102 out.start('Refreshing patch "%s"' % patch)
fcee87cf
CM
103
104 if autoresolved == 'yes':
105 resolved_all()
6ee70d6b 106 crt_series.refresh_patch(files = files,
ed60fdae 107 backup = True, notes = options.annotate)
fcee87cf 108
dc4e5946 109 if crt_series.empty_patch(patch):
27ac2b7e 110 out.done('empty patch')
dc4e5946 111 else:
27ac2b7e 112 out.done()
7c53fcf5 113
42fc7623
YD
114 if options.patch:
115 between.reverse()
116 push_patches(between)
ea7634bb
CM
117 elif options.annotate:
118 # only annotate the top log entry as there is no need to
119 # refresh the patch and generate a full commit
120 crt_series.log_patch(crt_series.get_patch(patch), None,
121 notes = options.annotate)
fcee87cf 122 else:
27ac2b7e 123 out.info('Patch "%s" is already up to date' % patch)