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
.assimilate
34 import stgit
.commands
.branch
35 import stgit
.commands
.delete
36 import stgit
.commands
.diff
37 import stgit
.commands
.clean
38 import stgit
.commands
.clone
39 import stgit
.commands
.commit
40 import stgit
.commands
.export
41 import stgit
.commands
.files
42 import stgit
.commands
.float
43 import stgit
.commands
.fold
44 import stgit
.commands
.goto
45 import stgit
.commands
.id
46 import stgit
.commands
.imprt
47 import stgit
.commands
.init
48 import stgit
.commands
.log
49 import stgit
.commands
.mail
50 import stgit
.commands
.new
51 import stgit
.commands
.patches
52 import stgit
.commands
.pick
53 import stgit
.commands
.pop
54 import stgit
.commands
.pull
55 import stgit
.commands
.push
56 import stgit
.commands
.refresh
57 import stgit
.commands
.rename
58 import stgit
.commands
.resolved
59 import stgit
.commands
.rm
60 import stgit
.commands
.series
61 import stgit
.commands
.show
62 import stgit
.commands
.status
63 import stgit
.commands
.top
64 import stgit
.commands
.unapplied
65 import stgit
.commands
.uncommit
72 'add': stgit
.commands
.add
,
73 'applied': stgit
.commands
.applied
,
74 'assimilate': stgit
.commands
.assimilate
,
75 'branch': stgit
.commands
.branch
,
76 'delete': stgit
.commands
.delete
,
77 'diff': stgit
.commands
.diff
,
78 'clean': stgit
.commands
.clean
,
79 'clone': stgit
.commands
.clone
,
80 'commit': stgit
.commands
.commit
,
81 'export': stgit
.commands
.export
,
82 'files': stgit
.commands
.files
,
83 'float': stgit
.commands
.float,
84 'fold': stgit
.commands
.fold
,
85 'goto': stgit
.commands
.goto
,
86 'id': stgit
.commands
.id,
87 'import': stgit
.commands
.imprt
,
88 'init': stgit
.commands
.init
,
89 'log': stgit
.commands
.log
,
90 'mail': stgit
.commands
.mail
,
91 'new': stgit
.commands
.new
,
92 'patches': stgit
.commands
.patches
,
93 'pick': stgit
.commands
.pick
,
94 'pop': stgit
.commands
.pop
,
95 'pull': stgit
.commands
.pull
,
96 'push': stgit
.commands
.push
,
97 'refresh': stgit
.commands
.refresh
,
98 'rename': stgit
.commands
.rename
,
99 'resolved': stgit
.commands
.resolved
,
100 'rm': stgit
.commands
.rm
,
101 'series': stgit
.commands
.series
,
102 'show': stgit
.commands
.show
,
103 'status': stgit
.commands
.status
,
104 'top': stgit
.commands
.top
,
105 'unapplied':stgit
.commands
.unapplied
,
106 'uncommit': stgit
.commands
.uncommit
,
109 # classification: repository, stack, patch, working copy
154 def _print_helpstring(cmd
):
155 print ' ' + cmd
+ ' ' * (12 - len(cmd
)) + commands
[cmd
].help
158 print 'usage: %s <command> [options]' % os
.path
.basename(sys
.argv
[0])
160 print 'Generic commands:'
161 print ' help print the detailed command usage'
162 print ' version display version information'
163 print ' copyright display copyright information'
164 # unclassified commands if any
165 cmds
= commands
.keys()
168 if not cmd
in repocommands
and not cmd
in stackcommands \
169 and not cmd
in patchcommands
and not cmd
in wccommands
:
170 _print_helpstring(cmd
)
173 print 'Repository commands:'
174 for cmd
in repocommands
:
175 _print_helpstring(cmd
)
178 print 'Stack commands:'
179 for cmd
in stackcommands
:
180 _print_helpstring(cmd
)
183 print 'Patch commands:'
184 for cmd
in patchcommands
:
185 _print_helpstring(cmd
)
188 print 'Working-copy commands:'
189 for cmd
in wccommands
:
190 _print_helpstring(cmd
)
193 # The main function (command dispatcher)
198 prog
= os
.path
.basename(sys
.argv
[0])
200 if len(sys
.argv
) < 2:
201 print >> sys
.stderr
, 'usage: %s <command>' % prog
202 print >> sys
.stderr
, \
203 ' Try "%s --help" for a list of supported commands' % prog
208 if cmd
in ['-h', '--help']:
209 if len(sys
.argv
) >= 3 and sys
.argv
[2] in commands
:
211 sys
.argv
[2] = '--help'
216 if len(sys
.argv
) == 3 and not sys
.argv
[2] in ['-h', '--help']:
218 if not cmd
in commands
:
219 print >> sys
.stderr
, '%s help: "%s" command unknown' \
223 sys
.argv
[0] += ' %s' % cmd
224 command
= commands
[cmd
]
225 parser
= OptionParser(usage
= command
.usage
,
226 option_list
= command
.options
)
231 if cmd
in ['-v', '--version', 'version']:
232 print 'Stacked GIT %s' % version
233 os
.system('git --version')
234 print 'Python version %s' % sys
.version
236 if cmd
in ['copyright']:
239 if not cmd
in commands
:
240 print >> sys
.stderr
, 'Unknown command: %s' % cmd
241 print >> sys
.stderr
, ' Try "%s help" for a list of supported ' \
245 # re-build the command line arguments
246 sys
.argv
[0] += ' %s' % cmd
249 command
= commands
[cmd
]
250 usage
= command
.usage
.split('\n')[0].strip()
251 parser
= OptionParser(usage
= usage
, option_list
= command
.options
)
252 options
, args
= parser
.parse_args()
254 # 'clone' doesn't expect an already initialised GIT tree. A Series
255 # object will be created after the GIT tree is cloned
257 if hasattr(options
, 'branch') and options
.branch
:
258 command
.crt_series
= stack
.Series(options
.branch
)
260 command
.crt_series
= stack
.Series()
261 stgit
.commands
.common
.crt_series
= command
.crt_series
263 command
.func(parser
, options
, args
)
264 except (IOError, CmdException
, stack
.StackException
, git
.GitException
,
265 gitmergeonefile
.GitMergeException
), err
:
266 print >> sys
.stderr
, '%s %s: %s' %
(prog
, cmd
, err
)
268 except KeyboardInterrupt: