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