1 """Basic quilt-like functionality
5 Copyright (C) 2005, Catalin Marinas <catalin.marinas@gmail.com>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License version 2 as
9 published by the Free Software Foundation.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 from optparse import OptionParser, make_option
24 from stgit.utils import *
25 from stgit import stack, git, gitmergeonefile
26 from stgit.version import version
27 from stgit.config import config
28 from stgit.commands.common import *
31 import stgit.commands.add
32 import stgit.commands.applied
33 import stgit.commands.branch
34 import stgit.commands.delete
35 import stgit.commands.diff
36 import stgit.commands.clean
37 import stgit.commands.clone
38 import stgit.commands.commit
39 import stgit.commands.export
40 import stgit.commands.files
41 import stgit.commands.float
42 import stgit.commands.fold
43 import stgit.commands.goto
44 import stgit.commands.id
45 import stgit.commands.imprt
46 import stgit.commands.init
47 import stgit.commands.log
48 import stgit.commands.mail
49 import stgit.commands.new
50 import stgit.commands.patches
51 import stgit.commands.pick
52 import stgit.commands.pop
53 import stgit.commands.pull
54 import stgit.commands.push
55 import stgit.commands.refresh
56 import stgit.commands.rename
57 import stgit.commands.resolved
58 import stgit.commands.rm
59 import stgit.commands.series
60 import stgit.commands.show
61 import stgit.commands.status
62 import stgit.commands.top
63 import stgit.commands.unapplied
64 import stgit.commands.uncommit
71 'add': stgit.commands.add,
72 'applied': stgit.commands.applied,
73 'branch': stgit.commands.branch,
74 'delete': stgit.commands.delete,
75 'diff': stgit.commands.diff,
76 'clean': stgit.commands.clean,
77 'clone': stgit.commands.clone,
78 'commit': stgit.commands.commit,
79 'export': stgit.commands.export,
80 'files': stgit.commands.files,
81 'float': stgit.commands.float,
82 'fold': stgit.commands.fold,
83 'goto': stgit.commands.goto,
84 'id': stgit.commands.id,
85 'import': stgit.commands.imprt,
86 'init': stgit.commands.init,
87 'log': stgit.commands.log,
88 'mail': stgit.commands.mail,
89 'new': stgit.commands.new,
90 'patches': stgit.commands.patches,
91 'pick': stgit.commands.pick,
92 'pop': stgit.commands.pop,
93 'pull': stgit.commands.pull,
94 'push': stgit.commands.push,
95 'refresh': stgit.commands.refresh,
96 'rename': stgit.commands.rename,
97 'resolved': stgit.commands.resolved,
98 'rm': stgit.commands.rm,
99 'series': stgit.commands.series,
100 'show': stgit.commands.show,
101 'status': stgit.commands.status,
102 'top': stgit.commands.top,
103 'unapplied':stgit.commands.unapplied,
104 'uncommit': stgit.commands.uncommit,
107 # classification: repository, stack, patch, working copy
151 def _print_helpstring(cmd):
152 print ' ' + cmd + ' ' * (12 - len(cmd)) + commands[cmd].help
155 print 'usage: %s <command> [options]' % os.path.basename(sys.argv[0])
157 print 'Generic commands:'
158 print ' help print the detailed command usage'
159 print ' version display version information'
160 print ' copyright display copyright information'
161 # unclassified commands if any
162 cmds = commands.keys()
165 if not cmd in repocommands and not cmd in stackcommands \
166 and not cmd in patchcommands and not cmd in wccommands:
167 _print_helpstring(cmd)
170 print 'Repository commands:'
171 for cmd in repocommands:
172 _print_helpstring(cmd)
175 print 'Stack commands:'
176 for cmd in stackcommands:
177 _print_helpstring(cmd)
180 print 'Patch commands:'
181 for cmd in patchcommands:
182 _print_helpstring(cmd)
185 print 'Working-copy commands:'
186 for cmd in wccommands:
187 _print_helpstring(cmd)
190 # The main function (command dispatcher)
195 prog = os.path.basename(sys.argv[0])
197 if len(sys.argv) < 2:
198 print >> sys.stderr, 'usage: %s <command>' % prog
199 print >> sys.stderr, \
200 ' Try "%s --help" for a list of supported commands' % prog
205 if cmd in ['-h', '--help']:
206 if len(sys.argv) == 3 and sys.argv[2] in commands:
208 sys.argv[2] = '--help'
213 if len(sys.argv) == 3 and not sys.argv[2] in ['-h', '--help']:
215 if not cmd in commands:
216 print >> sys.stderr, '%s help: "%s" command unknown' \
220 sys.argv[0] += ' %s' % cmd
221 command = commands[cmd]
222 parser = OptionParser(usage = command.usage,
223 option_list = command.options)
228 if cmd in ['-v', '--version', 'version']:
229 print 'Stacked GIT %s' % version
230 os.system('git --version')
231 print 'Python version %s' % sys.version
233 if cmd in ['copyright']:
236 if not cmd in commands:
237 print >> sys.stderr, 'Unknown command: %s' % cmd
238 print >> sys.stderr, ' Try "%s help" for a list of supported ' \
242 # re-build the command line arguments
243 sys.argv[0] += ' %s' % cmd
246 command = commands[cmd]
247 usage = command.usage.split('\n')[0].strip()
248 parser = OptionParser(usage = usage, option_list = command.options)
249 options, args = parser.parse_args()
251 # 'clone' doesn't expect an already initialised GIT tree. A Series
252 # object will be created after the GIT tree is cloned
254 if hasattr(options, 'branch') and options.branch:
255 command.crt_series = stack.Series(options.branch)
257 command.crt_series = stack.Series()
258 stgit.commands.common.crt_series = command.crt_series
260 command.func(parser, options, args)
261 except (IOError, CmdException, stack.StackException, git.GitException,
262 gitmergeonefile.GitMergeException), err:
263 print >> sys.stderr, '%s %s: %s' % (prog, cmd, err)
265 except KeyboardInterrupt: