Check bad head and clean iw before StackTransaction
[stgit.git] / stgit / commands / hide.py
blob2b5064c637dd7706fb0548e960904bff2afb7817
1 from stgit.argparse import opt, patch_range
2 from stgit.commands.common import (
3 DirectoryHasRepository,
4 check_head_top_equal,
5 parse_patches,
7 from stgit.lib import transaction
8 from stgit.out import out
10 __copyright__ = """
11 Copyright (C) 2009, Catalin Marinas <catalin.marinas@gmail.com>
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License version 2 as
15 published by the Free Software Foundation.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, see http://www.gnu.org/licenses/.
24 """
26 help = 'Hide a patch in the series'
27 kind = 'stack'
28 usage = ['[options] [--] <patch-range>']
29 description = """
30 Hide a range of unapplied patches so that they are no longer shown in
31 the plain 'series' command output."""
33 args = [patch_range('applied_patches', 'unapplied_patches')]
34 options = [
35 opt(
36 '-b',
37 '--branch',
38 args=['stg_branches'],
39 short='Use BRANCH instead of the default branch',
43 directory = DirectoryHasRepository()
46 def func(parser, options, args):
47 """Hide a range of patch in the series."""
48 stack = directory.repository.current_stack
49 check_head_top_equal(stack)
50 trans = transaction.StackTransaction(stack)
52 if not args:
53 parser.error('No patches specified')
55 patches = parse_patches(args, trans.all_patches)
56 for p in patches:
57 if p in trans.hidden:
58 out.warn('Patch "%s" already hidden' % p)
59 patches = [p for p in patches if p not in set(trans.hidden)]
61 applied = [p for p in trans.applied if p not in set(patches)]
62 unapplied = [p for p in trans.unapplied if p not in set(patches)]
63 hidden = patches + trans.hidden
65 trans.reorder_patches(applied, unapplied, hidden)
66 return trans.run('hide')