chiark / gitweb /
7c68ba6380e9d542a8546e08c8b92fb77dc8c18b
[stgit] / stgit / commands / status.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 stgit.argparse import opt
21 from stgit.commands.common import *
22 from stgit.utils import *
23 from stgit import stack, git
24
25 help = 'Show the tree status'
26 kind = 'wc'
27 usage = ['[options] [<files or dirs>]']
28 description = """
29 Show the status of the whole working copy or the given files. The
30 command also shows the files in the current directory which are not
31 under revision control. The files are prefixed as follows:
32
33   M - locally modified
34   N - newly added to the repository
35   D - deleted from the repository
36   C - conflict
37   ? - unknown
38
39 An 'stg refresh' command clears the status of the modified, new and
40 deleted files."""
41
42 options = [
43     opt('-m', '--modified', action = 'store_true',
44         short = 'Show modified files only'),
45     opt('-n', '--new', action = 'store_true',
46         short = 'Show new files only'),
47     opt('-d', '--deleted', action = 'store_true',
48         short = 'Show deleted files only'),
49     opt('-c', '--conflict', action = 'store_true',
50         short = 'Show conflict files only'),
51     opt('-u', '--unknown', action = 'store_true',
52         short = 'Show unknown files only'),
53     opt('-x', '--noexclude', action = 'store_true',
54         short = 'Do not exclude any files from listing'),
55     opt('--reset', action = 'store_true',
56         short = 'Reset the current tree changes')]
57
58 directory = DirectoryHasRepository(needs_current_series = False)
59
60 def status(files, modified, new, deleted, conflict, unknown, noexclude):
61     """Show the tree status
62     """
63     cache_files = git.tree_status(files,
64                                   unknown = (not files),
65                                   noexclude = noexclude)
66     filtered = (modified or new or deleted or conflict or unknown)
67
68     if filtered:
69         filestat = []
70         if modified:
71             filestat.append('M')
72         if new:
73             filestat.append('A')
74             filestat.append('N')
75         if deleted:
76             filestat.append('D')
77         if conflict:
78             filestat.append('C')
79         if unknown:
80             filestat.append('?')
81         cache_files = [x for x in cache_files if x[0] in filestat]
82
83     output = []
84     for st, fn in cache_files:
85         if filtered:
86             output.append(fn)
87         else:
88             output.append('%s %s' % (st, fn))
89     for o in sorted(output):
90         out.stdout(o)
91
92 def func(parser, options, args):
93     """Show the tree status
94     """
95     args = git.ls_files(args)
96     directory.cd_to_topdir()
97
98     if options.reset:
99         if args:
100             conflicts = git.get_conflicts()
101             git.resolved([fn for fn in args if fn in conflicts])
102             git.reset(args)
103         else:
104             resolved_all()
105             git.reset()
106     else:
107         status(args, options.modified, options.new, options.deleted,
108                options.conflict, options.unknown, options.noexclude)