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