Automatic bash completion
[stgit] / stgit / commands / status.py
CommitLineData
fcee87cf
CM
1
2__copyright__ = """
3Copyright (C) 2005, Catalin Marinas <catalin.marinas@gmail.com>
4
5This program is free software; you can redistribute it and/or modify
6it under the terms of the GNU General Public License version 2 as
7published by the Free Software Foundation.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program; if not, write to the Free Software
16Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17"""
18
19import sys, os
575bbdae 20from stgit.argparse import opt
fcee87cf
CM
21from stgit.commands.common import *
22from stgit.utils import *
6c8a90e1 23from stgit import argparse, stack, git
fcee87cf 24
575bbdae 25help = 'Show the tree status'
33ff9cdd 26kind = 'wc'
575bbdae
KH
27usage = ['[options] [<files or dirs>]']
28description = """
26aab5b0
CM
29Show the status of the whole working copy or the given files. The
30command also shows the files in the current directory which are not
31under 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
575bbdae
KH
39An 'stg refresh' command clears the status of the modified, new and
40deleted files."""
fcee87cf 41
6c8a90e1 42args = [argparse.files]
575bbdae
KH
43options = [
44 opt('-m', '--modified', action = 'store_true',
45 short = 'Show modified files only'),
46 opt('-n', '--new', action = 'store_true',
47 short = 'Show new files only'),
48 opt('-d', '--deleted', action = 'store_true',
49 short = 'Show deleted files only'),
50 opt('-c', '--conflict', action = 'store_true',
51 short = 'Show conflict files only'),
52 opt('-u', '--unknown', action = 'store_true',
53 short = 'Show unknown files only'),
54 opt('-x', '--noexclude', action = 'store_true',
55 short = 'Do not exclude any files from listing'),
56 opt('--reset', action = 'store_true',
57 short = 'Reset the current tree changes')]
fcee87cf 58
117ed129 59directory = DirectoryHasRepository(needs_current_series = False, log = False)
fcee87cf 60
7a6a45b5 61def status(files, modified, new, deleted, conflict, unknown, noexclude):
4361d795
DK
62 """Show the tree status
63 """
64 cache_files = git.tree_status(files,
d4356ac6 65 unknown = (not files),
a6c4be12 66 noexclude = noexclude)
4361d795
DK
67 filtered = (modified or new or deleted or conflict or unknown)
68
69 if filtered:
70 filestat = []
71 if modified:
72 filestat.append('M')
73 if new:
74 filestat.append('A')
75 filestat.append('N')
76 if deleted:
77 filestat.append('D')
78 if conflict:
79 filestat.append('C')
80 if unknown:
81 filestat.append('?')
82 cache_files = [x for x in cache_files if x[0] in filestat]
83
cbd2f5f3
KH
84 output = []
85 for st, fn in cache_files:
cbd2f5f3
KH
86 if filtered:
87 output.append(fn)
4361d795 88 else:
cbd2f5f3
KH
89 output.append('%s %s' % (st, fn))
90 for o in sorted(output):
91 out.stdout(o)
4361d795 92
fcee87cf
CM
93def func(parser, options, args):
94 """Show the tree status
95 """
d4356ac6
CM
96 args = git.ls_files(args)
97 directory.cd_to_topdir()
98
94227db3 99 if options.reset:
117ed129 100 directory.log = True
49e316b9 101 if args:
29197bc0 102 conflicts = git.get_conflicts()
6ce2faa0 103 git.resolved([fn for fn in args if fn in conflicts])
49e316b9
CM
104 git.reset(args)
105 else:
106 resolved_all()
107 git.reset()
94227db3 108 else:
4361d795 109 status(args, options.modified, options.new, options.deleted,
a6c4be12 110 options.conflict, options.unknown, options.noexclude)