Commit | Line | Data |
---|---|---|
fcee87cf CM |
1 | |
2 | __copyright__ = """ | |
3 | Copyright (C) 2005, Catalin Marinas <catalin.marinas@gmail.com> | |
4 | ||
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. | |
8 | ||
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. | |
13 | ||
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 | |
17 | """ | |
18 | ||
19 | import sys, os | |
20 | from optparse import OptionParser, make_option | |
21 | ||
22 | from stgit.commands.common import * | |
23 | from stgit.utils import * | |
5e888f30 | 24 | from stgit.out import * |
fcee87cf CM |
25 | from stgit import stack, git |
26 | from stgit.config import config | |
27 | ||
28 | ||
29 | help = 'generate a new commit for the current patch' | |
d4356ac6 | 30 | usage = """%prog [options] [<files or dirs>] |
26aab5b0 CM |
31 | |
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 patch attributes like author, | |
35 | committer and description can be changed with the command line | |
36 | options. The '--force' option is useful when a commit object was | |
37 | created with a different tool but the changes need to be included in | |
38 | the current patch.""" | |
fcee87cf | 39 | |
d4356ac6 | 40 | directory = DirectoryHasRepository() |
fcee87cf CM |
41 | options = [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 | |
57 | def func(parser, options, args): | |
d4356ac6 CM |
58 | """Generate a new commit for the current or given patch. |
59 | """ | |
60 | args = git.ls_files(args) | |
61 | directory.cd_to_topdir() | |
fcee87cf | 62 | |
d4356ac6 | 63 | autoresolved = config.get('stgit.autoresolved') |
fcee87cf CM |
64 | if autoresolved != 'yes': |
65 | check_conflicts() | |
66 | ||
42fc7623 | 67 | if options.patch: |
6ee70d6b | 68 | if args or options.update: |
42fc7623 YD |
69 | raise CmdException, \ |
70 | 'Only full refresh is available with the --patch option' | |
71 | patch = options.patch | |
72 | if not crt_series.patch_applied(patch): | |
73 | raise CmdException, 'Patches "%s" not applied' % patch | |
74 | else: | |
75 | patch = crt_series.get_current() | |
76 | if not patch: | |
77 | raise CmdException, 'No patches applied' | |
fcee87cf CM |
78 | |
79 | if not options.force: | |
6972fd6b | 80 | check_head_top_equal(crt_series) |
fcee87cf | 81 | |
f80bef49 | 82 | if options.undo: |
27ac2b7e | 83 | out.start('Undoing the refresh of "%s"' % patch) |
f80bef49 | 84 | crt_series.undo_refresh() |
27ac2b7e | 85 | out.done() |
f80bef49 CM |
86 | return |
87 | ||
d4356ac6 | 88 | files = [path for (stat, path) in git.tree_status(files = args, verbose = True)] |
6ee70d6b | 89 | |
ed60fdae | 90 | if files or not crt_series.head_top_equal(): |
42fc7623 YD |
91 | if options.patch: |
92 | applied = crt_series.get_applied() | |
93 | between = applied[:applied.index(patch):-1] | |
6972fd6b | 94 | pop_patches(crt_series, between, keep = True) |
6ee70d6b | 95 | elif options.update: |
6972fd6b KH |
96 | rev1 = git_id(crt_series, '//bottom') |
97 | rev2 = git_id(crt_series, '//top') | |
6ee70d6b CM |
98 | patch_files = git.barefiles(rev1, rev2).split('\n') |
99 | files = [f for f in files if f in patch_files] | |
100 | if not files: | |
101 | out.info('No modified files for updating patch "%s"' % patch) | |
102 | return | |
42fc7623 | 103 | |
27ac2b7e | 104 | out.start('Refreshing patch "%s"' % patch) |
fcee87cf CM |
105 | |
106 | if autoresolved == 'yes': | |
107 | resolved_all() | |
6ee70d6b | 108 | crt_series.refresh_patch(files = files, |
ed60fdae | 109 | backup = True, notes = options.annotate) |
fcee87cf | 110 | |
dc4e5946 | 111 | if crt_series.empty_patch(patch): |
27ac2b7e | 112 | out.done('empty patch') |
dc4e5946 | 113 | else: |
27ac2b7e | 114 | out.done() |
7c53fcf5 | 115 | |
42fc7623 YD |
116 | if options.patch: |
117 | between.reverse() | |
6972fd6b | 118 | push_patches(crt_series, between) |
ea7634bb CM |
119 | elif options.annotate: |
120 | # only annotate the top log entry as there is no need to | |
121 | # refresh the patch and generate a full commit | |
122 | crt_series.log_patch(crt_series.get_patch(patch), None, | |
123 | notes = options.annotate) | |
fcee87cf | 124 | else: |
27ac2b7e | 125 | out.info('Patch "%s" is already up to date' % patch) |