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...>]
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
40 options
= [make_option('-f', '--force',
41 help = 'force the refresh even if HEAD and '\
43 action
= 'store_true'),
44 make_option('--update',
45 help = 'only update the current patch files',
46 action
= 'store_true'),
48 help = 'revert the commit generated by the last refresh',
49 action
= 'store_true'),
50 make_option('-a', '--annotate', metavar
= 'NOTE',
51 help = 'annotate the patch log entry'),
52 make_option('-p', '--patch',
53 help = 'refresh (applied) PATCH instead of the top one')
56 def func(parser
, options
, args
):
57 autoresolved
= config
.get('stgit.autoresolved')
59 if autoresolved
!= 'yes':
63 if args
or options
.update
:
65 'Only full refresh is available with the --patch option'
67 if not crt_series
.patch_applied(patch
):
68 raise CmdException
, 'Patches "%s" not applied' % patch
70 patch
= crt_series
.get_current()
72 raise CmdException
, 'No patches applied'
75 check_head_top_equal()
78 out
.start('Undoing the refresh of "%s"' % patch
)
79 crt_series
.undo_refresh()
83 files
= [path
for (stat
,path
) in git
.tree_status(verbose
= True)]
85 files
= [f
for f
in files
if f
in args
]
87 if files
or not crt_series
.head_top_equal():
89 applied
= crt_series
.get_applied()
90 between
= applied
[:applied
.index(patch
):-1]
91 pop_patches(between
, keep
= True)
93 rev1
= git_id('//bottom')
94 rev2
= git_id('//top')
95 patch_files
= git
.barefiles(rev1
, rev2
).split('\n')
96 files
= [f
for f
in files
if f
in patch_files
]
98 out
.info('No modified files for updating patch "%s"' % patch
)
101 out
.start('Refreshing patch "%s"' % patch
)
103 if autoresolved
== 'yes':
105 crt_series
.refresh_patch(files
= files
,
106 backup
= True, notes
= options
.annotate
)
108 if crt_series
.empty_patch(patch
):
109 out
.done('empty patch')
115 push_patches(between
)
116 elif options
.annotate
:
117 # only annotate the top log entry as there is no need to
118 # refresh the patch and generate a full commit
119 crt_series
.log_patch(crt_series
.get_patch(patch
), None,
120 notes
= options
.annotate
)
122 out
.info('Patch "%s" is already up to date' % patch
)