chiark / gitweb /
Make the 'series --short' length configurable
[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] [<files...>]
30
31 Include the latest tree changes in the current patch. This command
32 generates a new GIT commit object with the patch details, the previous
33 one no longer being visible. The patch attributes like author,
34 committer and description can be changed with the command line
35 options. The '--force' option is useful when a commit object was
36 created with a different tool but the changes need to be included in
37 the current patch."""
38
39 options = [make_option('-f', '--force',
40                        help = 'force the refresh even if HEAD and '\
41                        'top differ',
42                        action = 'store_true'),
43            make_option('-e', '--edit',
44                        help = 'invoke an editor for the patch '\
45                        'description',
46                        action = 'store_true'),
47            make_option('-s', '--showpatch',
48                        help = 'show the patch content in the editor buffer',
49                        action = 'store_true'),
50            make_option('--undo',
51                        help = 'revert the commit generated by the last refresh',
52                        action = 'store_true'),
53            make_option('-m', '--message',
54                        help = 'use MESSAGE as the patch ' \
55                        'description'),
56            make_option('-a', '--author', metavar = '"NAME <EMAIL>"',
57                        help = 'use "NAME <EMAIL>" as the author details'),
58            make_option('--authname',
59                        help = 'use AUTHNAME as the author name'),
60            make_option('--authemail',
61                        help = 'use AUTHEMAIL as the author e-mail'),
62            make_option('--authdate',
63                        help = 'use AUTHDATE as the author date'),
64            make_option('--commname',
65                        help = 'use COMMNAME as the committer name'),
66            make_option('--commemail',
67                        help = 'use COMMEMAIL as the committer ' \
68                        'e-mail'),
69            make_option('-p', '--patch',
70                        help = 'refresh (applied) PATCH instead of the top one'),
71            make_option('--sign',
72                        help = 'add Signed-off-by line',
73                        action = 'store_true'),
74            make_option('--ack',
75                        help = 'add Acked-by line',
76                        action = 'store_true')]
77
78
79 def func(parser, options, args):
80     autoresolved = config.get('stgit', 'autoresolved')
81
82     if autoresolved != 'yes':
83         check_conflicts()
84
85     if options.patch:
86         if args:
87             raise CmdException, \
88                   'Only full refresh is available with the --patch option'
89         patch = options.patch
90         if not crt_series.patch_applied(patch):
91             raise CmdException, 'Patches "%s" not applied' % patch
92     else:
93         patch = crt_series.get_current()
94         if not patch:
95             raise CmdException, 'No patches applied'
96
97     if not options.force:
98         check_head_top_equal()
99
100     if options.undo:
101         print 'Undoing the "%s" refresh...' % patch,
102         sys.stdout.flush()
103         crt_series.undo_refresh()
104         print 'done'
105         return
106
107     if options.author:
108         options.authname, options.authemail = name_email(options.author)
109
110     if options.sign:
111         sign_str = 'Signed-off-by'
112         if options.ack:
113             raise CmdException, '--ack and --sign were both specified'
114     elif options.ack:
115         sign_str = 'Acked-by'
116     else:
117         sign_str = None
118
119     if git.local_changes() \
120            or not crt_series.head_top_equal() \
121            or options.edit or options.message \
122            or options.authname or options.authemail or options.authdate \
123            or options.commname or options.commemail \
124            or options.sign or options.ack:
125
126         if options.patch:
127             applied = crt_series.get_applied()
128             between = applied[:applied.index(patch):-1]
129             pop_patches(between, keep = True)
130
131         print 'Refreshing patch "%s"...' % patch,
132         sys.stdout.flush()
133
134         if autoresolved == 'yes':
135             resolved_all()
136         crt_series.refresh_patch(files = args,
137                                  message = options.message,
138                                  edit = options.edit,
139                                  show_patch = options.showpatch,
140                                  author_name = options.authname,
141                                  author_email = options.authemail,
142                                  author_date = options.authdate,
143                                  committer_name = options.commname,
144                                  committer_email = options.commemail,
145                                  backup = True, sign_str = sign_str)
146
147         print 'done'
148
149         if options.patch:
150             between.reverse()
151             push_patches(between)
152     else:
153         print 'Patch "%s" is already up to date' % patch