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 | |
575bbdae | 20 | from stgit.argparse import opt |
fcee87cf CM |
21 | from stgit.commands.common import * |
22 | from stgit.utils import * | |
5e888f30 | 23 | from stgit.out import * |
fcee87cf CM |
24 | from stgit import stack, git |
25 | from stgit.config import config | |
26 | ||
575bbdae KH |
27 | help = 'Generate a new commit for the current patch' |
28 | usage = ['[options] [<files or dirs>]'] | |
29 | description = """ | |
26aab5b0 CM |
30 | Include the latest tree changes in the current patch. This command |
31 | generates a new GIT commit object with the patch details, the previous | |
b8038cef PO |
32 | one no longer being visible. The '--force' option is useful |
33 | when a commit object was created with a different tool | |
34 | but the changes need to be included in the current patch.""" | |
fcee87cf | 35 | |
575bbdae KH |
36 | options = [ |
37 | opt('-f', '--force', action = 'store_true', | |
38 | short = 'Force the refresh even if HEAD and top differ'), | |
39 | opt('--update', action = 'store_true', | |
40 | short = 'Only update the current patch files'), | |
41 | opt('--index', action = 'store_true', | |
42 | short = 'Refresh from index instead of worktree', long = """ | |
43 | Instead of setting the patch top to the current contents of | |
44 | the worktree, set it to the current contents of the index."""), | |
45 | opt('--undo', action = 'store_true', | |
46 | short = 'Revert the commit generated by the last refresh'), | |
47 | opt('-a', '--annotate', metavar = 'NOTE', | |
48 | short = 'Annotate the patch log entry'), | |
49 | opt('-p', '--patch', | |
50 | short = 'Refresh (applied) PATCH instead of the top patch')] | |
51 | ||
d4356ac6 | 52 | directory = DirectoryHasRepository() |
fcee87cf CM |
53 | |
54 | def func(parser, options, args): | |
d4356ac6 CM |
55 | """Generate a new commit for the current or given patch. |
56 | """ | |
57 | args = git.ls_files(args) | |
58 | directory.cd_to_topdir() | |
fcee87cf | 59 | |
d4356ac6 | 60 | autoresolved = config.get('stgit.autoresolved') |
fcee87cf CM |
61 | if autoresolved != 'yes': |
62 | check_conflicts() | |
63 | ||
42fc7623 | 64 | if options.patch: |
6ee70d6b | 65 | if args or options.update: |
42fc7623 YD |
66 | raise CmdException, \ |
67 | 'Only full refresh is available with the --patch option' | |
68 | patch = options.patch | |
69 | if not crt_series.patch_applied(patch): | |
70 | raise CmdException, 'Patches "%s" not applied' % patch | |
71 | else: | |
72 | patch = crt_series.get_current() | |
73 | if not patch: | |
74 | raise CmdException, 'No patches applied' | |
fcee87cf | 75 | |
c3a72ae1 PO |
76 | if options.index: |
77 | if args or options.update: | |
78 | raise CmdException, \ | |
79 | 'Only full refresh is available with the --index option' | |
80 | if options.patch: | |
81 | raise CmdException, \ | |
82 | '--patch is not compatible with the --index option' | |
83 | ||
fcee87cf | 84 | if not options.force: |
6972fd6b | 85 | check_head_top_equal(crt_series) |
fcee87cf | 86 | |
f80bef49 | 87 | if options.undo: |
27ac2b7e | 88 | out.start('Undoing the refresh of "%s"' % patch) |
f80bef49 | 89 | crt_series.undo_refresh() |
27ac2b7e | 90 | out.done() |
f80bef49 CM |
91 | return |
92 | ||
c3a72ae1 PO |
93 | if not options.index: |
94 | files = [path for (stat, path) in git.tree_status(files = args, verbose = True)] | |
6ee70d6b | 95 | |
c3a72ae1 | 96 | if options.index or files or not crt_series.head_top_equal(): |
42fc7623 YD |
97 | if options.patch: |
98 | applied = crt_series.get_applied() | |
99 | between = applied[:applied.index(patch):-1] | |
6972fd6b | 100 | pop_patches(crt_series, between, keep = True) |
6ee70d6b | 101 | elif options.update: |
e4560d7e CM |
102 | rev1 = git_id(crt_series, 'HEAD^') |
103 | rev2 = git_id(crt_series, 'HEAD') | |
6ee70d6b CM |
104 | patch_files = git.barefiles(rev1, rev2).split('\n') |
105 | files = [f for f in files if f in patch_files] | |
106 | if not files: | |
107 | out.info('No modified files for updating patch "%s"' % patch) | |
108 | return | |
42fc7623 | 109 | |
27ac2b7e | 110 | out.start('Refreshing patch "%s"' % patch) |
fcee87cf CM |
111 | |
112 | if autoresolved == 'yes': | |
113 | resolved_all() | |
c3a72ae1 PO |
114 | |
115 | if options.index: | |
116 | crt_series.refresh_patch(cache_update = False, | |
117 | backup = True, notes = options.annotate) | |
118 | else: | |
119 | crt_series.refresh_patch(files = files, | |
120 | backup = True, notes = options.annotate) | |
fcee87cf | 121 | |
dc4e5946 | 122 | if crt_series.empty_patch(patch): |
27ac2b7e | 123 | out.done('empty patch') |
dc4e5946 | 124 | else: |
27ac2b7e | 125 | out.done() |
7c53fcf5 | 126 | |
42fc7623 YD |
127 | if options.patch: |
128 | between.reverse() | |
6972fd6b | 129 | push_patches(crt_series, between) |
ea7634bb CM |
130 | elif options.annotate: |
131 | # only annotate the top log entry as there is no need to | |
132 | # refresh the patch and generate a full commit | |
133 | crt_series.log_patch(crt_series.get_patch(patch), None, | |
134 | notes = options.annotate) | |
fcee87cf | 135 | else: |
27ac2b7e | 136 | out.info('Patch "%s" is already up to date' % patch) |