Separate the commands in stgit/commands/* files
[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 *
24from stgit import stack, git
25from stgit.config import config
26
27
28help = 'generate a new commit for the current patch'
29usage = '%prog [options]'
30
31options = [make_option('-f', '--force',
32 help = 'force the refresh even if HEAD and '\
33 'top differ',
34 action = 'store_true'),
35 make_option('-e', '--edit',
36 help = 'invoke an editor for the patch '\
37 'description',
38 action = 'store_true'),
39 make_option('-m', '--message',
40 help = 'use MESSAGE as the patch ' \
41 'description'),
42 make_option('--authname',
43 help = 'use AUTHNAME as the author name'),
44 make_option('--authemail',
45 help = 'use AUTHEMAIL as the author e-mail'),
46 make_option('--authdate',
47 help = 'use AUTHDATE as the author date'),
48 make_option('--commname',
49 help = 'use COMMNAME as the committer name'),
50 make_option('--commemail',
51 help = 'use COMMEMAIL as the committer ' \
52 'e-mail')]
53
54
55def func(parser, options, args):
56 if len(args) != 0:
57 parser.error('incorrect number of arguments')
58
59 if config.has_option('stgit', 'autoresolved'):
60 autoresolved = config.get('stgit', 'autoresolved')
61 else:
62 autoresolved = 'no'
63
64 if autoresolved != 'yes':
65 check_conflicts()
66
67 patch = crt_series.get_current()
68 if not patch:
69 raise CmdException, 'No patches applied'
70
71 if not options.force:
72 check_head_top_equal()
73
74 if git.local_changes() \
75 or not crt_series.head_top_equal() \
76 or options.edit or options.message \
77 or options.authname or options.authemail or options.authdate \
78 or options.commname or options.commemail:
79 print 'Refreshing patch "%s"...' % patch,
80 sys.stdout.flush()
81
82 if autoresolved == 'yes':
83 resolved_all()
84 crt_series.refresh_patch(message = options.message,
85 edit = options.edit,
86 author_name = options.authname,
87 author_email = options.authemail,
88 author_date = options.authdate,
89 committer_name = options.commname,
90 committer_email = options.commemail)
91
92 print 'done'
93 else:
94 print 'Patch "%s" is already up to date' % patch