3 Copyright (C) 2005, Catalin Marinas <catalin.marinas@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License version 2 as
7 published by the Free Software Foundation.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 from optparse import OptionParser, make_option
22 from stgit.commands.common import *
23 from stgit.utils import *
24 from stgit.out import *
25 from stgit import stack, git
26 from stgit.config import config
29 help = 'generate a new commit for the current patch'
30 usage = """%prog [options] [<files or dirs>]
32 Include the latest tree changes in the current patch. This command
33 generates a new GIT commit object with the patch details, the previous
34 one no longer being visible. The '--force' option is useful
35 when a commit object was created with a different tool
36 but the changes need to be included in the current patch."""
38 directory = DirectoryHasRepository()
39 options = [make_option('-f', '--force',
40 help = 'force the refresh even if HEAD and '\
42 action = 'store_true'),
43 make_option('--update',
44 help = 'only update the current patch files',
45 action = 'store_true'),
46 make_option('--index',
47 help = 'use the current contents of the index instead of looking at the working directory',
48 action = 'store_true'),
50 help = 'revert the commit generated by the last refresh',
51 action = 'store_true'),
52 make_option('-a', '--annotate', metavar = 'NOTE',
53 help = 'annotate the patch log entry'),
54 make_option('-p', '--patch',
55 help = 'refresh (applied) PATCH instead of the top one')
58 def func(parser, options, args):
59 """Generate a new commit for the current or given patch.
61 args = git.ls_files(args)
62 directory.cd_to_topdir()
64 autoresolved = config.get('stgit.autoresolved')
65 if autoresolved != 'yes':
69 if args or options.update:
71 'Only full refresh is available with the --patch option'
73 if not crt_series.patch_applied(patch):
74 raise CmdException, 'Patches "%s" not applied' % patch
76 patch = crt_series.get_current()
78 raise CmdException, 'No patches applied'
81 if args or options.update:
83 'Only full refresh is available with the --index option'
86 '--patch is not compatible with the --index option'
89 check_head_top_equal(crt_series)
92 out.start('Undoing the refresh of "%s"' % patch)
93 crt_series.undo_refresh()
98 files = [path for (stat, path) in git.tree_status(files = args, verbose = True)]
100 if options.index or files or not crt_series.head_top_equal():
102 applied = crt_series.get_applied()
103 between = applied[:applied.index(patch):-1]
104 pop_patches(crt_series, between, keep = True)
106 rev1 = git_id(crt_series, '//bottom')
107 rev2 = git_id(crt_series, '//top')
108 patch_files = git.barefiles(rev1, rev2).split('\n')
109 files = [f for f in files if f in patch_files]
111 out.info('No modified files for updating patch "%s"' % patch)
114 out.start('Refreshing patch "%s"' % patch)
116 if autoresolved == 'yes':
120 crt_series.refresh_patch(cache_update = False,
121 backup = True, notes = options.annotate)
123 crt_series.refresh_patch(files = files,
124 backup = True, notes = options.annotate)
126 if crt_series.empty_patch(patch):
127 out.done('empty patch')
133 push_patches(crt_series, between)
134 elif options.annotate:
135 # only annotate the top log entry as there is no need to
136 # refresh the patch and generate a full commit
137 crt_series.log_patch(crt_series.get_patch(patch), None,
138 notes = options.annotate)
140 out.info('Patch "%s" is already up to date' % patch)