##// END OF EJS Templates
githelp: add some minimal help for pickaxe functionality...
Augie Fackler -
r45419:94f227ba default
parent child Browse files
Show More
@@ -1,1261 +1,1270 b''
1 # githelp.py - Try to map Git commands to Mercurial equivalents.
1 # githelp.py - Try to map Git commands to Mercurial equivalents.
2 #
2 #
3 # Copyright 2013 Facebook, Inc.
3 # Copyright 2013 Facebook, Inc.
4 #
4 #
5 # This software may be used and distributed according to the terms of the
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version.
6 # GNU General Public License version 2 or any later version.
7 """try mapping git commands to Mercurial commands
7 """try mapping git commands to Mercurial commands
8
8
9 Tries to map a given git command to a Mercurial command:
9 Tries to map a given git command to a Mercurial command:
10
10
11 $ hg githelp -- git checkout master
11 $ hg githelp -- git checkout master
12 hg update master
12 hg update master
13
13
14 If an unknown command or parameter combination is detected, an error is
14 If an unknown command or parameter combination is detected, an error is
15 produced.
15 produced.
16 """
16 """
17
17
18 from __future__ import absolute_import
18 from __future__ import absolute_import
19
19
20 import getopt
20 import getopt
21 import re
21 import re
22
22
23 from mercurial.i18n import _
23 from mercurial.i18n import _
24 from mercurial import (
24 from mercurial import (
25 encoding,
25 encoding,
26 error,
26 error,
27 fancyopts,
27 fancyopts,
28 pycompat,
28 pycompat,
29 registrar,
29 registrar,
30 scmutil,
30 scmutil,
31 )
31 )
32 from mercurial.utils import procutil
32 from mercurial.utils import procutil
33
33
34 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
34 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
35 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
35 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
36 # be specifying the version(s) of Mercurial they are tested with, or
36 # be specifying the version(s) of Mercurial they are tested with, or
37 # leave the attribute unspecified.
37 # leave the attribute unspecified.
38 testedwith = b'ships-with-hg-core'
38 testedwith = b'ships-with-hg-core'
39
39
40 cmdtable = {}
40 cmdtable = {}
41 command = registrar.command(cmdtable)
41 command = registrar.command(cmdtable)
42
42
43
43
44 def convert(s):
44 def convert(s):
45 if s.startswith(b"origin/"):
45 if s.startswith(b"origin/"):
46 return s[7:]
46 return s[7:]
47 if b'HEAD' in s:
47 if b'HEAD' in s:
48 s = s.replace(b'HEAD', b'.')
48 s = s.replace(b'HEAD', b'.')
49 # HEAD~ in git is .~1 in mercurial
49 # HEAD~ in git is .~1 in mercurial
50 s = re.sub(b'~$', b'~1', s)
50 s = re.sub(b'~$', b'~1', s)
51 return s
51 return s
52
52
53
53
54 @command(
54 @command(
55 b'githelp|git',
55 b'githelp|git',
56 [],
56 [],
57 _(b'hg githelp'),
57 _(b'hg githelp'),
58 helpcategory=command.CATEGORY_HELP,
58 helpcategory=command.CATEGORY_HELP,
59 helpbasic=True,
59 helpbasic=True,
60 )
60 )
61 def githelp(ui, repo, *args, **kwargs):
61 def githelp(ui, repo, *args, **kwargs):
62 '''suggests the Mercurial equivalent of the given git command
62 '''suggests the Mercurial equivalent of the given git command
63
63
64 Usage: hg githelp -- <git command>
64 Usage: hg githelp -- <git command>
65 '''
65 '''
66
66
67 if len(args) == 0 or (len(args) == 1 and args[0] == b'git'):
67 if len(args) == 0 or (len(args) == 1 and args[0] == b'git'):
68 raise error.Abort(
68 raise error.Abort(
69 _(b'missing git command - usage: hg githelp -- <git command>')
69 _(b'missing git command - usage: hg githelp -- <git command>')
70 )
70 )
71
71
72 if args[0] == b'git':
72 if args[0] == b'git':
73 args = args[1:]
73 args = args[1:]
74
74
75 cmd = args[0]
75 cmd = args[0]
76 if not cmd in gitcommands:
76 if not cmd in gitcommands:
77 raise error.Abort(_(b"error: unknown git command %s") % cmd)
77 raise error.Abort(_(b"error: unknown git command %s") % cmd)
78
78
79 ui.pager(b'githelp')
79 ui.pager(b'githelp')
80 args = args[1:]
80 args = args[1:]
81 return gitcommands[cmd](ui, repo, *args, **kwargs)
81 return gitcommands[cmd](ui, repo, *args, **kwargs)
82
82
83
83
84 def parseoptions(ui, cmdoptions, args):
84 def parseoptions(ui, cmdoptions, args):
85 cmdoptions = list(cmdoptions)
85 cmdoptions = list(cmdoptions)
86 opts = {}
86 opts = {}
87 args = list(args)
87 args = list(args)
88 while True:
88 while True:
89 try:
89 try:
90 args = fancyopts.fancyopts(list(args), cmdoptions, opts, True)
90 args = fancyopts.fancyopts(list(args), cmdoptions, opts, True)
91 break
91 break
92 except getopt.GetoptError as ex:
92 except getopt.GetoptError as ex:
93 if "requires argument" in ex.msg:
93 if "requires argument" in ex.msg:
94 raise
94 raise
95 if ('--' + ex.opt) in ex.msg:
95 if ('--' + ex.opt) in ex.msg:
96 flag = b'--' + pycompat.bytestr(ex.opt)
96 flag = b'--' + pycompat.bytestr(ex.opt)
97 elif ('-' + ex.opt) in ex.msg:
97 elif ('-' + ex.opt) in ex.msg:
98 flag = b'-' + pycompat.bytestr(ex.opt)
98 flag = b'-' + pycompat.bytestr(ex.opt)
99 else:
99 else:
100 raise error.Abort(
100 raise error.Abort(
101 _(b"unknown option %s") % pycompat.bytestr(ex.opt)
101 _(b"unknown option %s") % pycompat.bytestr(ex.opt)
102 )
102 )
103 try:
103 try:
104 args.remove(flag)
104 args.remove(flag)
105 except Exception:
105 except Exception:
106 msg = _(b"unknown option '%s' packed with other options")
106 msg = _(b"unknown option '%s' packed with other options")
107 hint = _(b"please try passing the option as its own flag: -%s")
107 hint = _(b"please try passing the option as its own flag: -%s")
108 raise error.Abort(
108 raise error.Abort(
109 msg % pycompat.bytestr(ex.opt),
109 msg % pycompat.bytestr(ex.opt),
110 hint=hint % pycompat.bytestr(ex.opt),
110 hint=hint % pycompat.bytestr(ex.opt),
111 )
111 )
112
112
113 ui.warn(_(b"ignoring unknown option %s\n") % flag)
113 ui.warn(_(b"ignoring unknown option %s\n") % flag)
114
114
115 args = list([convert(x) for x in args])
115 args = list([convert(x) for x in args])
116 opts = dict(
116 opts = dict(
117 [
117 [
118 (k, convert(v)) if isinstance(v, bytes) else (k, v)
118 (k, convert(v)) if isinstance(v, bytes) else (k, v)
119 for k, v in pycompat.iteritems(opts)
119 for k, v in pycompat.iteritems(opts)
120 ]
120 ]
121 )
121 )
122
122
123 return args, opts
123 return args, opts
124
124
125
125
126 class Command(object):
126 class Command(object):
127 def __init__(self, name):
127 def __init__(self, name):
128 self.name = name
128 self.name = name
129 self.args = []
129 self.args = []
130 self.opts = {}
130 self.opts = {}
131
131
132 def __bytes__(self):
132 def __bytes__(self):
133 cmd = b"hg " + self.name
133 cmd = b"hg " + self.name
134 if self.opts:
134 if self.opts:
135 for k, values in sorted(pycompat.iteritems(self.opts)):
135 for k, values in sorted(pycompat.iteritems(self.opts)):
136 for v in values:
136 for v in values:
137 if v:
137 if v:
138 if isinstance(v, int):
138 if isinstance(v, int):
139 fmt = b' %s %d'
139 fmt = b' %s %d'
140 else:
140 else:
141 fmt = b' %s %s'
141 fmt = b' %s %s'
142
142
143 cmd += fmt % (k, v)
143 cmd += fmt % (k, v)
144 else:
144 else:
145 cmd += b" %s" % (k,)
145 cmd += b" %s" % (k,)
146 if self.args:
146 if self.args:
147 cmd += b" "
147 cmd += b" "
148 cmd += b" ".join(self.args)
148 cmd += b" ".join(self.args)
149 return cmd
149 return cmd
150
150
151 __str__ = encoding.strmethod(__bytes__)
151 __str__ = encoding.strmethod(__bytes__)
152
152
153 def append(self, value):
153 def append(self, value):
154 self.args.append(value)
154 self.args.append(value)
155
155
156 def extend(self, values):
156 def extend(self, values):
157 self.args.extend(values)
157 self.args.extend(values)
158
158
159 def __setitem__(self, key, value):
159 def __setitem__(self, key, value):
160 values = self.opts.setdefault(key, [])
160 values = self.opts.setdefault(key, [])
161 values.append(value)
161 values.append(value)
162
162
163 def __and__(self, other):
163 def __and__(self, other):
164 return AndCommand(self, other)
164 return AndCommand(self, other)
165
165
166
166
167 class AndCommand(object):
167 class AndCommand(object):
168 def __init__(self, left, right):
168 def __init__(self, left, right):
169 self.left = left
169 self.left = left
170 self.right = right
170 self.right = right
171
171
172 def __str__(self):
172 def __str__(self):
173 return b"%s && %s" % (self.left, self.right)
173 return b"%s && %s" % (self.left, self.right)
174
174
175 def __and__(self, other):
175 def __and__(self, other):
176 return AndCommand(self, other)
176 return AndCommand(self, other)
177
177
178
178
179 def add(ui, repo, *args, **kwargs):
179 def add(ui, repo, *args, **kwargs):
180 cmdoptions = [
180 cmdoptions = [
181 (b'A', b'all', None, b''),
181 (b'A', b'all', None, b''),
182 (b'p', b'patch', None, b''),
182 (b'p', b'patch', None, b''),
183 ]
183 ]
184 args, opts = parseoptions(ui, cmdoptions, args)
184 args, opts = parseoptions(ui, cmdoptions, args)
185
185
186 if opts.get(b'patch'):
186 if opts.get(b'patch'):
187 ui.status(
187 ui.status(
188 _(
188 _(
189 b"note: Mercurial will commit when complete, "
189 b"note: Mercurial will commit when complete, "
190 b"as there is no staging area in Mercurial\n\n"
190 b"as there is no staging area in Mercurial\n\n"
191 )
191 )
192 )
192 )
193 cmd = Command(b'commit --interactive')
193 cmd = Command(b'commit --interactive')
194 else:
194 else:
195 cmd = Command(b"add")
195 cmd = Command(b"add")
196
196
197 if not opts.get(b'all'):
197 if not opts.get(b'all'):
198 cmd.extend(args)
198 cmd.extend(args)
199 else:
199 else:
200 ui.status(
200 ui.status(
201 _(
201 _(
202 b"note: use hg addremove to remove files that have "
202 b"note: use hg addremove to remove files that have "
203 b"been deleted\n\n"
203 b"been deleted\n\n"
204 )
204 )
205 )
205 )
206
206
207 ui.status((bytes(cmd)), b"\n")
207 ui.status((bytes(cmd)), b"\n")
208
208
209
209
210 def am(ui, repo, *args, **kwargs):
210 def am(ui, repo, *args, **kwargs):
211 cmdoptions = []
211 cmdoptions = []
212 parseoptions(ui, cmdoptions, args)
212 parseoptions(ui, cmdoptions, args)
213 cmd = Command(b'import')
213 cmd = Command(b'import')
214 ui.status(bytes(cmd), b"\n")
214 ui.status(bytes(cmd), b"\n")
215
215
216
216
217 def apply(ui, repo, *args, **kwargs):
217 def apply(ui, repo, *args, **kwargs):
218 cmdoptions = [
218 cmdoptions = [
219 (b'p', b'p', int, b''),
219 (b'p', b'p', int, b''),
220 (b'', b'directory', b'', b''),
220 (b'', b'directory', b'', b''),
221 ]
221 ]
222 args, opts = parseoptions(ui, cmdoptions, args)
222 args, opts = parseoptions(ui, cmdoptions, args)
223
223
224 cmd = Command(b'import --no-commit')
224 cmd = Command(b'import --no-commit')
225 if opts.get(b'p'):
225 if opts.get(b'p'):
226 cmd[b'-p'] = opts.get(b'p')
226 cmd[b'-p'] = opts.get(b'p')
227 if opts.get(b'directory'):
227 if opts.get(b'directory'):
228 cmd[b'--prefix'] = opts.get(b'directory')
228 cmd[b'--prefix'] = opts.get(b'directory')
229 cmd.extend(args)
229 cmd.extend(args)
230
230
231 ui.status((bytes(cmd)), b"\n")
231 ui.status((bytes(cmd)), b"\n")
232
232
233
233
234 def bisect(ui, repo, *args, **kwargs):
234 def bisect(ui, repo, *args, **kwargs):
235 ui.status(_(b"see 'hg help bisect' for how to use bisect\n\n"))
235 ui.status(_(b"see 'hg help bisect' for how to use bisect\n\n"))
236
236
237
237
238 def blame(ui, repo, *args, **kwargs):
238 def blame(ui, repo, *args, **kwargs):
239 cmdoptions = []
239 cmdoptions = []
240 args, opts = parseoptions(ui, cmdoptions, args)
240 args, opts = parseoptions(ui, cmdoptions, args)
241 cmd = Command(b'annotate -udl')
241 cmd = Command(b'annotate -udl')
242 cmd.extend([convert(v) for v in args])
242 cmd.extend([convert(v) for v in args])
243 ui.status((bytes(cmd)), b"\n")
243 ui.status((bytes(cmd)), b"\n")
244
244
245
245
246 def branch(ui, repo, *args, **kwargs):
246 def branch(ui, repo, *args, **kwargs):
247 cmdoptions = [
247 cmdoptions = [
248 (b'', b'set-upstream', None, b''),
248 (b'', b'set-upstream', None, b''),
249 (b'', b'set-upstream-to', b'', b''),
249 (b'', b'set-upstream-to', b'', b''),
250 (b'd', b'delete', None, b''),
250 (b'd', b'delete', None, b''),
251 (b'D', b'delete', None, b''),
251 (b'D', b'delete', None, b''),
252 (b'm', b'move', None, b''),
252 (b'm', b'move', None, b''),
253 (b'M', b'move', None, b''),
253 (b'M', b'move', None, b''),
254 ]
254 ]
255 args, opts = parseoptions(ui, cmdoptions, args)
255 args, opts = parseoptions(ui, cmdoptions, args)
256
256
257 cmd = Command(b"bookmark")
257 cmd = Command(b"bookmark")
258
258
259 if opts.get(b'set_upstream') or opts.get(b'set_upstream_to'):
259 if opts.get(b'set_upstream') or opts.get(b'set_upstream_to'):
260 ui.status(_(b"Mercurial has no concept of upstream branches\n"))
260 ui.status(_(b"Mercurial has no concept of upstream branches\n"))
261 return
261 return
262 elif opts.get(b'delete'):
262 elif opts.get(b'delete'):
263 cmd = Command(b"strip")
263 cmd = Command(b"strip")
264 for branch in args:
264 for branch in args:
265 cmd[b'-B'] = branch
265 cmd[b'-B'] = branch
266 else:
266 else:
267 cmd[b'-B'] = None
267 cmd[b'-B'] = None
268 elif opts.get(b'move'):
268 elif opts.get(b'move'):
269 if len(args) > 0:
269 if len(args) > 0:
270 if len(args) > 1:
270 if len(args) > 1:
271 old = args.pop(0)
271 old = args.pop(0)
272 else:
272 else:
273 # shell command to output the active bookmark for the active
273 # shell command to output the active bookmark for the active
274 # revision
274 # revision
275 old = b'`hg log -T"{activebookmark}" -r .`'
275 old = b'`hg log -T"{activebookmark}" -r .`'
276 else:
276 else:
277 raise error.Abort(_(b'missing newbranch argument'))
277 raise error.Abort(_(b'missing newbranch argument'))
278 new = args[0]
278 new = args[0]
279 cmd[b'-m'] = old
279 cmd[b'-m'] = old
280 cmd.append(new)
280 cmd.append(new)
281 else:
281 else:
282 if len(args) > 1:
282 if len(args) > 1:
283 cmd[b'-r'] = args[1]
283 cmd[b'-r'] = args[1]
284 cmd.append(args[0])
284 cmd.append(args[0])
285 elif len(args) == 1:
285 elif len(args) == 1:
286 cmd.append(args[0])
286 cmd.append(args[0])
287 ui.status((bytes(cmd)), b"\n")
287 ui.status((bytes(cmd)), b"\n")
288
288
289
289
290 def ispath(repo, string):
290 def ispath(repo, string):
291 """
291 """
292 The first argument to git checkout can either be a revision or a path. Let's
292 The first argument to git checkout can either be a revision or a path. Let's
293 generally assume it's a revision, unless it's obviously a path. There are
293 generally assume it's a revision, unless it's obviously a path. There are
294 too many ways to spell revisions in git for us to reasonably catch all of
294 too many ways to spell revisions in git for us to reasonably catch all of
295 them, so let's be conservative.
295 them, so let's be conservative.
296 """
296 """
297 if scmutil.isrevsymbol(repo, string):
297 if scmutil.isrevsymbol(repo, string):
298 # if it's definitely a revision let's not even check if a file of the
298 # if it's definitely a revision let's not even check if a file of the
299 # same name exists.
299 # same name exists.
300 return False
300 return False
301
301
302 cwd = repo.getcwd()
302 cwd = repo.getcwd()
303 if cwd == b'':
303 if cwd == b'':
304 repopath = string
304 repopath = string
305 else:
305 else:
306 repopath = cwd + b'/' + string
306 repopath = cwd + b'/' + string
307
307
308 exists = repo.wvfs.exists(repopath)
308 exists = repo.wvfs.exists(repopath)
309 if exists:
309 if exists:
310 return True
310 return True
311
311
312 manifest = repo[b'.'].manifest()
312 manifest = repo[b'.'].manifest()
313
313
314 didexist = (repopath in manifest) or manifest.hasdir(repopath)
314 didexist = (repopath in manifest) or manifest.hasdir(repopath)
315
315
316 return didexist
316 return didexist
317
317
318
318
319 def checkout(ui, repo, *args, **kwargs):
319 def checkout(ui, repo, *args, **kwargs):
320 cmdoptions = [
320 cmdoptions = [
321 (b'b', b'branch', b'', b''),
321 (b'b', b'branch', b'', b''),
322 (b'B', b'branch', b'', b''),
322 (b'B', b'branch', b'', b''),
323 (b'f', b'force', None, b''),
323 (b'f', b'force', None, b''),
324 (b'p', b'patch', None, b''),
324 (b'p', b'patch', None, b''),
325 ]
325 ]
326 paths = []
326 paths = []
327 if b'--' in args:
327 if b'--' in args:
328 sepindex = args.index(b'--')
328 sepindex = args.index(b'--')
329 paths.extend(args[sepindex + 1 :])
329 paths.extend(args[sepindex + 1 :])
330 args = args[:sepindex]
330 args = args[:sepindex]
331
331
332 args, opts = parseoptions(ui, cmdoptions, args)
332 args, opts = parseoptions(ui, cmdoptions, args)
333
333
334 rev = None
334 rev = None
335 if args and ispath(repo, args[0]):
335 if args and ispath(repo, args[0]):
336 paths = args + paths
336 paths = args + paths
337 elif args:
337 elif args:
338 rev = args[0]
338 rev = args[0]
339 paths = args[1:] + paths
339 paths = args[1:] + paths
340
340
341 cmd = Command(b'update')
341 cmd = Command(b'update')
342
342
343 if opts.get(b'force'):
343 if opts.get(b'force'):
344 if paths or rev:
344 if paths or rev:
345 cmd[b'-C'] = None
345 cmd[b'-C'] = None
346
346
347 if opts.get(b'patch'):
347 if opts.get(b'patch'):
348 cmd = Command(b'revert')
348 cmd = Command(b'revert')
349 cmd[b'-i'] = None
349 cmd[b'-i'] = None
350
350
351 if opts.get(b'branch'):
351 if opts.get(b'branch'):
352 if len(args) == 0:
352 if len(args) == 0:
353 cmd = Command(b'bookmark')
353 cmd = Command(b'bookmark')
354 cmd.append(opts.get(b'branch'))
354 cmd.append(opts.get(b'branch'))
355 else:
355 else:
356 cmd.append(args[0])
356 cmd.append(args[0])
357 bookcmd = Command(b'bookmark')
357 bookcmd = Command(b'bookmark')
358 bookcmd.append(opts.get(b'branch'))
358 bookcmd.append(opts.get(b'branch'))
359 cmd = cmd & bookcmd
359 cmd = cmd & bookcmd
360 # if there is any path argument supplied, use revert instead of update
360 # if there is any path argument supplied, use revert instead of update
361 elif len(paths) > 0:
361 elif len(paths) > 0:
362 ui.status(_(b"note: use --no-backup to avoid creating .orig files\n\n"))
362 ui.status(_(b"note: use --no-backup to avoid creating .orig files\n\n"))
363 cmd = Command(b'revert')
363 cmd = Command(b'revert')
364 if opts.get(b'patch'):
364 if opts.get(b'patch'):
365 cmd[b'-i'] = None
365 cmd[b'-i'] = None
366 if rev:
366 if rev:
367 cmd[b'-r'] = rev
367 cmd[b'-r'] = rev
368 cmd.extend(paths)
368 cmd.extend(paths)
369 elif rev:
369 elif rev:
370 if opts.get(b'patch'):
370 if opts.get(b'patch'):
371 cmd[b'-r'] = rev
371 cmd[b'-r'] = rev
372 else:
372 else:
373 cmd.append(rev)
373 cmd.append(rev)
374 elif opts.get(b'force'):
374 elif opts.get(b'force'):
375 cmd = Command(b'revert')
375 cmd = Command(b'revert')
376 cmd[b'--all'] = None
376 cmd[b'--all'] = None
377 else:
377 else:
378 raise error.Abort(_(b"a commit must be specified"))
378 raise error.Abort(_(b"a commit must be specified"))
379
379
380 ui.status((bytes(cmd)), b"\n")
380 ui.status((bytes(cmd)), b"\n")
381
381
382
382
383 def cherrypick(ui, repo, *args, **kwargs):
383 def cherrypick(ui, repo, *args, **kwargs):
384 cmdoptions = [
384 cmdoptions = [
385 (b'', b'continue', None, b''),
385 (b'', b'continue', None, b''),
386 (b'', b'abort', None, b''),
386 (b'', b'abort', None, b''),
387 (b'e', b'edit', None, b''),
387 (b'e', b'edit', None, b''),
388 ]
388 ]
389 args, opts = parseoptions(ui, cmdoptions, args)
389 args, opts = parseoptions(ui, cmdoptions, args)
390
390
391 cmd = Command(b'graft')
391 cmd = Command(b'graft')
392
392
393 if opts.get(b'edit'):
393 if opts.get(b'edit'):
394 cmd[b'--edit'] = None
394 cmd[b'--edit'] = None
395 if opts.get(b'continue'):
395 if opts.get(b'continue'):
396 cmd[b'--continue'] = None
396 cmd[b'--continue'] = None
397 elif opts.get(b'abort'):
397 elif opts.get(b'abort'):
398 ui.status(_(b"note: hg graft does not have --abort\n\n"))
398 ui.status(_(b"note: hg graft does not have --abort\n\n"))
399 return
399 return
400 else:
400 else:
401 cmd.extend(args)
401 cmd.extend(args)
402
402
403 ui.status((bytes(cmd)), b"\n")
403 ui.status((bytes(cmd)), b"\n")
404
404
405
405
406 def clean(ui, repo, *args, **kwargs):
406 def clean(ui, repo, *args, **kwargs):
407 cmdoptions = [
407 cmdoptions = [
408 (b'd', b'd', None, b''),
408 (b'd', b'd', None, b''),
409 (b'f', b'force', None, b''),
409 (b'f', b'force', None, b''),
410 (b'x', b'x', None, b''),
410 (b'x', b'x', None, b''),
411 ]
411 ]
412 args, opts = parseoptions(ui, cmdoptions, args)
412 args, opts = parseoptions(ui, cmdoptions, args)
413
413
414 cmd = Command(b'purge')
414 cmd = Command(b'purge')
415 if opts.get(b'x'):
415 if opts.get(b'x'):
416 cmd[b'--all'] = None
416 cmd[b'--all'] = None
417 cmd.extend(args)
417 cmd.extend(args)
418
418
419 ui.status((bytes(cmd)), b"\n")
419 ui.status((bytes(cmd)), b"\n")
420
420
421
421
422 def clone(ui, repo, *args, **kwargs):
422 def clone(ui, repo, *args, **kwargs):
423 cmdoptions = [
423 cmdoptions = [
424 (b'', b'bare', None, b''),
424 (b'', b'bare', None, b''),
425 (b'n', b'no-checkout', None, b''),
425 (b'n', b'no-checkout', None, b''),
426 (b'b', b'branch', b'', b''),
426 (b'b', b'branch', b'', b''),
427 ]
427 ]
428 args, opts = parseoptions(ui, cmdoptions, args)
428 args, opts = parseoptions(ui, cmdoptions, args)
429
429
430 if len(args) == 0:
430 if len(args) == 0:
431 raise error.Abort(_(b"a repository to clone must be specified"))
431 raise error.Abort(_(b"a repository to clone must be specified"))
432
432
433 cmd = Command(b'clone')
433 cmd = Command(b'clone')
434 cmd.append(args[0])
434 cmd.append(args[0])
435 if len(args) > 1:
435 if len(args) > 1:
436 cmd.append(args[1])
436 cmd.append(args[1])
437
437
438 if opts.get(b'bare'):
438 if opts.get(b'bare'):
439 cmd[b'-U'] = None
439 cmd[b'-U'] = None
440 ui.status(
440 ui.status(
441 _(
441 _(
442 b"note: Mercurial does not have bare clones. "
442 b"note: Mercurial does not have bare clones. "
443 b"-U will clone the repo without checking out a commit\n\n"
443 b"-U will clone the repo without checking out a commit\n\n"
444 )
444 )
445 )
445 )
446 elif opts.get(b'no_checkout'):
446 elif opts.get(b'no_checkout'):
447 cmd[b'-U'] = None
447 cmd[b'-U'] = None
448
448
449 if opts.get(b'branch'):
449 if opts.get(b'branch'):
450 cocmd = Command(b"update")
450 cocmd = Command(b"update")
451 cocmd.append(opts.get(b'branch'))
451 cocmd.append(opts.get(b'branch'))
452 cmd = cmd & cocmd
452 cmd = cmd & cocmd
453
453
454 ui.status((bytes(cmd)), b"\n")
454 ui.status((bytes(cmd)), b"\n")
455
455
456
456
457 def commit(ui, repo, *args, **kwargs):
457 def commit(ui, repo, *args, **kwargs):
458 cmdoptions = [
458 cmdoptions = [
459 (b'a', b'all', None, b''),
459 (b'a', b'all', None, b''),
460 (b'm', b'message', b'', b''),
460 (b'm', b'message', b'', b''),
461 (b'p', b'patch', None, b''),
461 (b'p', b'patch', None, b''),
462 (b'C', b'reuse-message', b'', b''),
462 (b'C', b'reuse-message', b'', b''),
463 (b'F', b'file', b'', b''),
463 (b'F', b'file', b'', b''),
464 (b'', b'author', b'', b''),
464 (b'', b'author', b'', b''),
465 (b'', b'date', b'', b''),
465 (b'', b'date', b'', b''),
466 (b'', b'amend', None, b''),
466 (b'', b'amend', None, b''),
467 (b'', b'no-edit', None, b''),
467 (b'', b'no-edit', None, b''),
468 ]
468 ]
469 args, opts = parseoptions(ui, cmdoptions, args)
469 args, opts = parseoptions(ui, cmdoptions, args)
470
470
471 cmd = Command(b'commit')
471 cmd = Command(b'commit')
472 if opts.get(b'patch'):
472 if opts.get(b'patch'):
473 cmd = Command(b'commit --interactive')
473 cmd = Command(b'commit --interactive')
474
474
475 if opts.get(b'amend'):
475 if opts.get(b'amend'):
476 if opts.get(b'no_edit'):
476 if opts.get(b'no_edit'):
477 cmd = Command(b'amend')
477 cmd = Command(b'amend')
478 else:
478 else:
479 cmd[b'--amend'] = None
479 cmd[b'--amend'] = None
480
480
481 if opts.get(b'reuse_message'):
481 if opts.get(b'reuse_message'):
482 cmd[b'-M'] = opts.get(b'reuse_message')
482 cmd[b'-M'] = opts.get(b'reuse_message')
483
483
484 if opts.get(b'message'):
484 if opts.get(b'message'):
485 cmd[b'-m'] = b"'%s'" % (opts.get(b'message'),)
485 cmd[b'-m'] = b"'%s'" % (opts.get(b'message'),)
486
486
487 if opts.get(b'all'):
487 if opts.get(b'all'):
488 ui.status(
488 ui.status(
489 _(
489 _(
490 b"note: Mercurial doesn't have a staging area, "
490 b"note: Mercurial doesn't have a staging area, "
491 b"so there is no --all. -A will add and remove files "
491 b"so there is no --all. -A will add and remove files "
492 b"for you though.\n\n"
492 b"for you though.\n\n"
493 )
493 )
494 )
494 )
495
495
496 if opts.get(b'file'):
496 if opts.get(b'file'):
497 cmd[b'-l'] = opts.get(b'file')
497 cmd[b'-l'] = opts.get(b'file')
498
498
499 if opts.get(b'author'):
499 if opts.get(b'author'):
500 cmd[b'-u'] = opts.get(b'author')
500 cmd[b'-u'] = opts.get(b'author')
501
501
502 if opts.get(b'date'):
502 if opts.get(b'date'):
503 cmd[b'-d'] = opts.get(b'date')
503 cmd[b'-d'] = opts.get(b'date')
504
504
505 cmd.extend(args)
505 cmd.extend(args)
506
506
507 ui.status((bytes(cmd)), b"\n")
507 ui.status((bytes(cmd)), b"\n")
508
508
509
509
510 def deprecated(ui, repo, *args, **kwargs):
510 def deprecated(ui, repo, *args, **kwargs):
511 ui.warn(
511 ui.warn(
512 _(
512 _(
513 b'this command has been deprecated in the git project, '
513 b'this command has been deprecated in the git project, '
514 b'thus isn\'t supported by this tool\n\n'
514 b'thus isn\'t supported by this tool\n\n'
515 )
515 )
516 )
516 )
517
517
518
518
519 def diff(ui, repo, *args, **kwargs):
519 def diff(ui, repo, *args, **kwargs):
520 cmdoptions = [
520 cmdoptions = [
521 (b'a', b'all', None, b''),
521 (b'a', b'all', None, b''),
522 (b'', b'cached', None, b''),
522 (b'', b'cached', None, b''),
523 (b'R', b'reverse', None, b''),
523 (b'R', b'reverse', None, b''),
524 ]
524 ]
525 args, opts = parseoptions(ui, cmdoptions, args)
525 args, opts = parseoptions(ui, cmdoptions, args)
526
526
527 cmd = Command(b'diff')
527 cmd = Command(b'diff')
528
528
529 if opts.get(b'cached'):
529 if opts.get(b'cached'):
530 ui.status(
530 ui.status(
531 _(
531 _(
532 b'note: Mercurial has no concept of a staging area, '
532 b'note: Mercurial has no concept of a staging area, '
533 b'so --cached does nothing\n\n'
533 b'so --cached does nothing\n\n'
534 )
534 )
535 )
535 )
536
536
537 if opts.get(b'reverse'):
537 if opts.get(b'reverse'):
538 cmd[b'--reverse'] = None
538 cmd[b'--reverse'] = None
539
539
540 for a in list(args):
540 for a in list(args):
541 args.remove(a)
541 args.remove(a)
542 try:
542 try:
543 repo.revs(a)
543 repo.revs(a)
544 cmd[b'-r'] = a
544 cmd[b'-r'] = a
545 except Exception:
545 except Exception:
546 cmd.append(a)
546 cmd.append(a)
547
547
548 ui.status((bytes(cmd)), b"\n")
548 ui.status((bytes(cmd)), b"\n")
549
549
550
550
551 def difftool(ui, repo, *args, **kwargs):
551 def difftool(ui, repo, *args, **kwargs):
552 ui.status(
552 ui.status(
553 _(
553 _(
554 b'Mercurial does not enable external difftool by default. You '
554 b'Mercurial does not enable external difftool by default. You '
555 b'need to enable the extdiff extension in your .hgrc file by adding\n'
555 b'need to enable the extdiff extension in your .hgrc file by adding\n'
556 b'extdiff =\n'
556 b'extdiff =\n'
557 b'to the [extensions] section and then running\n\n'
557 b'to the [extensions] section and then running\n\n'
558 b'hg extdiff -p <program>\n\n'
558 b'hg extdiff -p <program>\n\n'
559 b'See \'hg help extdiff\' and \'hg help -e extdiff\' for more '
559 b'See \'hg help extdiff\' and \'hg help -e extdiff\' for more '
560 b'information.\n'
560 b'information.\n'
561 )
561 )
562 )
562 )
563
563
564
564
565 def fetch(ui, repo, *args, **kwargs):
565 def fetch(ui, repo, *args, **kwargs):
566 cmdoptions = [
566 cmdoptions = [
567 (b'', b'all', None, b''),
567 (b'', b'all', None, b''),
568 (b'f', b'force', None, b''),
568 (b'f', b'force', None, b''),
569 ]
569 ]
570 args, opts = parseoptions(ui, cmdoptions, args)
570 args, opts = parseoptions(ui, cmdoptions, args)
571
571
572 cmd = Command(b'pull')
572 cmd = Command(b'pull')
573
573
574 if len(args) > 0:
574 if len(args) > 0:
575 cmd.append(args[0])
575 cmd.append(args[0])
576 if len(args) > 1:
576 if len(args) > 1:
577 ui.status(
577 ui.status(
578 _(
578 _(
579 b"note: Mercurial doesn't have refspecs. "
579 b"note: Mercurial doesn't have refspecs. "
580 b"-r can be used to specify which commits you want to "
580 b"-r can be used to specify which commits you want to "
581 b"pull. -B can be used to specify which bookmark you "
581 b"pull. -B can be used to specify which bookmark you "
582 b"want to pull.\n\n"
582 b"want to pull.\n\n"
583 )
583 )
584 )
584 )
585 for v in args[1:]:
585 for v in args[1:]:
586 if v in repo._bookmarks:
586 if v in repo._bookmarks:
587 cmd[b'-B'] = v
587 cmd[b'-B'] = v
588 else:
588 else:
589 cmd[b'-r'] = v
589 cmd[b'-r'] = v
590
590
591 ui.status((bytes(cmd)), b"\n")
591 ui.status((bytes(cmd)), b"\n")
592
592
593
593
594 def grep(ui, repo, *args, **kwargs):
594 def grep(ui, repo, *args, **kwargs):
595 cmdoptions = []
595 cmdoptions = []
596 args, opts = parseoptions(ui, cmdoptions, args)
596 args, opts = parseoptions(ui, cmdoptions, args)
597
597
598 cmd = Command(b'grep')
598 cmd = Command(b'grep')
599
599
600 # For basic usage, git grep and hg grep are the same. They both have the
600 # For basic usage, git grep and hg grep are the same. They both have the
601 # pattern first, followed by paths.
601 # pattern first, followed by paths.
602 cmd.extend(args)
602 cmd.extend(args)
603
603
604 ui.status((bytes(cmd)), b"\n")
604 ui.status((bytes(cmd)), b"\n")
605
605
606
606
607 def init(ui, repo, *args, **kwargs):
607 def init(ui, repo, *args, **kwargs):
608 cmdoptions = []
608 cmdoptions = []
609 args, opts = parseoptions(ui, cmdoptions, args)
609 args, opts = parseoptions(ui, cmdoptions, args)
610
610
611 cmd = Command(b'init')
611 cmd = Command(b'init')
612
612
613 if len(args) > 0:
613 if len(args) > 0:
614 cmd.append(args[0])
614 cmd.append(args[0])
615
615
616 ui.status((bytes(cmd)), b"\n")
616 ui.status((bytes(cmd)), b"\n")
617
617
618
618
619 def log(ui, repo, *args, **kwargs):
619 def log(ui, repo, *args, **kwargs):
620 cmdoptions = [
620 cmdoptions = [
621 (b'', b'follow', None, b''),
621 (b'', b'follow', None, b''),
622 (b'', b'decorate', None, b''),
622 (b'', b'decorate', None, b''),
623 (b'n', b'number', b'', b''),
623 (b'n', b'number', b'', b''),
624 (b'1', b'1', None, b''),
624 (b'1', b'1', None, b''),
625 (b'', b'pretty', b'', b''),
625 (b'', b'pretty', b'', b''),
626 (b'', b'format', b'', b''),
626 (b'', b'format', b'', b''),
627 (b'', b'oneline', None, b''),
627 (b'', b'oneline', None, b''),
628 (b'', b'stat', None, b''),
628 (b'', b'stat', None, b''),
629 (b'', b'graph', None, b''),
629 (b'', b'graph', None, b''),
630 (b'p', b'patch', None, b''),
630 (b'p', b'patch', None, b''),
631 (b'G', b'grep-diff', b'', b''),
632 (b'S', b'pickaxe-regex', b'', b''),
631 ]
633 ]
632 args, opts = parseoptions(ui, cmdoptions, args)
634 args, opts = parseoptions(ui, cmdoptions, args)
635 grep_pat = opts.get(b'grep_diff') or opts.get(b'pickaxe_regex')
636 if grep_pat:
637 cmd = Command(b'grep')
638 cmd[b'--diff'] = grep_pat
639 ui.status(b'%s\n' % bytes(cmd))
640 return
641
633 ui.status(
642 ui.status(
634 _(
643 _(
635 b'note: -v prints the entire commit message like Git does. To '
644 b'note: -v prints the entire commit message like Git does. To '
636 b'print just the first line, drop the -v.\n\n'
645 b'print just the first line, drop the -v.\n\n'
637 )
646 )
638 )
647 )
639 ui.status(
648 ui.status(
640 _(
649 _(
641 b"note: see hg help revset for information on how to filter "
650 b"note: see hg help revset for information on how to filter "
642 b"log output\n\n"
651 b"log output\n\n"
643 )
652 )
644 )
653 )
645
654
646 cmd = Command(b'log')
655 cmd = Command(b'log')
647 cmd[b'-v'] = None
656 cmd[b'-v'] = None
648
657
649 if opts.get(b'number'):
658 if opts.get(b'number'):
650 cmd[b'-l'] = opts.get(b'number')
659 cmd[b'-l'] = opts.get(b'number')
651 if opts.get(b'1'):
660 if opts.get(b'1'):
652 cmd[b'-l'] = b'1'
661 cmd[b'-l'] = b'1'
653 if opts.get(b'stat'):
662 if opts.get(b'stat'):
654 cmd[b'--stat'] = None
663 cmd[b'--stat'] = None
655 if opts.get(b'graph'):
664 if opts.get(b'graph'):
656 cmd[b'-G'] = None
665 cmd[b'-G'] = None
657 if opts.get(b'patch'):
666 if opts.get(b'patch'):
658 cmd[b'-p'] = None
667 cmd[b'-p'] = None
659
668
660 if opts.get(b'pretty') or opts.get(b'format') or opts.get(b'oneline'):
669 if opts.get(b'pretty') or opts.get(b'format') or opts.get(b'oneline'):
661 format = opts.get(b'format', b'')
670 format = opts.get(b'format', b'')
662 if b'format:' in format:
671 if b'format:' in format:
663 ui.status(
672 ui.status(
664 _(
673 _(
665 b"note: --format format:??? equates to Mercurial's "
674 b"note: --format format:??? equates to Mercurial's "
666 b"--template. See hg help templates for more info.\n\n"
675 b"--template. See hg help templates for more info.\n\n"
667 )
676 )
668 )
677 )
669 cmd[b'--template'] = b'???'
678 cmd[b'--template'] = b'???'
670 else:
679 else:
671 ui.status(
680 ui.status(
672 _(
681 _(
673 b"note: --pretty/format/oneline equate to Mercurial's "
682 b"note: --pretty/format/oneline equate to Mercurial's "
674 b"--style or --template. See hg help templates for "
683 b"--style or --template. See hg help templates for "
675 b"more info.\n\n"
684 b"more info.\n\n"
676 )
685 )
677 )
686 )
678 cmd[b'--style'] = b'???'
687 cmd[b'--style'] = b'???'
679
688
680 if len(args) > 0:
689 if len(args) > 0:
681 if b'..' in args[0]:
690 if b'..' in args[0]:
682 since, until = args[0].split(b'..')
691 since, until = args[0].split(b'..')
683 cmd[b'-r'] = b"'%s::%s'" % (since, until)
692 cmd[b'-r'] = b"'%s::%s'" % (since, until)
684 del args[0]
693 del args[0]
685 cmd.extend(args)
694 cmd.extend(args)
686
695
687 ui.status((bytes(cmd)), b"\n")
696 ui.status((bytes(cmd)), b"\n")
688
697
689
698
690 def lsfiles(ui, repo, *args, **kwargs):
699 def lsfiles(ui, repo, *args, **kwargs):
691 cmdoptions = [
700 cmdoptions = [
692 (b'c', b'cached', None, b''),
701 (b'c', b'cached', None, b''),
693 (b'd', b'deleted', None, b''),
702 (b'd', b'deleted', None, b''),
694 (b'm', b'modified', None, b''),
703 (b'm', b'modified', None, b''),
695 (b'o', b'others', None, b''),
704 (b'o', b'others', None, b''),
696 (b'i', b'ignored', None, b''),
705 (b'i', b'ignored', None, b''),
697 (b's', b'stage', None, b''),
706 (b's', b'stage', None, b''),
698 (b'z', b'_zero', None, b''),
707 (b'z', b'_zero', None, b''),
699 ]
708 ]
700 args, opts = parseoptions(ui, cmdoptions, args)
709 args, opts = parseoptions(ui, cmdoptions, args)
701
710
702 if (
711 if (
703 opts.get(b'modified')
712 opts.get(b'modified')
704 or opts.get(b'deleted')
713 or opts.get(b'deleted')
705 or opts.get(b'others')
714 or opts.get(b'others')
706 or opts.get(b'ignored')
715 or opts.get(b'ignored')
707 ):
716 ):
708 cmd = Command(b'status')
717 cmd = Command(b'status')
709 if opts.get(b'deleted'):
718 if opts.get(b'deleted'):
710 cmd[b'-d'] = None
719 cmd[b'-d'] = None
711 if opts.get(b'modified'):
720 if opts.get(b'modified'):
712 cmd[b'-m'] = None
721 cmd[b'-m'] = None
713 if opts.get(b'others'):
722 if opts.get(b'others'):
714 cmd[b'-o'] = None
723 cmd[b'-o'] = None
715 if opts.get(b'ignored'):
724 if opts.get(b'ignored'):
716 cmd[b'-i'] = None
725 cmd[b'-i'] = None
717 else:
726 else:
718 cmd = Command(b'files')
727 cmd = Command(b'files')
719 if opts.get(b'stage'):
728 if opts.get(b'stage'):
720 ui.status(
729 ui.status(
721 _(
730 _(
722 b"note: Mercurial doesn't have a staging area, ignoring "
731 b"note: Mercurial doesn't have a staging area, ignoring "
723 b"--stage\n"
732 b"--stage\n"
724 )
733 )
725 )
734 )
726 if opts.get(b'_zero'):
735 if opts.get(b'_zero'):
727 cmd[b'-0'] = None
736 cmd[b'-0'] = None
728 cmd.append(b'.')
737 cmd.append(b'.')
729 for include in args:
738 for include in args:
730 cmd[b'-I'] = procutil.shellquote(include)
739 cmd[b'-I'] = procutil.shellquote(include)
731
740
732 ui.status((bytes(cmd)), b"\n")
741 ui.status((bytes(cmd)), b"\n")
733
742
734
743
735 def merge(ui, repo, *args, **kwargs):
744 def merge(ui, repo, *args, **kwargs):
736 cmdoptions = []
745 cmdoptions = []
737 args, opts = parseoptions(ui, cmdoptions, args)
746 args, opts = parseoptions(ui, cmdoptions, args)
738
747
739 cmd = Command(b'merge')
748 cmd = Command(b'merge')
740
749
741 if len(args) > 0:
750 if len(args) > 0:
742 cmd.append(args[len(args) - 1])
751 cmd.append(args[len(args) - 1])
743
752
744 ui.status((bytes(cmd)), b"\n")
753 ui.status((bytes(cmd)), b"\n")
745
754
746
755
747 def mergebase(ui, repo, *args, **kwargs):
756 def mergebase(ui, repo, *args, **kwargs):
748 cmdoptions = []
757 cmdoptions = []
749 args, opts = parseoptions(ui, cmdoptions, args)
758 args, opts = parseoptions(ui, cmdoptions, args)
750
759
751 if len(args) != 2:
760 if len(args) != 2:
752 args = [b'A', b'B']
761 args = [b'A', b'B']
753
762
754 cmd = Command(
763 cmd = Command(
755 b"log -T '{node}\\n' -r 'ancestor(%s,%s)'" % (args[0], args[1])
764 b"log -T '{node}\\n' -r 'ancestor(%s,%s)'" % (args[0], args[1])
756 )
765 )
757
766
758 ui.status(
767 ui.status(
759 _(b'note: ancestors() is part of the revset language\n'),
768 _(b'note: ancestors() is part of the revset language\n'),
760 _(b"(learn more about revsets with 'hg help revsets')\n\n"),
769 _(b"(learn more about revsets with 'hg help revsets')\n\n"),
761 )
770 )
762 ui.status((bytes(cmd)), b"\n")
771 ui.status((bytes(cmd)), b"\n")
763
772
764
773
765 def mergetool(ui, repo, *args, **kwargs):
774 def mergetool(ui, repo, *args, **kwargs):
766 cmdoptions = []
775 cmdoptions = []
767 args, opts = parseoptions(ui, cmdoptions, args)
776 args, opts = parseoptions(ui, cmdoptions, args)
768
777
769 cmd = Command(b"resolve")
778 cmd = Command(b"resolve")
770
779
771 if len(args) == 0:
780 if len(args) == 0:
772 cmd[b'--all'] = None
781 cmd[b'--all'] = None
773 cmd.extend(args)
782 cmd.extend(args)
774 ui.status((bytes(cmd)), b"\n")
783 ui.status((bytes(cmd)), b"\n")
775
784
776
785
777 def mv(ui, repo, *args, **kwargs):
786 def mv(ui, repo, *args, **kwargs):
778 cmdoptions = [
787 cmdoptions = [
779 (b'f', b'force', None, b''),
788 (b'f', b'force', None, b''),
780 (b'n', b'dry-run', None, b''),
789 (b'n', b'dry-run', None, b''),
781 ]
790 ]
782 args, opts = parseoptions(ui, cmdoptions, args)
791 args, opts = parseoptions(ui, cmdoptions, args)
783
792
784 cmd = Command(b'mv')
793 cmd = Command(b'mv')
785 cmd.extend(args)
794 cmd.extend(args)
786
795
787 if opts.get(b'force'):
796 if opts.get(b'force'):
788 cmd[b'-f'] = None
797 cmd[b'-f'] = None
789 if opts.get(b'dry_run'):
798 if opts.get(b'dry_run'):
790 cmd[b'-n'] = None
799 cmd[b'-n'] = None
791
800
792 ui.status((bytes(cmd)), b"\n")
801 ui.status((bytes(cmd)), b"\n")
793
802
794
803
795 def pull(ui, repo, *args, **kwargs):
804 def pull(ui, repo, *args, **kwargs):
796 cmdoptions = [
805 cmdoptions = [
797 (b'', b'all', None, b''),
806 (b'', b'all', None, b''),
798 (b'f', b'force', None, b''),
807 (b'f', b'force', None, b''),
799 (b'r', b'rebase', None, b''),
808 (b'r', b'rebase', None, b''),
800 ]
809 ]
801 args, opts = parseoptions(ui, cmdoptions, args)
810 args, opts = parseoptions(ui, cmdoptions, args)
802
811
803 cmd = Command(b'pull')
812 cmd = Command(b'pull')
804 cmd[b'--rebase'] = None
813 cmd[b'--rebase'] = None
805
814
806 if len(args) > 0:
815 if len(args) > 0:
807 cmd.append(args[0])
816 cmd.append(args[0])
808 if len(args) > 1:
817 if len(args) > 1:
809 ui.status(
818 ui.status(
810 _(
819 _(
811 b"note: Mercurial doesn't have refspecs. "
820 b"note: Mercurial doesn't have refspecs. "
812 b"-r can be used to specify which commits you want to "
821 b"-r can be used to specify which commits you want to "
813 b"pull. -B can be used to specify which bookmark you "
822 b"pull. -B can be used to specify which bookmark you "
814 b"want to pull.\n\n"
823 b"want to pull.\n\n"
815 )
824 )
816 )
825 )
817 for v in args[1:]:
826 for v in args[1:]:
818 if v in repo._bookmarks:
827 if v in repo._bookmarks:
819 cmd[b'-B'] = v
828 cmd[b'-B'] = v
820 else:
829 else:
821 cmd[b'-r'] = v
830 cmd[b'-r'] = v
822
831
823 ui.status((bytes(cmd)), b"\n")
832 ui.status((bytes(cmd)), b"\n")
824
833
825
834
826 def push(ui, repo, *args, **kwargs):
835 def push(ui, repo, *args, **kwargs):
827 cmdoptions = [
836 cmdoptions = [
828 (b'', b'all', None, b''),
837 (b'', b'all', None, b''),
829 (b'f', b'force', None, b''),
838 (b'f', b'force', None, b''),
830 ]
839 ]
831 args, opts = parseoptions(ui, cmdoptions, args)
840 args, opts = parseoptions(ui, cmdoptions, args)
832
841
833 cmd = Command(b'push')
842 cmd = Command(b'push')
834
843
835 if len(args) > 0:
844 if len(args) > 0:
836 cmd.append(args[0])
845 cmd.append(args[0])
837 if len(args) > 1:
846 if len(args) > 1:
838 ui.status(
847 ui.status(
839 _(
848 _(
840 b"note: Mercurial doesn't have refspecs. "
849 b"note: Mercurial doesn't have refspecs. "
841 b"-r can be used to specify which commits you want "
850 b"-r can be used to specify which commits you want "
842 b"to push. -B can be used to specify which bookmark "
851 b"to push. -B can be used to specify which bookmark "
843 b"you want to push.\n\n"
852 b"you want to push.\n\n"
844 )
853 )
845 )
854 )
846 for v in args[1:]:
855 for v in args[1:]:
847 if v in repo._bookmarks:
856 if v in repo._bookmarks:
848 cmd[b'-B'] = v
857 cmd[b'-B'] = v
849 else:
858 else:
850 cmd[b'-r'] = v
859 cmd[b'-r'] = v
851
860
852 if opts.get(b'force'):
861 if opts.get(b'force'):
853 cmd[b'-f'] = None
862 cmd[b'-f'] = None
854
863
855 ui.status((bytes(cmd)), b"\n")
864 ui.status((bytes(cmd)), b"\n")
856
865
857
866
858 def rebase(ui, repo, *args, **kwargs):
867 def rebase(ui, repo, *args, **kwargs):
859 cmdoptions = [
868 cmdoptions = [
860 (b'', b'all', None, b''),
869 (b'', b'all', None, b''),
861 (b'i', b'interactive', None, b''),
870 (b'i', b'interactive', None, b''),
862 (b'', b'onto', b'', b''),
871 (b'', b'onto', b'', b''),
863 (b'', b'abort', None, b''),
872 (b'', b'abort', None, b''),
864 (b'', b'continue', None, b''),
873 (b'', b'continue', None, b''),
865 (b'', b'skip', None, b''),
874 (b'', b'skip', None, b''),
866 ]
875 ]
867 args, opts = parseoptions(ui, cmdoptions, args)
876 args, opts = parseoptions(ui, cmdoptions, args)
868
877
869 if opts.get(b'interactive'):
878 if opts.get(b'interactive'):
870 ui.status(
879 ui.status(
871 _(
880 _(
872 b"note: hg histedit does not perform a rebase. "
881 b"note: hg histedit does not perform a rebase. "
873 b"It just edits history.\n\n"
882 b"It just edits history.\n\n"
874 )
883 )
875 )
884 )
876 cmd = Command(b'histedit')
885 cmd = Command(b'histedit')
877 if len(args) > 0:
886 if len(args) > 0:
878 ui.status(
887 ui.status(
879 _(
888 _(
880 b"also note: 'hg histedit' will automatically detect"
889 b"also note: 'hg histedit' will automatically detect"
881 b" your stack, so no second argument is necessary\n\n"
890 b" your stack, so no second argument is necessary\n\n"
882 )
891 )
883 )
892 )
884 ui.status((bytes(cmd)), b"\n")
893 ui.status((bytes(cmd)), b"\n")
885 return
894 return
886
895
887 if opts.get(b'skip'):
896 if opts.get(b'skip'):
888 cmd = Command(b'revert --all -r .')
897 cmd = Command(b'revert --all -r .')
889 ui.status((bytes(cmd)), b"\n")
898 ui.status((bytes(cmd)), b"\n")
890
899
891 cmd = Command(b'rebase')
900 cmd = Command(b'rebase')
892
901
893 if opts.get(b'continue') or opts.get(b'skip'):
902 if opts.get(b'continue') or opts.get(b'skip'):
894 cmd[b'--continue'] = None
903 cmd[b'--continue'] = None
895 if opts.get(b'abort'):
904 if opts.get(b'abort'):
896 cmd[b'--abort'] = None
905 cmd[b'--abort'] = None
897
906
898 if opts.get(b'onto'):
907 if opts.get(b'onto'):
899 ui.status(
908 ui.status(
900 _(
909 _(
901 b"note: if you're trying to lift a commit off one branch, "
910 b"note: if you're trying to lift a commit off one branch, "
902 b"try hg rebase -d <destination commit> -s <commit to be "
911 b"try hg rebase -d <destination commit> -s <commit to be "
903 b"lifted>\n\n"
912 b"lifted>\n\n"
904 )
913 )
905 )
914 )
906 cmd[b'-d'] = convert(opts.get(b'onto'))
915 cmd[b'-d'] = convert(opts.get(b'onto'))
907 if len(args) < 2:
916 if len(args) < 2:
908 raise error.Abort(_(b"expected format: git rebase --onto X Y Z"))
917 raise error.Abort(_(b"expected format: git rebase --onto X Y Z"))
909 cmd[b'-s'] = b"'::%s - ::%s'" % (convert(args[1]), convert(args[0]))
918 cmd[b'-s'] = b"'::%s - ::%s'" % (convert(args[1]), convert(args[0]))
910 else:
919 else:
911 if len(args) == 1:
920 if len(args) == 1:
912 cmd[b'-d'] = convert(args[0])
921 cmd[b'-d'] = convert(args[0])
913 elif len(args) == 2:
922 elif len(args) == 2:
914 cmd[b'-d'] = convert(args[0])
923 cmd[b'-d'] = convert(args[0])
915 cmd[b'-b'] = convert(args[1])
924 cmd[b'-b'] = convert(args[1])
916
925
917 ui.status((bytes(cmd)), b"\n")
926 ui.status((bytes(cmd)), b"\n")
918
927
919
928
920 def reflog(ui, repo, *args, **kwargs):
929 def reflog(ui, repo, *args, **kwargs):
921 cmdoptions = [
930 cmdoptions = [
922 (b'', b'all', None, b''),
931 (b'', b'all', None, b''),
923 ]
932 ]
924 args, opts = parseoptions(ui, cmdoptions, args)
933 args, opts = parseoptions(ui, cmdoptions, args)
925
934
926 cmd = Command(b'journal')
935 cmd = Command(b'journal')
927 if opts.get(b'all'):
936 if opts.get(b'all'):
928 cmd[b'--all'] = None
937 cmd[b'--all'] = None
929 if len(args) > 0:
938 if len(args) > 0:
930 cmd.append(args[0])
939 cmd.append(args[0])
931
940
932 ui.status(bytes(cmd), b"\n\n")
941 ui.status(bytes(cmd), b"\n\n")
933 ui.status(
942 ui.status(
934 _(
943 _(
935 b"note: in hg commits can be deleted from repo but we always"
944 b"note: in hg commits can be deleted from repo but we always"
936 b" have backups\n"
945 b" have backups\n"
937 )
946 )
938 )
947 )
939
948
940
949
941 def reset(ui, repo, *args, **kwargs):
950 def reset(ui, repo, *args, **kwargs):
942 cmdoptions = [
951 cmdoptions = [
943 (b'', b'soft', None, b''),
952 (b'', b'soft', None, b''),
944 (b'', b'hard', None, b''),
953 (b'', b'hard', None, b''),
945 (b'', b'mixed', None, b''),
954 (b'', b'mixed', None, b''),
946 ]
955 ]
947 args, opts = parseoptions(ui, cmdoptions, args)
956 args, opts = parseoptions(ui, cmdoptions, args)
948
957
949 commit = convert(args[0] if len(args) > 0 else b'.')
958 commit = convert(args[0] if len(args) > 0 else b'.')
950 hard = opts.get(b'hard')
959 hard = opts.get(b'hard')
951
960
952 if opts.get(b'mixed'):
961 if opts.get(b'mixed'):
953 ui.status(
962 ui.status(
954 _(
963 _(
955 b'note: --mixed has no meaning since Mercurial has no '
964 b'note: --mixed has no meaning since Mercurial has no '
956 b'staging area\n\n'
965 b'staging area\n\n'
957 )
966 )
958 )
967 )
959 if opts.get(b'soft'):
968 if opts.get(b'soft'):
960 ui.status(
969 ui.status(
961 _(
970 _(
962 b'note: --soft has no meaning since Mercurial has no '
971 b'note: --soft has no meaning since Mercurial has no '
963 b'staging area\n\n'
972 b'staging area\n\n'
964 )
973 )
965 )
974 )
966
975
967 cmd = Command(b'update')
976 cmd = Command(b'update')
968 if hard:
977 if hard:
969 cmd.append(b'--clean')
978 cmd.append(b'--clean')
970
979
971 cmd.append(commit)
980 cmd.append(commit)
972
981
973 ui.status((bytes(cmd)), b"\n")
982 ui.status((bytes(cmd)), b"\n")
974
983
975
984
976 def revert(ui, repo, *args, **kwargs):
985 def revert(ui, repo, *args, **kwargs):
977 cmdoptions = []
986 cmdoptions = []
978 args, opts = parseoptions(ui, cmdoptions, args)
987 args, opts = parseoptions(ui, cmdoptions, args)
979
988
980 if len(args) > 1:
989 if len(args) > 1:
981 ui.status(
990 ui.status(
982 _(
991 _(
983 b"note: hg backout doesn't support multiple commits at "
992 b"note: hg backout doesn't support multiple commits at "
984 b"once\n\n"
993 b"once\n\n"
985 )
994 )
986 )
995 )
987
996
988 cmd = Command(b'backout')
997 cmd = Command(b'backout')
989 if args:
998 if args:
990 cmd.append(args[0])
999 cmd.append(args[0])
991
1000
992 ui.status((bytes(cmd)), b"\n")
1001 ui.status((bytes(cmd)), b"\n")
993
1002
994
1003
995 def revparse(ui, repo, *args, **kwargs):
1004 def revparse(ui, repo, *args, **kwargs):
996 cmdoptions = [
1005 cmdoptions = [
997 (b'', b'show-cdup', None, b''),
1006 (b'', b'show-cdup', None, b''),
998 (b'', b'show-toplevel', None, b''),
1007 (b'', b'show-toplevel', None, b''),
999 ]
1008 ]
1000 args, opts = parseoptions(ui, cmdoptions, args)
1009 args, opts = parseoptions(ui, cmdoptions, args)
1001
1010
1002 if opts.get(b'show_cdup') or opts.get(b'show_toplevel'):
1011 if opts.get(b'show_cdup') or opts.get(b'show_toplevel'):
1003 cmd = Command(b'root')
1012 cmd = Command(b'root')
1004 if opts.get(b'show_cdup'):
1013 if opts.get(b'show_cdup'):
1005 ui.status(_(b"note: hg root prints the root of the repository\n\n"))
1014 ui.status(_(b"note: hg root prints the root of the repository\n\n"))
1006 ui.status((bytes(cmd)), b"\n")
1015 ui.status((bytes(cmd)), b"\n")
1007 else:
1016 else:
1008 ui.status(_(b"note: see hg help revset for how to refer to commits\n"))
1017 ui.status(_(b"note: see hg help revset for how to refer to commits\n"))
1009
1018
1010
1019
1011 def rm(ui, repo, *args, **kwargs):
1020 def rm(ui, repo, *args, **kwargs):
1012 cmdoptions = [
1021 cmdoptions = [
1013 (b'f', b'force', None, b''),
1022 (b'f', b'force', None, b''),
1014 (b'n', b'dry-run', None, b''),
1023 (b'n', b'dry-run', None, b''),
1015 ]
1024 ]
1016 args, opts = parseoptions(ui, cmdoptions, args)
1025 args, opts = parseoptions(ui, cmdoptions, args)
1017
1026
1018 cmd = Command(b'rm')
1027 cmd = Command(b'rm')
1019 cmd.extend(args)
1028 cmd.extend(args)
1020
1029
1021 if opts.get(b'force'):
1030 if opts.get(b'force'):
1022 cmd[b'-f'] = None
1031 cmd[b'-f'] = None
1023 if opts.get(b'dry_run'):
1032 if opts.get(b'dry_run'):
1024 cmd[b'-n'] = None
1033 cmd[b'-n'] = None
1025
1034
1026 ui.status((bytes(cmd)), b"\n")
1035 ui.status((bytes(cmd)), b"\n")
1027
1036
1028
1037
1029 def show(ui, repo, *args, **kwargs):
1038 def show(ui, repo, *args, **kwargs):
1030 cmdoptions = [
1039 cmdoptions = [
1031 (b'', b'name-status', None, b''),
1040 (b'', b'name-status', None, b''),
1032 (b'', b'pretty', b'', b''),
1041 (b'', b'pretty', b'', b''),
1033 (b'U', b'unified', int, b''),
1042 (b'U', b'unified', int, b''),
1034 ]
1043 ]
1035 args, opts = parseoptions(ui, cmdoptions, args)
1044 args, opts = parseoptions(ui, cmdoptions, args)
1036
1045
1037 if opts.get(b'name_status'):
1046 if opts.get(b'name_status'):
1038 if opts.get(b'pretty') == b'format:':
1047 if opts.get(b'pretty') == b'format:':
1039 cmd = Command(b'status')
1048 cmd = Command(b'status')
1040 cmd[b'--change'] = b'.'
1049 cmd[b'--change'] = b'.'
1041 else:
1050 else:
1042 cmd = Command(b'log')
1051 cmd = Command(b'log')
1043 cmd.append(b'--style status')
1052 cmd.append(b'--style status')
1044 cmd.append(b'-r .')
1053 cmd.append(b'-r .')
1045 elif len(args) > 0:
1054 elif len(args) > 0:
1046 if ispath(repo, args[0]):
1055 if ispath(repo, args[0]):
1047 cmd = Command(b'cat')
1056 cmd = Command(b'cat')
1048 else:
1057 else:
1049 cmd = Command(b'export')
1058 cmd = Command(b'export')
1050 cmd.extend(args)
1059 cmd.extend(args)
1051 if opts.get(b'unified'):
1060 if opts.get(b'unified'):
1052 cmd.append(b'--config diff.unified=%d' % (opts[b'unified'],))
1061 cmd.append(b'--config diff.unified=%d' % (opts[b'unified'],))
1053 elif opts.get(b'unified'):
1062 elif opts.get(b'unified'):
1054 cmd = Command(b'export')
1063 cmd = Command(b'export')
1055 cmd.append(b'--config diff.unified=%d' % (opts[b'unified'],))
1064 cmd.append(b'--config diff.unified=%d' % (opts[b'unified'],))
1056 else:
1065 else:
1057 cmd = Command(b'export')
1066 cmd = Command(b'export')
1058
1067
1059 ui.status((bytes(cmd)), b"\n")
1068 ui.status((bytes(cmd)), b"\n")
1060
1069
1061
1070
1062 def stash(ui, repo, *args, **kwargs):
1071 def stash(ui, repo, *args, **kwargs):
1063 cmdoptions = [
1072 cmdoptions = [
1064 (b'p', b'patch', None, b''),
1073 (b'p', b'patch', None, b''),
1065 ]
1074 ]
1066 args, opts = parseoptions(ui, cmdoptions, args)
1075 args, opts = parseoptions(ui, cmdoptions, args)
1067
1076
1068 cmd = Command(b'shelve')
1077 cmd = Command(b'shelve')
1069 action = args[0] if len(args) > 0 else None
1078 action = args[0] if len(args) > 0 else None
1070
1079
1071 if action == b'list':
1080 if action == b'list':
1072 cmd[b'-l'] = None
1081 cmd[b'-l'] = None
1073 if opts.get(b'patch'):
1082 if opts.get(b'patch'):
1074 cmd[b'-p'] = None
1083 cmd[b'-p'] = None
1075 elif action == b'show':
1084 elif action == b'show':
1076 if opts.get(b'patch'):
1085 if opts.get(b'patch'):
1077 cmd[b'-p'] = None
1086 cmd[b'-p'] = None
1078 else:
1087 else:
1079 cmd[b'--stat'] = None
1088 cmd[b'--stat'] = None
1080 if len(args) > 1:
1089 if len(args) > 1:
1081 cmd.append(args[1])
1090 cmd.append(args[1])
1082 elif action == b'clear':
1091 elif action == b'clear':
1083 cmd[b'--cleanup'] = None
1092 cmd[b'--cleanup'] = None
1084 elif action == b'drop':
1093 elif action == b'drop':
1085 cmd[b'-d'] = None
1094 cmd[b'-d'] = None
1086 if len(args) > 1:
1095 if len(args) > 1:
1087 cmd.append(args[1])
1096 cmd.append(args[1])
1088 else:
1097 else:
1089 cmd.append(b'<shelve name>')
1098 cmd.append(b'<shelve name>')
1090 elif action == b'pop' or action == b'apply':
1099 elif action == b'pop' or action == b'apply':
1091 cmd = Command(b'unshelve')
1100 cmd = Command(b'unshelve')
1092 if len(args) > 1:
1101 if len(args) > 1:
1093 cmd.append(args[1])
1102 cmd.append(args[1])
1094 if action == b'apply':
1103 if action == b'apply':
1095 cmd[b'--keep'] = None
1104 cmd[b'--keep'] = None
1096 elif action == b'branch' or action == b'create':
1105 elif action == b'branch' or action == b'create':
1097 ui.status(
1106 ui.status(
1098 _(
1107 _(
1099 b"note: Mercurial doesn't have equivalents to the "
1108 b"note: Mercurial doesn't have equivalents to the "
1100 b"git stash branch or create actions\n\n"
1109 b"git stash branch or create actions\n\n"
1101 )
1110 )
1102 )
1111 )
1103 return
1112 return
1104 else:
1113 else:
1105 if len(args) > 0:
1114 if len(args) > 0:
1106 if args[0] != b'save':
1115 if args[0] != b'save':
1107 cmd[b'--name'] = args[0]
1116 cmd[b'--name'] = args[0]
1108 elif len(args) > 1:
1117 elif len(args) > 1:
1109 cmd[b'--name'] = args[1]
1118 cmd[b'--name'] = args[1]
1110
1119
1111 ui.status((bytes(cmd)), b"\n")
1120 ui.status((bytes(cmd)), b"\n")
1112
1121
1113
1122
1114 def status(ui, repo, *args, **kwargs):
1123 def status(ui, repo, *args, **kwargs):
1115 cmdoptions = [
1124 cmdoptions = [
1116 (b'', b'ignored', None, b''),
1125 (b'', b'ignored', None, b''),
1117 ]
1126 ]
1118 args, opts = parseoptions(ui, cmdoptions, args)
1127 args, opts = parseoptions(ui, cmdoptions, args)
1119
1128
1120 cmd = Command(b'status')
1129 cmd = Command(b'status')
1121 cmd.extend(args)
1130 cmd.extend(args)
1122
1131
1123 if opts.get(b'ignored'):
1132 if opts.get(b'ignored'):
1124 cmd[b'-i'] = None
1133 cmd[b'-i'] = None
1125
1134
1126 ui.status((bytes(cmd)), b"\n")
1135 ui.status((bytes(cmd)), b"\n")
1127
1136
1128
1137
1129 def svn(ui, repo, *args, **kwargs):
1138 def svn(ui, repo, *args, **kwargs):
1130 if not args:
1139 if not args:
1131 raise error.Abort(_(b'missing svn command'))
1140 raise error.Abort(_(b'missing svn command'))
1132 svncmd = args[0]
1141 svncmd = args[0]
1133 if svncmd not in gitsvncommands:
1142 if svncmd not in gitsvncommands:
1134 raise error.Abort(_(b'unknown git svn command "%s"') % svncmd)
1143 raise error.Abort(_(b'unknown git svn command "%s"') % svncmd)
1135
1144
1136 args = args[1:]
1145 args = args[1:]
1137 return gitsvncommands[svncmd](ui, repo, *args, **kwargs)
1146 return gitsvncommands[svncmd](ui, repo, *args, **kwargs)
1138
1147
1139
1148
1140 def svndcommit(ui, repo, *args, **kwargs):
1149 def svndcommit(ui, repo, *args, **kwargs):
1141 cmdoptions = []
1150 cmdoptions = []
1142 parseoptions(ui, cmdoptions, args)
1151 parseoptions(ui, cmdoptions, args)
1143
1152
1144 cmd = Command(b'push')
1153 cmd = Command(b'push')
1145
1154
1146 ui.status((bytes(cmd)), b"\n")
1155 ui.status((bytes(cmd)), b"\n")
1147
1156
1148
1157
1149 def svnfetch(ui, repo, *args, **kwargs):
1158 def svnfetch(ui, repo, *args, **kwargs):
1150 cmdoptions = []
1159 cmdoptions = []
1151 parseoptions(ui, cmdoptions, args)
1160 parseoptions(ui, cmdoptions, args)
1152
1161
1153 cmd = Command(b'pull')
1162 cmd = Command(b'pull')
1154 cmd.append(b'default-push')
1163 cmd.append(b'default-push')
1155
1164
1156 ui.status((bytes(cmd)), b"\n")
1165 ui.status((bytes(cmd)), b"\n")
1157
1166
1158
1167
1159 def svnfindrev(ui, repo, *args, **kwargs):
1168 def svnfindrev(ui, repo, *args, **kwargs):
1160 cmdoptions = []
1169 cmdoptions = []
1161 args, opts = parseoptions(ui, cmdoptions, args)
1170 args, opts = parseoptions(ui, cmdoptions, args)
1162
1171
1163 if not args:
1172 if not args:
1164 raise error.Abort(_(b'missing find-rev argument'))
1173 raise error.Abort(_(b'missing find-rev argument'))
1165
1174
1166 cmd = Command(b'log')
1175 cmd = Command(b'log')
1167 cmd[b'-r'] = args[0]
1176 cmd[b'-r'] = args[0]
1168
1177
1169 ui.status((bytes(cmd)), b"\n")
1178 ui.status((bytes(cmd)), b"\n")
1170
1179
1171
1180
1172 def svnrebase(ui, repo, *args, **kwargs):
1181 def svnrebase(ui, repo, *args, **kwargs):
1173 cmdoptions = [
1182 cmdoptions = [
1174 (b'l', b'local', None, b''),
1183 (b'l', b'local', None, b''),
1175 ]
1184 ]
1176 parseoptions(ui, cmdoptions, args)
1185 parseoptions(ui, cmdoptions, args)
1177
1186
1178 pullcmd = Command(b'pull')
1187 pullcmd = Command(b'pull')
1179 pullcmd.append(b'default-push')
1188 pullcmd.append(b'default-push')
1180 rebasecmd = Command(b'rebase')
1189 rebasecmd = Command(b'rebase')
1181 rebasecmd.append(b'tip')
1190 rebasecmd.append(b'tip')
1182
1191
1183 cmd = pullcmd & rebasecmd
1192 cmd = pullcmd & rebasecmd
1184
1193
1185 ui.status((bytes(cmd)), b"\n")
1194 ui.status((bytes(cmd)), b"\n")
1186
1195
1187
1196
1188 def tag(ui, repo, *args, **kwargs):
1197 def tag(ui, repo, *args, **kwargs):
1189 cmdoptions = [
1198 cmdoptions = [
1190 (b'f', b'force', None, b''),
1199 (b'f', b'force', None, b''),
1191 (b'l', b'list', None, b''),
1200 (b'l', b'list', None, b''),
1192 (b'd', b'delete', None, b''),
1201 (b'd', b'delete', None, b''),
1193 ]
1202 ]
1194 args, opts = parseoptions(ui, cmdoptions, args)
1203 args, opts = parseoptions(ui, cmdoptions, args)
1195
1204
1196 if opts.get(b'list'):
1205 if opts.get(b'list'):
1197 cmd = Command(b'tags')
1206 cmd = Command(b'tags')
1198 else:
1207 else:
1199 cmd = Command(b'tag')
1208 cmd = Command(b'tag')
1200
1209
1201 if not args:
1210 if not args:
1202 raise error.Abort(_(b'missing tag argument'))
1211 raise error.Abort(_(b'missing tag argument'))
1203
1212
1204 cmd.append(args[0])
1213 cmd.append(args[0])
1205 if len(args) > 1:
1214 if len(args) > 1:
1206 cmd[b'-r'] = args[1]
1215 cmd[b'-r'] = args[1]
1207
1216
1208 if opts.get(b'delete'):
1217 if opts.get(b'delete'):
1209 cmd[b'--remove'] = None
1218 cmd[b'--remove'] = None
1210
1219
1211 if opts.get(b'force'):
1220 if opts.get(b'force'):
1212 cmd[b'-f'] = None
1221 cmd[b'-f'] = None
1213
1222
1214 ui.status((bytes(cmd)), b"\n")
1223 ui.status((bytes(cmd)), b"\n")
1215
1224
1216
1225
1217 gitcommands = {
1226 gitcommands = {
1218 b'add': add,
1227 b'add': add,
1219 b'am': am,
1228 b'am': am,
1220 b'apply': apply,
1229 b'apply': apply,
1221 b'bisect': bisect,
1230 b'bisect': bisect,
1222 b'blame': blame,
1231 b'blame': blame,
1223 b'branch': branch,
1232 b'branch': branch,
1224 b'checkout': checkout,
1233 b'checkout': checkout,
1225 b'cherry-pick': cherrypick,
1234 b'cherry-pick': cherrypick,
1226 b'clean': clean,
1235 b'clean': clean,
1227 b'clone': clone,
1236 b'clone': clone,
1228 b'commit': commit,
1237 b'commit': commit,
1229 b'diff': diff,
1238 b'diff': diff,
1230 b'difftool': difftool,
1239 b'difftool': difftool,
1231 b'fetch': fetch,
1240 b'fetch': fetch,
1232 b'grep': grep,
1241 b'grep': grep,
1233 b'init': init,
1242 b'init': init,
1234 b'log': log,
1243 b'log': log,
1235 b'ls-files': lsfiles,
1244 b'ls-files': lsfiles,
1236 b'merge': merge,
1245 b'merge': merge,
1237 b'merge-base': mergebase,
1246 b'merge-base': mergebase,
1238 b'mergetool': mergetool,
1247 b'mergetool': mergetool,
1239 b'mv': mv,
1248 b'mv': mv,
1240 b'pull': pull,
1249 b'pull': pull,
1241 b'push': push,
1250 b'push': push,
1242 b'rebase': rebase,
1251 b'rebase': rebase,
1243 b'reflog': reflog,
1252 b'reflog': reflog,
1244 b'reset': reset,
1253 b'reset': reset,
1245 b'revert': revert,
1254 b'revert': revert,
1246 b'rev-parse': revparse,
1255 b'rev-parse': revparse,
1247 b'rm': rm,
1256 b'rm': rm,
1248 b'show': show,
1257 b'show': show,
1249 b'stash': stash,
1258 b'stash': stash,
1250 b'status': status,
1259 b'status': status,
1251 b'svn': svn,
1260 b'svn': svn,
1252 b'tag': tag,
1261 b'tag': tag,
1253 b'whatchanged': deprecated,
1262 b'whatchanged': deprecated,
1254 }
1263 }
1255
1264
1256 gitsvncommands = {
1265 gitsvncommands = {
1257 b'dcommit': svndcommit,
1266 b'dcommit': svndcommit,
1258 b'fetch': svnfetch,
1267 b'fetch': svnfetch,
1259 b'find-rev': svnfindrev,
1268 b'find-rev': svnfindrev,
1260 b'rebase': svnrebase,
1269 b'rebase': svnrebase,
1261 }
1270 }
@@ -1,320 +1,327 b''
1 $ cat >> $HGRCPATH << EOF
1 $ cat >> $HGRCPATH << EOF
2 > [extensions]
2 > [extensions]
3 > githelp =
3 > githelp =
4 > EOF
4 > EOF
5
5
6 $ hg init repo
6 $ hg init repo
7 $ cd repo
7 $ cd repo
8 $ echo foo > test_file
8 $ echo foo > test_file
9 $ mkdir dir
9 $ mkdir dir
10 $ echo foo > dir/file
10 $ echo foo > dir/file
11 $ echo foo > removed_file
11 $ echo foo > removed_file
12 $ echo foo > deleted_file
12 $ echo foo > deleted_file
13 $ hg add -q .
13 $ hg add -q .
14 $ hg commit -m 'bar'
14 $ hg commit -m 'bar'
15 $ hg bookmark both
15 $ hg bookmark both
16 $ touch both
16 $ touch both
17 $ touch untracked_file
17 $ touch untracked_file
18 $ hg remove removed_file
18 $ hg remove removed_file
19 $ rm deleted_file
19 $ rm deleted_file
20
20
21 githelp on a single command should succeed
21 githelp on a single command should succeed
22 $ hg githelp -- commit
22 $ hg githelp -- commit
23 hg commit
23 hg commit
24 $ hg githelp -- git commit
24 $ hg githelp -- git commit
25 hg commit
25 hg commit
26
26
27 githelp should fail nicely if we don't give it arguments
27 githelp should fail nicely if we don't give it arguments
28 $ hg githelp
28 $ hg githelp
29 abort: missing git command - usage: hg githelp -- <git command>
29 abort: missing git command - usage: hg githelp -- <git command>
30 [255]
30 [255]
31 $ hg githelp -- git
31 $ hg githelp -- git
32 abort: missing git command - usage: hg githelp -- <git command>
32 abort: missing git command - usage: hg githelp -- <git command>
33 [255]
33 [255]
34
34
35 githelp on a command with options should succeed
35 githelp on a command with options should succeed
36 $ hg githelp -- commit -pm "abc"
36 $ hg githelp -- commit -pm "abc"
37 hg commit --interactive -m 'abc'
37 hg commit --interactive -m 'abc'
38
38
39 githelp on a command with standalone unrecognized option should succeed with warning
39 githelp on a command with standalone unrecognized option should succeed with warning
40 $ hg githelp -- commit -p -v
40 $ hg githelp -- commit -p -v
41 ignoring unknown option -v
41 ignoring unknown option -v
42 hg commit --interactive
42 hg commit --interactive
43
43
44 githelp on a command with unrecognized option packed with other options should fail with error
44 githelp on a command with unrecognized option packed with other options should fail with error
45 $ hg githelp -- commit -pv
45 $ hg githelp -- commit -pv
46 abort: unknown option 'v' packed with other options
46 abort: unknown option 'v' packed with other options
47 (please try passing the option as its own flag: -v)
47 (please try passing the option as its own flag: -v)
48 [255]
48 [255]
49
49
50 githelp for git rebase --skip
50 githelp for git rebase --skip
51 $ hg githelp -- git rebase --skip
51 $ hg githelp -- git rebase --skip
52 hg revert --all -r .
52 hg revert --all -r .
53 hg rebase --continue
53 hg rebase --continue
54
54
55 githelp for git commit --amend (hg commit --amend pulls up an editor)
55 githelp for git commit --amend (hg commit --amend pulls up an editor)
56 $ hg githelp -- commit --amend
56 $ hg githelp -- commit --amend
57 hg commit --amend
57 hg commit --amend
58
58
59 githelp for git commit --amend --no-edit (hg amend does not pull up an editor)
59 githelp for git commit --amend --no-edit (hg amend does not pull up an editor)
60 $ hg githelp -- commit --amend --no-edit
60 $ hg githelp -- commit --amend --no-edit
61 hg amend
61 hg amend
62
62
63 githelp for git checkout -- . (checking out a directory)
63 githelp for git checkout -- . (checking out a directory)
64 $ hg githelp -- checkout -- .
64 $ hg githelp -- checkout -- .
65 note: use --no-backup to avoid creating .orig files
65 note: use --no-backup to avoid creating .orig files
66
66
67 hg revert .
67 hg revert .
68
68
69 githelp for git checkout "HEAD^" (should still work to pass a rev)
69 githelp for git checkout "HEAD^" (should still work to pass a rev)
70 $ hg githelp -- checkout "HEAD^"
70 $ hg githelp -- checkout "HEAD^"
71 hg update .^
71 hg update .^
72
72
73 githelp checkout: args after -- should be treated as paths no matter what
73 githelp checkout: args after -- should be treated as paths no matter what
74 $ hg githelp -- checkout -- HEAD
74 $ hg githelp -- checkout -- HEAD
75 note: use --no-backup to avoid creating .orig files
75 note: use --no-backup to avoid creating .orig files
76
76
77 hg revert HEAD
77 hg revert HEAD
78
78
79 githelp for git checkout with rev and path
79 githelp for git checkout with rev and path
80 $ hg githelp -- checkout "HEAD^" -- file.txt
80 $ hg githelp -- checkout "HEAD^" -- file.txt
81 note: use --no-backup to avoid creating .orig files
81 note: use --no-backup to avoid creating .orig files
82
82
83 hg revert -r .^ file.txt
83 hg revert -r .^ file.txt
84
84
85 githelp for git with rev and path, without separator
85 githelp for git with rev and path, without separator
86 $ hg githelp -- checkout "HEAD^" file.txt
86 $ hg githelp -- checkout "HEAD^" file.txt
87 note: use --no-backup to avoid creating .orig files
87 note: use --no-backup to avoid creating .orig files
88
88
89 hg revert -r .^ file.txt
89 hg revert -r .^ file.txt
90
90
91 githelp for checkout with a file as first argument
91 githelp for checkout with a file as first argument
92 $ hg githelp -- checkout test_file
92 $ hg githelp -- checkout test_file
93 note: use --no-backup to avoid creating .orig files
93 note: use --no-backup to avoid creating .orig files
94
94
95 hg revert test_file
95 hg revert test_file
96
96
97 githelp for checkout with a removed file as first argument
97 githelp for checkout with a removed file as first argument
98 $ hg githelp -- checkout removed_file
98 $ hg githelp -- checkout removed_file
99 note: use --no-backup to avoid creating .orig files
99 note: use --no-backup to avoid creating .orig files
100
100
101 hg revert removed_file
101 hg revert removed_file
102
102
103 githelp for checkout with a deleted file as first argument
103 githelp for checkout with a deleted file as first argument
104 $ hg githelp -- checkout deleted_file
104 $ hg githelp -- checkout deleted_file
105 note: use --no-backup to avoid creating .orig files
105 note: use --no-backup to avoid creating .orig files
106
106
107 hg revert deleted_file
107 hg revert deleted_file
108
108
109 githelp for checkout with a untracked file as first argument
109 githelp for checkout with a untracked file as first argument
110 $ hg githelp -- checkout untracked_file
110 $ hg githelp -- checkout untracked_file
111 note: use --no-backup to avoid creating .orig files
111 note: use --no-backup to avoid creating .orig files
112
112
113 hg revert untracked_file
113 hg revert untracked_file
114
114
115 githelp for checkout with a directory as first argument
115 githelp for checkout with a directory as first argument
116 $ hg githelp -- checkout dir
116 $ hg githelp -- checkout dir
117 note: use --no-backup to avoid creating .orig files
117 note: use --no-backup to avoid creating .orig files
118
118
119 hg revert dir
119 hg revert dir
120
120
121 githelp for checkout when not in repo root
121 githelp for checkout when not in repo root
122 $ cd dir
122 $ cd dir
123 $ hg githelp -- checkout file
123 $ hg githelp -- checkout file
124 note: use --no-backup to avoid creating .orig files
124 note: use --no-backup to avoid creating .orig files
125
125
126 hg revert file
126 hg revert file
127
127
128 $ cd ..
128 $ cd ..
129
129
130 githelp for checkout with an argument that is both a file and a revision
130 githelp for checkout with an argument that is both a file and a revision
131 $ hg githelp -- checkout both
131 $ hg githelp -- checkout both
132 hg update both
132 hg update both
133
133
134 githelp for checkout with the -p option
134 githelp for checkout with the -p option
135 $ hg githelp -- git checkout -p xyz
135 $ hg githelp -- git checkout -p xyz
136 hg revert -i -r xyz
136 hg revert -i -r xyz
137
137
138 $ hg githelp -- git checkout -p xyz -- abc
138 $ hg githelp -- git checkout -p xyz -- abc
139 note: use --no-backup to avoid creating .orig files
139 note: use --no-backup to avoid creating .orig files
140
140
141 hg revert -i -r xyz abc
141 hg revert -i -r xyz abc
142
142
143 githelp for checkout with the -f option and a rev
143 githelp for checkout with the -f option and a rev
144 $ hg githelp -- git checkout -f xyz
144 $ hg githelp -- git checkout -f xyz
145 hg update -C xyz
145 hg update -C xyz
146 $ hg githelp -- git checkout --force xyz
146 $ hg githelp -- git checkout --force xyz
147 hg update -C xyz
147 hg update -C xyz
148
148
149 githelp for checkout with the -f option without an arg
149 githelp for checkout with the -f option without an arg
150 $ hg githelp -- git checkout -f
150 $ hg githelp -- git checkout -f
151 hg revert --all
151 hg revert --all
152 $ hg githelp -- git checkout --force
152 $ hg githelp -- git checkout --force
153 hg revert --all
153 hg revert --all
154
154
155 githelp for grep with pattern and path
155 githelp for grep with pattern and path
156 $ hg githelp -- grep shrubbery flib/intern/
156 $ hg githelp -- grep shrubbery flib/intern/
157 hg grep shrubbery flib/intern/
157 hg grep shrubbery flib/intern/
158
158
159 githelp for reset, checking ~ in git becomes ~1 in mercurial
159 githelp for reset, checking ~ in git becomes ~1 in mercurial
160 $ hg githelp -- reset HEAD~
160 $ hg githelp -- reset HEAD~
161 hg update .~1
161 hg update .~1
162 $ hg githelp -- reset "HEAD^"
162 $ hg githelp -- reset "HEAD^"
163 hg update .^
163 hg update .^
164 $ hg githelp -- reset HEAD~3
164 $ hg githelp -- reset HEAD~3
165 hg update .~3
165 hg update .~3
166
166
167 $ hg githelp -- reset --mixed HEAD
167 $ hg githelp -- reset --mixed HEAD
168 note: --mixed has no meaning since Mercurial has no staging area
168 note: --mixed has no meaning since Mercurial has no staging area
169
169
170 hg update .
170 hg update .
171 $ hg githelp -- reset --soft HEAD
171 $ hg githelp -- reset --soft HEAD
172 note: --soft has no meaning since Mercurial has no staging area
172 note: --soft has no meaning since Mercurial has no staging area
173
173
174 hg update .
174 hg update .
175 $ hg githelp -- reset --hard HEAD
175 $ hg githelp -- reset --hard HEAD
176 hg update --clean .
176 hg update --clean .
177
177
178 githelp for git show --name-status
178 githelp for git show --name-status
179 $ hg githelp -- git show --name-status
179 $ hg githelp -- git show --name-status
180 hg log --style status -r .
180 hg log --style status -r .
181
181
182 githelp for git show --pretty=format: --name-status
182 githelp for git show --pretty=format: --name-status
183 $ hg githelp -- git show --pretty=format: --name-status
183 $ hg githelp -- git show --pretty=format: --name-status
184 hg status --change .
184 hg status --change .
185
185
186 githelp for show with no arguments
186 githelp for show with no arguments
187 $ hg githelp -- show
187 $ hg githelp -- show
188 hg export
188 hg export
189
189
190 githelp for show with a path
190 githelp for show with a path
191 $ hg githelp -- show test_file
191 $ hg githelp -- show test_file
192 hg cat test_file
192 hg cat test_file
193
193
194 githelp for show with not a path:
194 githelp for show with not a path:
195 $ hg githelp -- show rev
195 $ hg githelp -- show rev
196 hg export rev
196 hg export rev
197
197
198 githelp for show with many arguments
198 githelp for show with many arguments
199 $ hg githelp -- show argone argtwo
199 $ hg githelp -- show argone argtwo
200 hg export argone argtwo
200 hg export argone argtwo
201 $ hg githelp -- show test_file argone argtwo
201 $ hg githelp -- show test_file argone argtwo
202 hg cat test_file argone argtwo
202 hg cat test_file argone argtwo
203
203
204 githelp for show with --unified options
204 githelp for show with --unified options
205 $ hg githelp -- show --unified=10
205 $ hg githelp -- show --unified=10
206 hg export --config diff.unified=10
206 hg export --config diff.unified=10
207 $ hg githelp -- show -U100
207 $ hg githelp -- show -U100
208 hg export --config diff.unified=100
208 hg export --config diff.unified=100
209
209
210 githelp for show with a path and --unified
210 githelp for show with a path and --unified
211 $ hg githelp -- show -U20 test_file
211 $ hg githelp -- show -U20 test_file
212 hg cat test_file --config diff.unified=20
212 hg cat test_file --config diff.unified=20
213
213
214 githelp for stash drop without name
214 githelp for stash drop without name
215 $ hg githelp -- git stash drop
215 $ hg githelp -- git stash drop
216 hg shelve -d <shelve name>
216 hg shelve -d <shelve name>
217
217
218 githelp for stash drop with name
218 githelp for stash drop with name
219 $ hg githelp -- git stash drop xyz
219 $ hg githelp -- git stash drop xyz
220 hg shelve -d xyz
220 hg shelve -d xyz
221
221
222 githelp for stash list with patch
222 githelp for stash list with patch
223 $ hg githelp -- git stash list -p
223 $ hg githelp -- git stash list -p
224 hg shelve -l -p
224 hg shelve -l -p
225
225
226 githelp for stash show
226 githelp for stash show
227 $ hg githelp -- git stash show
227 $ hg githelp -- git stash show
228 hg shelve --stat
228 hg shelve --stat
229
229
230 githelp for stash show with patch and name
230 githelp for stash show with patch and name
231 $ hg githelp -- git stash show -p mystash
231 $ hg githelp -- git stash show -p mystash
232 hg shelve -p mystash
232 hg shelve -p mystash
233
233
234 githelp for stash clear
234 githelp for stash clear
235 $ hg githelp -- git stash clear
235 $ hg githelp -- git stash clear
236 hg shelve --cleanup
236 hg shelve --cleanup
237
237
238 githelp for whatchanged should show deprecated message
238 githelp for whatchanged should show deprecated message
239 $ hg githelp -- whatchanged -p
239 $ hg githelp -- whatchanged -p
240 this command has been deprecated in the git project, thus isn't supported by this tool
240 this command has been deprecated in the git project, thus isn't supported by this tool
241
241
242
242
243 githelp for git branch -m renaming
243 githelp for git branch -m renaming
244 $ hg githelp -- git branch -m old new
244 $ hg githelp -- git branch -m old new
245 hg bookmark -m old new
245 hg bookmark -m old new
246
246
247 When the old name is omitted, git branch -m new renames the current branch.
247 When the old name is omitted, git branch -m new renames the current branch.
248 $ hg githelp -- git branch -m new
248 $ hg githelp -- git branch -m new
249 hg bookmark -m `hg log -T"{activebookmark}" -r .` new
249 hg bookmark -m `hg log -T"{activebookmark}" -r .` new
250
250
251 Branch deletion in git strips commits
251 Branch deletion in git strips commits
252 $ hg githelp -- git branch -d
252 $ hg githelp -- git branch -d
253 hg strip -B
253 hg strip -B
254 $ hg githelp -- git branch -d feature
254 $ hg githelp -- git branch -d feature
255 hg strip -B feature -B
255 hg strip -B feature -B
256 $ hg githelp -- git branch --delete experiment1 experiment2
256 $ hg githelp -- git branch --delete experiment1 experiment2
257 hg strip -B experiment1 -B experiment2 -B
257 hg strip -B experiment1 -B experiment2 -B
258
258
259 githelp for reuse message using the shorthand
259 githelp for reuse message using the shorthand
260 $ hg githelp -- git commit -C deadbeef
260 $ hg githelp -- git commit -C deadbeef
261 hg commit -M deadbeef
261 hg commit -M deadbeef
262
262
263 githelp for reuse message using the the long version
263 githelp for reuse message using the the long version
264 $ hg githelp -- git commit --reuse-message deadbeef
264 $ hg githelp -- git commit --reuse-message deadbeef
265 hg commit -M deadbeef
265 hg commit -M deadbeef
266
266
267 githelp for reuse message using HEAD
267 githelp for reuse message using HEAD
268 $ hg githelp -- git commit --reuse-message HEAD~
268 $ hg githelp -- git commit --reuse-message HEAD~
269 hg commit -M .~1
269 hg commit -M .~1
270
270
271 githelp for apply with no options
271 githelp for apply with no options
272 $ hg githelp -- apply
272 $ hg githelp -- apply
273 hg import --no-commit
273 hg import --no-commit
274
274
275 githelp for apply with directory strip custom
275 githelp for apply with directory strip custom
276 $ hg githelp -- apply -p 5
276 $ hg githelp -- apply -p 5
277 hg import --no-commit -p 5
277 hg import --no-commit -p 5
278
278
279 githelp for apply with prefix directory
279 githelp for apply with prefix directory
280 $ hg githelp -- apply --directory=modules
280 $ hg githelp -- apply --directory=modules
281 hg import --no-commit --prefix modules
281 hg import --no-commit --prefix modules
282
282
283 git merge-base
283 git merge-base
284 $ hg githelp -- git merge-base --is-ancestor
284 $ hg githelp -- git merge-base --is-ancestor
285 ignoring unknown option --is-ancestor
285 ignoring unknown option --is-ancestor
286 note: ancestors() is part of the revset language
286 note: ancestors() is part of the revset language
287 (learn more about revsets with 'hg help revsets')
287 (learn more about revsets with 'hg help revsets')
288
288
289 hg log -T '{node}\n' -r 'ancestor(A,B)'
289 hg log -T '{node}\n' -r 'ancestor(A,B)'
290
290
291 githelp for git blame
291 githelp for git blame
292 $ hg githelp -- git blame
292 $ hg githelp -- git blame
293 hg annotate -udl
293 hg annotate -udl
294
294
295 githelp for add
295 githelp for add
296
296
297 $ hg githelp -- git add
297 $ hg githelp -- git add
298 hg add
298 hg add
299
299
300 $ hg githelp -- git add -p
300 $ hg githelp -- git add -p
301 note: Mercurial will commit when complete, as there is no staging area in Mercurial
301 note: Mercurial will commit when complete, as there is no staging area in Mercurial
302
302
303 hg commit --interactive
303 hg commit --interactive
304
304
305 $ hg githelp -- git add --all
305 $ hg githelp -- git add --all
306 note: use hg addremove to remove files that have been deleted
306 note: use hg addremove to remove files that have been deleted
307
307
308 hg add
308 hg add
309
309
310 githelp for reflog
310 githelp for reflog
311
311
312 $ hg githelp -- git reflog
312 $ hg githelp -- git reflog
313 hg journal
313 hg journal
314
314
315 note: in hg commits can be deleted from repo but we always have backups
315 note: in hg commits can be deleted from repo but we always have backups
316
316
317 $ hg githelp -- git reflog --all
317 $ hg githelp -- git reflog --all
318 hg journal --all
318 hg journal --all
319
319
320 note: in hg commits can be deleted from repo but we always have backups
320 note: in hg commits can be deleted from repo but we always have backups
321
322 $ hg githelp -- git log -Gnarf
323 hg grep --diff narf
324 $ hg githelp -- git log -S narf
325 hg grep --diff narf
326 $ hg githelp -- git log --pickaxe-regex narf
327 hg grep --diff narf
General Comments 0
You need to be logged in to leave comments. Login now