Refactor output handling to break circular dependency
[stgit] / stgit / commands / commit.py
CommitLineData
6a093bbb
CM
1__copyright__ = """
2Copyright (C) 2005, Catalin Marinas <catalin.marinas@gmail.com>
3
4This program is free software; you can redistribute it and/or modify
5it under the terms of the GNU General Public License version 2 as
6published by the Free Software Foundation.
7
8This program is distributed in the hope that it will be useful,
9but WITHOUT ANY WARRANTY; without even the implied warranty of
10MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11GNU General Public License for more details.
12
13You should have received a copy of the GNU General Public License
14along with this program; if not, write to the Free Software
15Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16"""
17
18import sys, os
19from optparse import OptionParser, make_option
20
21from stgit.commands.common import *
22from stgit.utils import *
5e888f30 23from stgit.out import *
6a093bbb
CM
24from stgit import stack, git
25
26help = 'permanently store the applied patches into stack base'
27usage = """%prog [options]
28
29Merge the applied patches into the base of the current stack and
30remove them from the series while advancing the base.
31
32Use this command only if you want to permanently store the applied
33patches and no longer manage them with StGIT."""
34
35options = []
36
37
38def func(parser, options, args):
39 """Merge the applied patches into the base of the current stack
40 and remove them from the series while advancing the base
41 """
42 if len(args) != 0:
43 parser.error('incorrect number of arguments')
44
45 check_local_changes()
46 check_conflicts()
47 check_head_top_equal()
48
49 applied = crt_series.get_applied()
50 if not applied:
51 raise CmdException, 'No patches applied'
52
0b4b9499
CL
53 if crt_series.get_protected():
54 raise CmdException, 'This branch is protected. Commit is not permitted'
55
6a093bbb
CM
56 crt_head = git.get_head()
57
27ac2b7e 58 out.start('Committing %d patches' % len(applied))
6a093bbb
CM
59
60 crt_series.pop_patch(applied[0])
61 git.switch(crt_head)
62
63 for patch in applied:
64 crt_series.delete_patch(patch)
65
27ac2b7e 66 out.done()