Show More
@@ -1,1079 +1,1090 | |||||
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: | |||
|
240 | raise error.Abort(_('missing newbranch argument')) | |||
239 | new = args[0] |
|
241 | new = args[0] | |
240 | cmd['-m'] = old |
|
242 | cmd['-m'] = old | |
241 | cmd.append(new) |
|
243 | cmd.append(new) | |
242 | else: |
|
244 | else: | |
243 | if len(args) > 1: |
|
245 | if len(args) > 1: | |
244 | cmd['-r'] = args[1] |
|
246 | cmd['-r'] = args[1] | |
245 | cmd.append(args[0]) |
|
247 | cmd.append(args[0]) | |
246 | elif len(args) == 1: |
|
248 | elif len(args) == 1: | |
247 | cmd.append(args[0]) |
|
249 | cmd.append(args[0]) | |
248 | ui.status((bytes(cmd)), "\n") |
|
250 | ui.status((bytes(cmd)), "\n") | |
249 |
|
251 | |||
250 | def ispath(repo, string): |
|
252 | def ispath(repo, string): | |
251 | """ |
|
253 | """ | |
252 | 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 | |
253 | 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 | |
254 | 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 | |
255 | them, so let's be conservative. |
|
257 | them, so let's be conservative. | |
256 | """ |
|
258 | """ | |
257 | if scmutil.isrevsymbol(repo, string): |
|
259 | if scmutil.isrevsymbol(repo, string): | |
258 | # 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 | |
259 | # same name exists. |
|
261 | # same name exists. | |
260 | return False |
|
262 | return False | |
261 |
|
263 | |||
262 | cwd = repo.getcwd() |
|
264 | cwd = repo.getcwd() | |
263 | if cwd == '': |
|
265 | if cwd == '': | |
264 | repopath = string |
|
266 | repopath = string | |
265 | else: |
|
267 | else: | |
266 | repopath = cwd + '/' + string |
|
268 | repopath = cwd + '/' + string | |
267 |
|
269 | |||
268 | exists = repo.wvfs.exists(repopath) |
|
270 | exists = repo.wvfs.exists(repopath) | |
269 | if exists: |
|
271 | if exists: | |
270 | return True |
|
272 | return True | |
271 |
|
273 | |||
272 | manifest = repo['.'].manifest() |
|
274 | manifest = repo['.'].manifest() | |
273 |
|
275 | |||
274 | didexist = (repopath in manifest) or manifest.hasdir(repopath) |
|
276 | didexist = (repopath in manifest) or manifest.hasdir(repopath) | |
275 |
|
277 | |||
276 | return didexist |
|
278 | return didexist | |
277 |
|
279 | |||
278 | def checkout(ui, repo, *args, **kwargs): |
|
280 | def checkout(ui, repo, *args, **kwargs): | |
279 | cmdoptions = [ |
|
281 | cmdoptions = [ | |
280 | ('b', 'branch', '', ''), |
|
282 | ('b', 'branch', '', ''), | |
281 | ('B', 'branch', '', ''), |
|
283 | ('B', 'branch', '', ''), | |
282 | ('f', 'force', None, ''), |
|
284 | ('f', 'force', None, ''), | |
283 | ('p', 'patch', None, ''), |
|
285 | ('p', 'patch', None, ''), | |
284 | ] |
|
286 | ] | |
285 | paths = [] |
|
287 | paths = [] | |
286 | if '--' in args: |
|
288 | if '--' in args: | |
287 | sepindex = args.index('--') |
|
289 | sepindex = args.index('--') | |
288 | paths.extend(args[sepindex + 1:]) |
|
290 | paths.extend(args[sepindex + 1:]) | |
289 | args = args[:sepindex] |
|
291 | args = args[:sepindex] | |
290 |
|
292 | |||
291 | args, opts = parseoptions(ui, cmdoptions, args) |
|
293 | args, opts = parseoptions(ui, cmdoptions, args) | |
292 |
|
294 | |||
293 | rev = None |
|
295 | rev = None | |
294 | if args and ispath(repo, args[0]): |
|
296 | if args and ispath(repo, args[0]): | |
295 | paths = args + paths |
|
297 | paths = args + paths | |
296 | elif args: |
|
298 | elif args: | |
297 | rev = args[0] |
|
299 | rev = args[0] | |
298 | paths = args[1:] + paths |
|
300 | paths = args[1:] + paths | |
299 |
|
301 | |||
300 | cmd = Command('update') |
|
302 | cmd = Command('update') | |
301 |
|
303 | |||
302 | if opts.get('force'): |
|
304 | if opts.get('force'): | |
303 | if paths or rev: |
|
305 | if paths or rev: | |
304 | cmd['-C'] = None |
|
306 | cmd['-C'] = None | |
305 |
|
307 | |||
306 | if opts.get('patch'): |
|
308 | if opts.get('patch'): | |
307 | cmd = Command('revert') |
|
309 | cmd = Command('revert') | |
308 | cmd['-i'] = None |
|
310 | cmd['-i'] = None | |
309 |
|
311 | |||
310 | if opts.get('branch'): |
|
312 | if opts.get('branch'): | |
311 | if len(args) == 0: |
|
313 | if len(args) == 0: | |
312 | cmd = Command('bookmark') |
|
314 | cmd = Command('bookmark') | |
313 | cmd.append(opts.get('branch')) |
|
315 | cmd.append(opts.get('branch')) | |
314 | else: |
|
316 | else: | |
315 | cmd.append(args[0]) |
|
317 | cmd.append(args[0]) | |
316 | bookcmd = Command('bookmark') |
|
318 | bookcmd = Command('bookmark') | |
317 | bookcmd.append(opts.get('branch')) |
|
319 | bookcmd.append(opts.get('branch')) | |
318 | cmd = cmd & bookcmd |
|
320 | cmd = cmd & bookcmd | |
319 | # 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 | |
320 | elif len(paths) > 0: |
|
322 | elif len(paths) > 0: | |
321 | 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")) | |
322 | cmd = Command('revert') |
|
324 | cmd = Command('revert') | |
323 | if opts.get('patch'): |
|
325 | if opts.get('patch'): | |
324 | cmd['-i'] = None |
|
326 | cmd['-i'] = None | |
325 | if rev: |
|
327 | if rev: | |
326 | cmd['-r'] = rev |
|
328 | cmd['-r'] = rev | |
327 | cmd.extend(paths) |
|
329 | cmd.extend(paths) | |
328 | elif rev: |
|
330 | elif rev: | |
329 | if opts.get('patch'): |
|
331 | if opts.get('patch'): | |
330 | cmd['-r'] = rev |
|
332 | cmd['-r'] = rev | |
331 | else: |
|
333 | else: | |
332 | cmd.append(rev) |
|
334 | cmd.append(rev) | |
333 | elif opts.get('force'): |
|
335 | elif opts.get('force'): | |
334 | cmd = Command('revert') |
|
336 | cmd = Command('revert') | |
335 | cmd['--all'] = None |
|
337 | cmd['--all'] = None | |
336 | else: |
|
338 | else: | |
337 | raise error.Abort("a commit must be specified") |
|
339 | raise error.Abort("a commit must be specified") | |
338 |
|
340 | |||
339 | ui.status((bytes(cmd)), "\n") |
|
341 | ui.status((bytes(cmd)), "\n") | |
340 |
|
342 | |||
341 | def cherrypick(ui, repo, *args, **kwargs): |
|
343 | def cherrypick(ui, repo, *args, **kwargs): | |
342 | cmdoptions = [ |
|
344 | cmdoptions = [ | |
343 | ('', 'continue', None, ''), |
|
345 | ('', 'continue', None, ''), | |
344 | ('', 'abort', None, ''), |
|
346 | ('', 'abort', None, ''), | |
345 | ('e', 'edit', None, ''), |
|
347 | ('e', 'edit', None, ''), | |
346 | ] |
|
348 | ] | |
347 | args, opts = parseoptions(ui, cmdoptions, args) |
|
349 | args, opts = parseoptions(ui, cmdoptions, args) | |
348 |
|
350 | |||
349 | cmd = Command('graft') |
|
351 | cmd = Command('graft') | |
350 |
|
352 | |||
351 | if opts.get('edit'): |
|
353 | if opts.get('edit'): | |
352 | cmd['--edit'] = None |
|
354 | cmd['--edit'] = None | |
353 | if opts.get('continue'): |
|
355 | if opts.get('continue'): | |
354 | cmd['--continue'] = None |
|
356 | cmd['--continue'] = None | |
355 | elif opts.get('abort'): |
|
357 | elif opts.get('abort'): | |
356 | ui.status(_("note: hg graft does not have --abort.\n\n")) |
|
358 | ui.status(_("note: hg graft does not have --abort.\n\n")) | |
357 | return |
|
359 | return | |
358 | else: |
|
360 | else: | |
359 | cmd.extend(args) |
|
361 | cmd.extend(args) | |
360 |
|
362 | |||
361 | ui.status((bytes(cmd)), "\n") |
|
363 | ui.status((bytes(cmd)), "\n") | |
362 |
|
364 | |||
363 | def clean(ui, repo, *args, **kwargs): |
|
365 | def clean(ui, repo, *args, **kwargs): | |
364 | cmdoptions = [ |
|
366 | cmdoptions = [ | |
365 | ('d', 'd', None, ''), |
|
367 | ('d', 'd', None, ''), | |
366 | ('f', 'force', None, ''), |
|
368 | ('f', 'force', None, ''), | |
367 | ('x', 'x', None, ''), |
|
369 | ('x', 'x', None, ''), | |
368 | ] |
|
370 | ] | |
369 | args, opts = parseoptions(ui, cmdoptions, args) |
|
371 | args, opts = parseoptions(ui, cmdoptions, args) | |
370 |
|
372 | |||
371 | cmd = Command('purge') |
|
373 | cmd = Command('purge') | |
372 | if opts.get('x'): |
|
374 | if opts.get('x'): | |
373 | cmd['--all'] = None |
|
375 | cmd['--all'] = None | |
374 | cmd.extend(args) |
|
376 | cmd.extend(args) | |
375 |
|
377 | |||
376 | ui.status((bytes(cmd)), "\n") |
|
378 | ui.status((bytes(cmd)), "\n") | |
377 |
|
379 | |||
378 | def clone(ui, repo, *args, **kwargs): |
|
380 | def clone(ui, repo, *args, **kwargs): | |
379 | cmdoptions = [ |
|
381 | cmdoptions = [ | |
380 | ('', 'bare', None, ''), |
|
382 | ('', 'bare', None, ''), | |
381 | ('n', 'no-checkout', None, ''), |
|
383 | ('n', 'no-checkout', None, ''), | |
382 | ('b', 'branch', '', ''), |
|
384 | ('b', 'branch', '', ''), | |
383 | ] |
|
385 | ] | |
384 | args, opts = parseoptions(ui, cmdoptions, args) |
|
386 | args, opts = parseoptions(ui, cmdoptions, args) | |
385 |
|
387 | |||
386 | if len(args) == 0: |
|
388 | if len(args) == 0: | |
387 | raise error.Abort("a repository to clone must be specified") |
|
389 | raise error.Abort("a repository to clone must be specified") | |
388 |
|
390 | |||
389 | cmd = Command('clone') |
|
391 | cmd = Command('clone') | |
390 | cmd.append(args[0]) |
|
392 | cmd.append(args[0]) | |
391 | if len(args) > 1: |
|
393 | if len(args) > 1: | |
392 | cmd.append(args[1]) |
|
394 | cmd.append(args[1]) | |
393 |
|
395 | |||
394 | if opts.get('bare'): |
|
396 | if opts.get('bare'): | |
395 | cmd['-U'] = None |
|
397 | cmd['-U'] = None | |
396 | ui.status(_("note: Mercurial does not have bare clones. " + |
|
398 | ui.status(_("note: Mercurial does not have bare clones. " + | |
397 | "-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")) | |
398 | elif opts.get('no_checkout'): |
|
400 | elif opts.get('no_checkout'): | |
399 | cmd['-U'] = None |
|
401 | cmd['-U'] = None | |
400 |
|
402 | |||
401 | if opts.get('branch'): |
|
403 | if opts.get('branch'): | |
402 | cocmd = Command("update") |
|
404 | cocmd = Command("update") | |
403 | cocmd.append(opts.get('branch')) |
|
405 | cocmd.append(opts.get('branch')) | |
404 | cmd = cmd & cocmd |
|
406 | cmd = cmd & cocmd | |
405 |
|
407 | |||
406 | ui.status((bytes(cmd)), "\n") |
|
408 | ui.status((bytes(cmd)), "\n") | |
407 |
|
409 | |||
408 | def commit(ui, repo, *args, **kwargs): |
|
410 | def commit(ui, repo, *args, **kwargs): | |
409 | cmdoptions = [ |
|
411 | cmdoptions = [ | |
410 | ('a', 'all', None, ''), |
|
412 | ('a', 'all', None, ''), | |
411 | ('m', 'message', '', ''), |
|
413 | ('m', 'message', '', ''), | |
412 | ('p', 'patch', None, ''), |
|
414 | ('p', 'patch', None, ''), | |
413 | ('C', 'reuse-message', '', ''), |
|
415 | ('C', 'reuse-message', '', ''), | |
414 | ('F', 'file', '', ''), |
|
416 | ('F', 'file', '', ''), | |
415 | ('', 'author', '', ''), |
|
417 | ('', 'author', '', ''), | |
416 | ('', 'date', '', ''), |
|
418 | ('', 'date', '', ''), | |
417 | ('', 'amend', None, ''), |
|
419 | ('', 'amend', None, ''), | |
418 | ('', 'no-edit', None, ''), |
|
420 | ('', 'no-edit', None, ''), | |
419 | ] |
|
421 | ] | |
420 | args, opts = parseoptions(ui, cmdoptions, args) |
|
422 | args, opts = parseoptions(ui, cmdoptions, args) | |
421 |
|
423 | |||
422 | cmd = Command('commit') |
|
424 | cmd = Command('commit') | |
423 | if opts.get('patch'): |
|
425 | if opts.get('patch'): | |
424 | cmd = Command('commit --interactive') |
|
426 | cmd = Command('commit --interactive') | |
425 |
|
427 | |||
426 | if opts.get('amend'): |
|
428 | if opts.get('amend'): | |
427 | if opts.get('no_edit'): |
|
429 | if opts.get('no_edit'): | |
428 | cmd = Command('amend') |
|
430 | cmd = Command('amend') | |
429 | else: |
|
431 | else: | |
430 | cmd['--amend'] = None |
|
432 | cmd['--amend'] = None | |
431 |
|
433 | |||
432 | if opts.get('reuse_message'): |
|
434 | if opts.get('reuse_message'): | |
433 | cmd['-M'] = opts.get('reuse_message') |
|
435 | cmd['-M'] = opts.get('reuse_message') | |
434 |
|
436 | |||
435 | if opts.get('message'): |
|
437 | if opts.get('message'): | |
436 | cmd['-m'] = "'%s'" % (opts.get('message'),) |
|
438 | cmd['-m'] = "'%s'" % (opts.get('message'),) | |
437 |
|
439 | |||
438 | if opts.get('all'): |
|
440 | if opts.get('all'): | |
439 | ui.status(_("note: Mercurial doesn't have a staging area, " + |
|
441 | ui.status(_("note: Mercurial doesn't have a staging area, " + | |
440 | "so there is no --all. -A will add and remove files " + |
|
442 | "so there is no --all. -A will add and remove files " + | |
441 | "for you though.\n\n")) |
|
443 | "for you though.\n\n")) | |
442 |
|
444 | |||
443 | if opts.get('file'): |
|
445 | if opts.get('file'): | |
444 | cmd['-l'] = opts.get('file') |
|
446 | cmd['-l'] = opts.get('file') | |
445 |
|
447 | |||
446 | if opts.get('author'): |
|
448 | if opts.get('author'): | |
447 | cmd['-u'] = opts.get('author') |
|
449 | cmd['-u'] = opts.get('author') | |
448 |
|
450 | |||
449 | if opts.get('date'): |
|
451 | if opts.get('date'): | |
450 | cmd['-d'] = opts.get('date') |
|
452 | cmd['-d'] = opts.get('date') | |
451 |
|
453 | |||
452 | cmd.extend(args) |
|
454 | cmd.extend(args) | |
453 |
|
455 | |||
454 | ui.status((bytes(cmd)), "\n") |
|
456 | ui.status((bytes(cmd)), "\n") | |
455 |
|
457 | |||
456 | def deprecated(ui, repo, *args, **kwargs): |
|
458 | def deprecated(ui, repo, *args, **kwargs): | |
457 | ui.warn(_('This command has been deprecated in the git project, ' + |
|
459 | ui.warn(_('This command has been deprecated in the git project, ' + | |
458 | 'thus isn\'t supported by this tool.\n\n')) |
|
460 | 'thus isn\'t supported by this tool.\n\n')) | |
459 |
|
461 | |||
460 | def diff(ui, repo, *args, **kwargs): |
|
462 | def diff(ui, repo, *args, **kwargs): | |
461 | cmdoptions = [ |
|
463 | cmdoptions = [ | |
462 | ('a', 'all', None, ''), |
|
464 | ('a', 'all', None, ''), | |
463 | ('', 'cached', None, ''), |
|
465 | ('', 'cached', None, ''), | |
464 | ('R', 'reverse', None, ''), |
|
466 | ('R', 'reverse', None, ''), | |
465 | ] |
|
467 | ] | |
466 | args, opts = parseoptions(ui, cmdoptions, args) |
|
468 | args, opts = parseoptions(ui, cmdoptions, args) | |
467 |
|
469 | |||
468 | cmd = Command('diff') |
|
470 | cmd = Command('diff') | |
469 |
|
471 | |||
470 | if opts.get('cached'): |
|
472 | if opts.get('cached'): | |
471 | ui.status(_('note: Mercurial has no concept of a staging area, ' + |
|
473 | ui.status(_('note: Mercurial has no concept of a staging area, ' + | |
472 | 'so --cached does nothing.\n\n')) |
|
474 | 'so --cached does nothing.\n\n')) | |
473 |
|
475 | |||
474 | if opts.get('reverse'): |
|
476 | if opts.get('reverse'): | |
475 | cmd['--reverse'] = None |
|
477 | cmd['--reverse'] = None | |
476 |
|
478 | |||
477 | for a in list(args): |
|
479 | for a in list(args): | |
478 | args.remove(a) |
|
480 | args.remove(a) | |
479 | try: |
|
481 | try: | |
480 | repo.revs(a) |
|
482 | repo.revs(a) | |
481 | cmd['-r'] = a |
|
483 | cmd['-r'] = a | |
482 | except Exception: |
|
484 | except Exception: | |
483 | cmd.append(a) |
|
485 | cmd.append(a) | |
484 |
|
486 | |||
485 | ui.status((bytes(cmd)), "\n") |
|
487 | ui.status((bytes(cmd)), "\n") | |
486 |
|
488 | |||
487 | def difftool(ui, repo, *args, **kwargs): |
|
489 | def difftool(ui, repo, *args, **kwargs): | |
488 | ui.status(_('Mercurial does not enable external difftool by default. You ' |
|
490 | ui.status(_('Mercurial does not enable external difftool by default. You ' | |
489 | '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' | |
490 | 'extdiff =\n' |
|
492 | 'extdiff =\n' | |
491 | 'to the [extensions] section and then running\n\n' |
|
493 | 'to the [extensions] section and then running\n\n' | |
492 | 'hg extdiff -p <program>\n\n' |
|
494 | 'hg extdiff -p <program>\n\n' | |
493 | 'See \'hg help extdiff\' and \'hg help -e extdiff\' for more ' |
|
495 | 'See \'hg help extdiff\' and \'hg help -e extdiff\' for more ' | |
494 | 'information.\n')) |
|
496 | 'information.\n')) | |
495 |
|
497 | |||
496 | def fetch(ui, repo, *args, **kwargs): |
|
498 | def fetch(ui, repo, *args, **kwargs): | |
497 | cmdoptions = [ |
|
499 | cmdoptions = [ | |
498 | ('', 'all', None, ''), |
|
500 | ('', 'all', None, ''), | |
499 | ('f', 'force', None, ''), |
|
501 | ('f', 'force', None, ''), | |
500 | ] |
|
502 | ] | |
501 | args, opts = parseoptions(ui, cmdoptions, args) |
|
503 | args, opts = parseoptions(ui, cmdoptions, args) | |
502 |
|
504 | |||
503 | cmd = Command('pull') |
|
505 | cmd = Command('pull') | |
504 |
|
506 | |||
505 | if len(args) > 0: |
|
507 | if len(args) > 0: | |
506 | cmd.append(args[0]) |
|
508 | cmd.append(args[0]) | |
507 | if len(args) > 1: |
|
509 | if len(args) > 1: | |
508 | ui.status(_("note: Mercurial doesn't have refspecs. " + |
|
510 | ui.status(_("note: Mercurial doesn't have refspecs. " + | |
509 | "-r can be used to specify which commits you want to pull. " + |
|
511 | "-r can be used to specify which commits you want to pull. " + | |
510 | "-B can be used to specify which bookmark you want to pull." + |
|
512 | "-B can be used to specify which bookmark you want to pull." + | |
511 | "\n\n")) |
|
513 | "\n\n")) | |
512 | for v in args[1:]: |
|
514 | for v in args[1:]: | |
513 | if v in repo._bookmarks: |
|
515 | if v in repo._bookmarks: | |
514 | cmd['-B'] = v |
|
516 | cmd['-B'] = v | |
515 | else: |
|
517 | else: | |
516 | cmd['-r'] = v |
|
518 | cmd['-r'] = v | |
517 |
|
519 | |||
518 | ui.status((bytes(cmd)), "\n") |
|
520 | ui.status((bytes(cmd)), "\n") | |
519 |
|
521 | |||
520 | def grep(ui, repo, *args, **kwargs): |
|
522 | def grep(ui, repo, *args, **kwargs): | |
521 | cmdoptions = [ |
|
523 | cmdoptions = [ | |
522 | ] |
|
524 | ] | |
523 | args, opts = parseoptions(ui, cmdoptions, args) |
|
525 | args, opts = parseoptions(ui, cmdoptions, args) | |
524 |
|
526 | |||
525 | cmd = Command('grep') |
|
527 | cmd = Command('grep') | |
526 |
|
528 | |||
527 | # 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 | |
528 | # pattern first, followed by paths. |
|
530 | # pattern first, followed by paths. | |
529 | cmd.extend(args) |
|
531 | cmd.extend(args) | |
530 |
|
532 | |||
531 | ui.status((bytes(cmd)), "\n") |
|
533 | ui.status((bytes(cmd)), "\n") | |
532 |
|
534 | |||
533 | def init(ui, repo, *args, **kwargs): |
|
535 | def init(ui, repo, *args, **kwargs): | |
534 | cmdoptions = [ |
|
536 | cmdoptions = [ | |
535 | ] |
|
537 | ] | |
536 | args, opts = parseoptions(ui, cmdoptions, args) |
|
538 | args, opts = parseoptions(ui, cmdoptions, args) | |
537 |
|
539 | |||
538 | cmd = Command('init') |
|
540 | cmd = Command('init') | |
539 |
|
541 | |||
540 | if len(args) > 0: |
|
542 | if len(args) > 0: | |
541 | cmd.append(args[0]) |
|
543 | cmd.append(args[0]) | |
542 |
|
544 | |||
543 | ui.status((bytes(cmd)), "\n") |
|
545 | ui.status((bytes(cmd)), "\n") | |
544 |
|
546 | |||
545 | def log(ui, repo, *args, **kwargs): |
|
547 | def log(ui, repo, *args, **kwargs): | |
546 | cmdoptions = [ |
|
548 | cmdoptions = [ | |
547 | ('', 'follow', None, ''), |
|
549 | ('', 'follow', None, ''), | |
548 | ('', 'decorate', None, ''), |
|
550 | ('', 'decorate', None, ''), | |
549 | ('n', 'number', '', ''), |
|
551 | ('n', 'number', '', ''), | |
550 | ('1', '1', None, ''), |
|
552 | ('1', '1', None, ''), | |
551 | ('', 'pretty', '', ''), |
|
553 | ('', 'pretty', '', ''), | |
552 | ('', 'format', '', ''), |
|
554 | ('', 'format', '', ''), | |
553 | ('', 'oneline', None, ''), |
|
555 | ('', 'oneline', None, ''), | |
554 | ('', 'stat', None, ''), |
|
556 | ('', 'stat', None, ''), | |
555 | ('', 'graph', None, ''), |
|
557 | ('', 'graph', None, ''), | |
556 | ('p', 'patch', None, ''), |
|
558 | ('p', 'patch', None, ''), | |
557 | ] |
|
559 | ] | |
558 | args, opts = parseoptions(ui, cmdoptions, args) |
|
560 | args, opts = parseoptions(ui, cmdoptions, args) | |
559 | 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 ' + | |
560 | 'print just the first line, drop the -v.\n\n')) |
|
562 | 'print just the first line, drop the -v.\n\n')) | |
561 | 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 " + | |
562 | "log output.\n\n")) |
|
564 | "log output.\n\n")) | |
563 |
|
565 | |||
564 | cmd = Command('log') |
|
566 | cmd = Command('log') | |
565 | cmd['-v'] = None |
|
567 | cmd['-v'] = None | |
566 |
|
568 | |||
567 | if opts.get('number'): |
|
569 | if opts.get('number'): | |
568 | cmd['-l'] = opts.get('number') |
|
570 | cmd['-l'] = opts.get('number') | |
569 | if opts.get('1'): |
|
571 | if opts.get('1'): | |
570 | cmd['-l'] = '1' |
|
572 | cmd['-l'] = '1' | |
571 | if opts.get('stat'): |
|
573 | if opts.get('stat'): | |
572 | cmd['--stat'] = None |
|
574 | cmd['--stat'] = None | |
573 | if opts.get('graph'): |
|
575 | if opts.get('graph'): | |
574 | cmd['-G'] = None |
|
576 | cmd['-G'] = None | |
575 | if opts.get('patch'): |
|
577 | if opts.get('patch'): | |
576 | cmd['-p'] = None |
|
578 | cmd['-p'] = None | |
577 |
|
579 | |||
578 | 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'): | |
579 | format = opts.get('format', '') |
|
581 | format = opts.get('format', '') | |
580 | if 'format:' in format: |
|
582 | if 'format:' in format: | |
581 | ui.status(_("note: --format format:??? equates to Mercurial's " + |
|
583 | ui.status(_("note: --format format:??? equates to Mercurial's " + | |
582 | "--template. See hg help templates for more info.\n\n")) |
|
584 | "--template. See hg help templates for more info.\n\n")) | |
583 | cmd['--template'] = '???' |
|
585 | cmd['--template'] = '???' | |
584 | else: |
|
586 | else: | |
585 | ui.status(_("note: --pretty/format/oneline equate to Mercurial's " + |
|
587 | ui.status(_("note: --pretty/format/oneline equate to Mercurial's " + | |
586 | "--style or --template. See hg help templates for more info." + |
|
588 | "--style or --template. See hg help templates for more info." + | |
587 | "\n\n")) |
|
589 | "\n\n")) | |
588 | cmd['--style'] = '???' |
|
590 | cmd['--style'] = '???' | |
589 |
|
591 | |||
590 | if len(args) > 0: |
|
592 | if len(args) > 0: | |
591 | if '..' in args[0]: |
|
593 | if '..' in args[0]: | |
592 | since, until = args[0].split('..') |
|
594 | since, until = args[0].split('..') | |
593 | cmd['-r'] = "'%s::%s'" % (since, until) |
|
595 | cmd['-r'] = "'%s::%s'" % (since, until) | |
594 | del args[0] |
|
596 | del args[0] | |
595 | cmd.extend(args) |
|
597 | cmd.extend(args) | |
596 |
|
598 | |||
597 | ui.status((bytes(cmd)), "\n") |
|
599 | ui.status((bytes(cmd)), "\n") | |
598 |
|
600 | |||
599 | def lsfiles(ui, repo, *args, **kwargs): |
|
601 | def lsfiles(ui, repo, *args, **kwargs): | |
600 | cmdoptions = [ |
|
602 | cmdoptions = [ | |
601 | ('c', 'cached', None, ''), |
|
603 | ('c', 'cached', None, ''), | |
602 | ('d', 'deleted', None, ''), |
|
604 | ('d', 'deleted', None, ''), | |
603 | ('m', 'modified', None, ''), |
|
605 | ('m', 'modified', None, ''), | |
604 | ('o', 'others', None, ''), |
|
606 | ('o', 'others', None, ''), | |
605 | ('i', 'ignored', None, ''), |
|
607 | ('i', 'ignored', None, ''), | |
606 | ('s', 'stage', None, ''), |
|
608 | ('s', 'stage', None, ''), | |
607 | ('z', '_zero', None, ''), |
|
609 | ('z', '_zero', None, ''), | |
608 | ] |
|
610 | ] | |
609 | args, opts = parseoptions(ui, cmdoptions, args) |
|
611 | args, opts = parseoptions(ui, cmdoptions, args) | |
610 |
|
612 | |||
611 | if (opts.get('modified') or opts.get('deleted') |
|
613 | if (opts.get('modified') or opts.get('deleted') | |
612 | or opts.get('others') or opts.get('ignored')): |
|
614 | or opts.get('others') or opts.get('ignored')): | |
613 | cmd = Command('status') |
|
615 | cmd = Command('status') | |
614 | if opts.get('deleted'): |
|
616 | if opts.get('deleted'): | |
615 | cmd['-d'] = None |
|
617 | cmd['-d'] = None | |
616 | if opts.get('modified'): |
|
618 | if opts.get('modified'): | |
617 | cmd['-m'] = None |
|
619 | cmd['-m'] = None | |
618 | if opts.get('others'): |
|
620 | if opts.get('others'): | |
619 | cmd['-o'] = None |
|
621 | cmd['-o'] = None | |
620 | if opts.get('ignored'): |
|
622 | if opts.get('ignored'): | |
621 | cmd['-i'] = None |
|
623 | cmd['-i'] = None | |
622 | else: |
|
624 | else: | |
623 | cmd = Command('files') |
|
625 | cmd = Command('files') | |
624 | if opts.get('stage'): |
|
626 | if opts.get('stage'): | |
625 | ui.status(_("note: Mercurial doesn't have a staging area, ignoring " |
|
627 | ui.status(_("note: Mercurial doesn't have a staging area, ignoring " | |
626 | "--stage\n")) |
|
628 | "--stage\n")) | |
627 | if opts.get('_zero'): |
|
629 | if opts.get('_zero'): | |
628 | cmd['-0'] = None |
|
630 | cmd['-0'] = None | |
629 | cmd.append('.') |
|
631 | cmd.append('.') | |
630 | for include in args: |
|
632 | for include in args: | |
631 | cmd['-I'] = procutil.shellquote(include) |
|
633 | cmd['-I'] = procutil.shellquote(include) | |
632 |
|
634 | |||
633 | ui.status((bytes(cmd)), "\n") |
|
635 | ui.status((bytes(cmd)), "\n") | |
634 |
|
636 | |||
635 | def merge(ui, repo, *args, **kwargs): |
|
637 | def merge(ui, repo, *args, **kwargs): | |
636 | cmdoptions = [ |
|
638 | cmdoptions = [ | |
637 | ] |
|
639 | ] | |
638 | args, opts = parseoptions(ui, cmdoptions, args) |
|
640 | args, opts = parseoptions(ui, cmdoptions, args) | |
639 |
|
641 | |||
640 | cmd = Command('merge') |
|
642 | cmd = Command('merge') | |
641 |
|
643 | |||
642 | if len(args) > 0: |
|
644 | if len(args) > 0: | |
643 | cmd.append(args[len(args) - 1]) |
|
645 | cmd.append(args[len(args) - 1]) | |
644 |
|
646 | |||
645 | ui.status((bytes(cmd)), "\n") |
|
647 | ui.status((bytes(cmd)), "\n") | |
646 |
|
648 | |||
647 | def mergebase(ui, repo, *args, **kwargs): |
|
649 | def mergebase(ui, repo, *args, **kwargs): | |
648 | cmdoptions = [] |
|
650 | cmdoptions = [] | |
649 | args, opts = parseoptions(ui, cmdoptions, args) |
|
651 | args, opts = parseoptions(ui, cmdoptions, args) | |
650 |
|
652 | |||
651 | if len(args) != 2: |
|
653 | if len(args) != 2: | |
652 | args = ['A', 'B'] |
|
654 | args = ['A', 'B'] | |
653 |
|
655 | |||
654 | cmd = Command("log -T '{node}\\n' -r 'ancestor(%s,%s)'" |
|
656 | cmd = Command("log -T '{node}\\n' -r 'ancestor(%s,%s)'" | |
655 | % (args[0], args[1])) |
|
657 | % (args[0], args[1])) | |
656 |
|
658 | |||
657 | ui.status(_('NOTE: ancestors() is part of the revset language.\n'), |
|
659 | ui.status(_('NOTE: ancestors() is part of the revset language.\n'), | |
658 | _("Learn more about revsets with 'hg help revsets'\n\n")) |
|
660 | _("Learn more about revsets with 'hg help revsets'\n\n")) | |
659 | ui.status((bytes(cmd)), "\n") |
|
661 | ui.status((bytes(cmd)), "\n") | |
660 |
|
662 | |||
661 | def mergetool(ui, repo, *args, **kwargs): |
|
663 | def mergetool(ui, repo, *args, **kwargs): | |
662 | cmdoptions = [] |
|
664 | cmdoptions = [] | |
663 | args, opts = parseoptions(ui, cmdoptions, args) |
|
665 | args, opts = parseoptions(ui, cmdoptions, args) | |
664 |
|
666 | |||
665 | cmd = Command("resolve") |
|
667 | cmd = Command("resolve") | |
666 |
|
668 | |||
667 | if len(args) == 0: |
|
669 | if len(args) == 0: | |
668 | cmd['--all'] = None |
|
670 | cmd['--all'] = None | |
669 | cmd.extend(args) |
|
671 | cmd.extend(args) | |
670 | ui.status((bytes(cmd)), "\n") |
|
672 | ui.status((bytes(cmd)), "\n") | |
671 |
|
673 | |||
672 | def mv(ui, repo, *args, **kwargs): |
|
674 | def mv(ui, repo, *args, **kwargs): | |
673 | cmdoptions = [ |
|
675 | cmdoptions = [ | |
674 | ('f', 'force', None, ''), |
|
676 | ('f', 'force', None, ''), | |
675 | ] |
|
677 | ] | |
676 | args, opts = parseoptions(ui, cmdoptions, args) |
|
678 | args, opts = parseoptions(ui, cmdoptions, args) | |
677 |
|
679 | |||
678 | cmd = Command('mv') |
|
680 | cmd = Command('mv') | |
679 | cmd.extend(args) |
|
681 | cmd.extend(args) | |
680 |
|
682 | |||
681 | if opts.get('force'): |
|
683 | if opts.get('force'): | |
682 | cmd['-f'] = None |
|
684 | cmd['-f'] = None | |
683 |
|
685 | |||
684 | ui.status((bytes(cmd)), "\n") |
|
686 | ui.status((bytes(cmd)), "\n") | |
685 |
|
687 | |||
686 | def pull(ui, repo, *args, **kwargs): |
|
688 | def pull(ui, repo, *args, **kwargs): | |
687 | cmdoptions = [ |
|
689 | cmdoptions = [ | |
688 | ('', 'all', None, ''), |
|
690 | ('', 'all', None, ''), | |
689 | ('f', 'force', None, ''), |
|
691 | ('f', 'force', None, ''), | |
690 | ('r', 'rebase', None, ''), |
|
692 | ('r', 'rebase', None, ''), | |
691 | ] |
|
693 | ] | |
692 | args, opts = parseoptions(ui, cmdoptions, args) |
|
694 | args, opts = parseoptions(ui, cmdoptions, args) | |
693 |
|
695 | |||
694 | cmd = Command('pull') |
|
696 | cmd = Command('pull') | |
695 | cmd['--rebase'] = None |
|
697 | cmd['--rebase'] = None | |
696 |
|
698 | |||
697 | if len(args) > 0: |
|
699 | if len(args) > 0: | |
698 | cmd.append(args[0]) |
|
700 | cmd.append(args[0]) | |
699 | if len(args) > 1: |
|
701 | if len(args) > 1: | |
700 | ui.status(_("note: Mercurial doesn't have refspecs. " + |
|
702 | ui.status(_("note: Mercurial doesn't have refspecs. " + | |
701 | "-r can be used to specify which commits you want to pull. " + |
|
703 | "-r can be used to specify which commits you want to pull. " + | |
702 | "-B can be used to specify which bookmark you want to pull." + |
|
704 | "-B can be used to specify which bookmark you want to pull." + | |
703 | "\n\n")) |
|
705 | "\n\n")) | |
704 | for v in args[1:]: |
|
706 | for v in args[1:]: | |
705 | if v in repo._bookmarks: |
|
707 | if v in repo._bookmarks: | |
706 | cmd['-B'] = v |
|
708 | cmd['-B'] = v | |
707 | else: |
|
709 | else: | |
708 | cmd['-r'] = v |
|
710 | cmd['-r'] = v | |
709 |
|
711 | |||
710 | ui.status((bytes(cmd)), "\n") |
|
712 | ui.status((bytes(cmd)), "\n") | |
711 |
|
713 | |||
712 | def push(ui, repo, *args, **kwargs): |
|
714 | def push(ui, repo, *args, **kwargs): | |
713 | cmdoptions = [ |
|
715 | cmdoptions = [ | |
714 | ('', 'all', None, ''), |
|
716 | ('', 'all', None, ''), | |
715 | ('f', 'force', None, ''), |
|
717 | ('f', 'force', None, ''), | |
716 | ] |
|
718 | ] | |
717 | args, opts = parseoptions(ui, cmdoptions, args) |
|
719 | args, opts = parseoptions(ui, cmdoptions, args) | |
718 |
|
720 | |||
719 | cmd = Command('push') |
|
721 | cmd = Command('push') | |
720 |
|
722 | |||
721 | if len(args) > 0: |
|
723 | if len(args) > 0: | |
722 | cmd.append(args[0]) |
|
724 | cmd.append(args[0]) | |
723 | if len(args) > 1: |
|
725 | if len(args) > 1: | |
724 | ui.status(_("note: Mercurial doesn't have refspecs. " + |
|
726 | ui.status(_("note: Mercurial doesn't have refspecs. " + | |
725 | "-r can be used to specify which commits you want to push. " + |
|
727 | "-r can be used to specify which commits you want to push. " + | |
726 | "-B can be used to specify which bookmark you want to push." + |
|
728 | "-B can be used to specify which bookmark you want to push." + | |
727 | "\n\n")) |
|
729 | "\n\n")) | |
728 | for v in args[1:]: |
|
730 | for v in args[1:]: | |
729 | if v in repo._bookmarks: |
|
731 | if v in repo._bookmarks: | |
730 | cmd['-B'] = v |
|
732 | cmd['-B'] = v | |
731 | else: |
|
733 | else: | |
732 | cmd['-r'] = v |
|
734 | cmd['-r'] = v | |
733 |
|
735 | |||
734 | if opts.get('force'): |
|
736 | if opts.get('force'): | |
735 | cmd['-f'] = None |
|
737 | cmd['-f'] = None | |
736 |
|
738 | |||
737 | ui.status((bytes(cmd)), "\n") |
|
739 | ui.status((bytes(cmd)), "\n") | |
738 |
|
740 | |||
739 | def rebase(ui, repo, *args, **kwargs): |
|
741 | def rebase(ui, repo, *args, **kwargs): | |
740 | cmdoptions = [ |
|
742 | cmdoptions = [ | |
741 | ('', 'all', None, ''), |
|
743 | ('', 'all', None, ''), | |
742 | ('i', 'interactive', None, ''), |
|
744 | ('i', 'interactive', None, ''), | |
743 | ('', 'onto', '', ''), |
|
745 | ('', 'onto', '', ''), | |
744 | ('', 'abort', None, ''), |
|
746 | ('', 'abort', None, ''), | |
745 | ('', 'continue', None, ''), |
|
747 | ('', 'continue', None, ''), | |
746 | ('', 'skip', None, ''), |
|
748 | ('', 'skip', None, ''), | |
747 | ] |
|
749 | ] | |
748 | args, opts = parseoptions(ui, cmdoptions, args) |
|
750 | args, opts = parseoptions(ui, cmdoptions, args) | |
749 |
|
751 | |||
750 | if opts.get('interactive'): |
|
752 | if opts.get('interactive'): | |
751 | ui.status(_("note: hg histedit does not perform a rebase. " + |
|
753 | ui.status(_("note: hg histedit does not perform a rebase. " + | |
752 | "It just edits history.\n\n")) |
|
754 | "It just edits history.\n\n")) | |
753 | cmd = Command('histedit') |
|
755 | cmd = Command('histedit') | |
754 | if len(args) > 0: |
|
756 | if len(args) > 0: | |
755 | ui.status(_("also note: 'hg histedit' will automatically detect" |
|
757 | ui.status(_("also note: 'hg histedit' will automatically detect" | |
756 | " your stack, so no second argument is necessary.\n\n")) |
|
758 | " your stack, so no second argument is necessary.\n\n")) | |
757 | ui.status((bytes(cmd)), "\n") |
|
759 | ui.status((bytes(cmd)), "\n") | |
758 | return |
|
760 | return | |
759 |
|
761 | |||
760 | if opts.get('skip'): |
|
762 | if opts.get('skip'): | |
761 | cmd = Command('revert --all -r .') |
|
763 | cmd = Command('revert --all -r .') | |
762 | ui.status((bytes(cmd)), "\n") |
|
764 | ui.status((bytes(cmd)), "\n") | |
763 |
|
765 | |||
764 | cmd = Command('rebase') |
|
766 | cmd = Command('rebase') | |
765 |
|
767 | |||
766 | if opts.get('continue') or opts.get('skip'): |
|
768 | if opts.get('continue') or opts.get('skip'): | |
767 | cmd['--continue'] = None |
|
769 | cmd['--continue'] = None | |
768 | if opts.get('abort'): |
|
770 | if opts.get('abort'): | |
769 | cmd['--abort'] = None |
|
771 | cmd['--abort'] = None | |
770 |
|
772 | |||
771 | if opts.get('onto'): |
|
773 | if opts.get('onto'): | |
772 | 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, " + | |
773 | "try hg rebase -d <destination commit> -s <commit to be lifted>" + |
|
775 | "try hg rebase -d <destination commit> -s <commit to be lifted>" + | |
774 | "\n\n")) |
|
776 | "\n\n")) | |
775 | cmd['-d'] = convert(opts.get('onto')) |
|
777 | cmd['-d'] = convert(opts.get('onto')) | |
776 | if len(args) < 2: |
|
778 | if len(args) < 2: | |
777 | raise error.Abort("Expected format: git rebase --onto X Y Z") |
|
779 | raise error.Abort("Expected format: git rebase --onto X Y Z") | |
778 | cmd['-s'] = "'::%s - ::%s'" % (convert(args[1]), convert(args[0])) |
|
780 | cmd['-s'] = "'::%s - ::%s'" % (convert(args[1]), convert(args[0])) | |
779 | else: |
|
781 | else: | |
780 | if len(args) == 1: |
|
782 | if len(args) == 1: | |
781 | cmd['-d'] = convert(args[0]) |
|
783 | cmd['-d'] = convert(args[0]) | |
782 | elif len(args) == 2: |
|
784 | elif len(args) == 2: | |
783 | cmd['-d'] = convert(args[0]) |
|
785 | cmd['-d'] = convert(args[0]) | |
784 | cmd['-b'] = convert(args[1]) |
|
786 | cmd['-b'] = convert(args[1]) | |
785 |
|
787 | |||
786 | ui.status((bytes(cmd)), "\n") |
|
788 | ui.status((bytes(cmd)), "\n") | |
787 |
|
789 | |||
788 | def reflog(ui, repo, *args, **kwargs): |
|
790 | def reflog(ui, repo, *args, **kwargs): | |
789 | cmdoptions = [ |
|
791 | cmdoptions = [ | |
790 | ('', 'all', None, ''), |
|
792 | ('', 'all', None, ''), | |
791 | ] |
|
793 | ] | |
792 | args, opts = parseoptions(ui, cmdoptions, args) |
|
794 | args, opts = parseoptions(ui, cmdoptions, args) | |
793 |
|
795 | |||
794 | cmd = Command('journal') |
|
796 | cmd = Command('journal') | |
795 | if opts.get('all'): |
|
797 | if opts.get('all'): | |
796 | cmd['--all'] = None |
|
798 | cmd['--all'] = None | |
797 | if len(args) > 0: |
|
799 | if len(args) > 0: | |
798 | cmd.append(args[0]) |
|
800 | cmd.append(args[0]) | |
799 |
|
801 | |||
800 | ui.status(bytes(cmd), "\n\n") |
|
802 | ui.status(bytes(cmd), "\n\n") | |
801 | 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" | |
802 | " have backups.\n")) |
|
804 | " have backups.\n")) | |
803 |
|
805 | |||
804 | def reset(ui, repo, *args, **kwargs): |
|
806 | def reset(ui, repo, *args, **kwargs): | |
805 | cmdoptions = [ |
|
807 | cmdoptions = [ | |
806 | ('', 'soft', None, ''), |
|
808 | ('', 'soft', None, ''), | |
807 | ('', 'hard', None, ''), |
|
809 | ('', 'hard', None, ''), | |
808 | ('', 'mixed', None, ''), |
|
810 | ('', 'mixed', None, ''), | |
809 | ] |
|
811 | ] | |
810 | args, opts = parseoptions(ui, cmdoptions, args) |
|
812 | args, opts = parseoptions(ui, cmdoptions, args) | |
811 |
|
813 | |||
812 | commit = convert(args[0] if len(args) > 0 else '.') |
|
814 | commit = convert(args[0] if len(args) > 0 else '.') | |
813 | hard = opts.get('hard') |
|
815 | hard = opts.get('hard') | |
814 |
|
816 | |||
815 | if opts.get('mixed'): |
|
817 | if opts.get('mixed'): | |
816 | ui.status(_('NOTE: --mixed has no meaning since Mercurial has no ' |
|
818 | ui.status(_('NOTE: --mixed has no meaning since Mercurial has no ' | |
817 | 'staging area\n\n')) |
|
819 | 'staging area\n\n')) | |
818 | if opts.get('soft'): |
|
820 | if opts.get('soft'): | |
819 | ui.status(_('NOTE: --soft has no meaning since Mercurial has no ' |
|
821 | ui.status(_('NOTE: --soft has no meaning since Mercurial has no ' | |
820 | 'staging area\n\n')) |
|
822 | 'staging area\n\n')) | |
821 |
|
823 | |||
822 | cmd = Command('update') |
|
824 | cmd = Command('update') | |
823 | if hard: |
|
825 | if hard: | |
824 | cmd.append('--clean') |
|
826 | cmd.append('--clean') | |
825 |
|
827 | |||
826 | cmd.append(commit) |
|
828 | cmd.append(commit) | |
827 |
|
829 | |||
828 | ui.status((bytes(cmd)), "\n") |
|
830 | ui.status((bytes(cmd)), "\n") | |
829 |
|
831 | |||
830 | def revert(ui, repo, *args, **kwargs): |
|
832 | def revert(ui, repo, *args, **kwargs): | |
831 | cmdoptions = [ |
|
833 | cmdoptions = [ | |
832 | ] |
|
834 | ] | |
833 | args, opts = parseoptions(ui, cmdoptions, args) |
|
835 | args, opts = parseoptions(ui, cmdoptions, args) | |
834 |
|
836 | |||
835 | if len(args) > 1: |
|
837 | if len(args) > 1: | |
836 | ui.status(_("note: hg backout doesn't support multiple commits at " + |
|
838 | ui.status(_("note: hg backout doesn't support multiple commits at " + | |
837 | "once\n\n")) |
|
839 | "once\n\n")) | |
838 |
|
840 | |||
839 | cmd = Command('backout') |
|
841 | cmd = Command('backout') | |
840 | if args: |
|
842 | if args: | |
841 | cmd.append(args[0]) |
|
843 | cmd.append(args[0]) | |
842 |
|
844 | |||
843 | ui.status((bytes(cmd)), "\n") |
|
845 | ui.status((bytes(cmd)), "\n") | |
844 |
|
846 | |||
845 | def revparse(ui, repo, *args, **kwargs): |
|
847 | def revparse(ui, repo, *args, **kwargs): | |
846 | cmdoptions = [ |
|
848 | cmdoptions = [ | |
847 | ('', 'show-cdup', None, ''), |
|
849 | ('', 'show-cdup', None, ''), | |
848 | ('', 'show-toplevel', None, ''), |
|
850 | ('', 'show-toplevel', None, ''), | |
849 | ] |
|
851 | ] | |
850 | args, opts = parseoptions(ui, cmdoptions, args) |
|
852 | args, opts = parseoptions(ui, cmdoptions, args) | |
851 |
|
853 | |||
852 | if opts.get('show_cdup') or opts.get('show_toplevel'): |
|
854 | if opts.get('show_cdup') or opts.get('show_toplevel'): | |
853 | cmd = Command('root') |
|
855 | cmd = Command('root') | |
854 | if opts.get('show_cdup'): |
|
856 | if opts.get('show_cdup'): | |
855 | 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")) | |
856 | ui.status((bytes(cmd)), "\n") |
|
858 | ui.status((bytes(cmd)), "\n") | |
857 | else: |
|
859 | else: | |
858 | 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")) | |
859 |
|
861 | |||
860 | def rm(ui, repo, *args, **kwargs): |
|
862 | def rm(ui, repo, *args, **kwargs): | |
861 | cmdoptions = [ |
|
863 | cmdoptions = [ | |
862 | ('f', 'force', None, ''), |
|
864 | ('f', 'force', None, ''), | |
863 | ('n', 'dry-run', None, ''), |
|
865 | ('n', 'dry-run', None, ''), | |
864 | ] |
|
866 | ] | |
865 | args, opts = parseoptions(ui, cmdoptions, args) |
|
867 | args, opts = parseoptions(ui, cmdoptions, args) | |
866 |
|
868 | |||
867 | cmd = Command('rm') |
|
869 | cmd = Command('rm') | |
868 | cmd.extend(args) |
|
870 | cmd.extend(args) | |
869 |
|
871 | |||
870 | if opts.get('force'): |
|
872 | if opts.get('force'): | |
871 | cmd['-f'] = None |
|
873 | cmd['-f'] = None | |
872 | if opts.get('dry_run'): |
|
874 | if opts.get('dry_run'): | |
873 | cmd['-n'] = None |
|
875 | cmd['-n'] = None | |
874 |
|
876 | |||
875 | ui.status((bytes(cmd)), "\n") |
|
877 | ui.status((bytes(cmd)), "\n") | |
876 |
|
878 | |||
877 | def show(ui, repo, *args, **kwargs): |
|
879 | def show(ui, repo, *args, **kwargs): | |
878 | cmdoptions = [ |
|
880 | cmdoptions = [ | |
879 | ('', 'name-status', None, ''), |
|
881 | ('', 'name-status', None, ''), | |
880 | ('', 'pretty', '', ''), |
|
882 | ('', 'pretty', '', ''), | |
881 | ('U', 'unified', int, ''), |
|
883 | ('U', 'unified', int, ''), | |
882 | ] |
|
884 | ] | |
883 | args, opts = parseoptions(ui, cmdoptions, args) |
|
885 | args, opts = parseoptions(ui, cmdoptions, args) | |
884 |
|
886 | |||
885 | if opts.get('name_status'): |
|
887 | if opts.get('name_status'): | |
886 | if opts.get('pretty') == 'format:': |
|
888 | if opts.get('pretty') == 'format:': | |
887 | cmd = Command('status') |
|
889 | cmd = Command('status') | |
888 | cmd['--change'] = '.' |
|
890 | cmd['--change'] = '.' | |
889 | else: |
|
891 | else: | |
890 | cmd = Command('log') |
|
892 | cmd = Command('log') | |
891 | cmd.append('--style status') |
|
893 | cmd.append('--style status') | |
892 | cmd.append('-r .') |
|
894 | cmd.append('-r .') | |
893 | elif len(args) > 0: |
|
895 | elif len(args) > 0: | |
894 | if ispath(repo, args[0]): |
|
896 | if ispath(repo, args[0]): | |
895 | cmd = Command('cat') |
|
897 | cmd = Command('cat') | |
896 | else: |
|
898 | else: | |
897 | cmd = Command('export') |
|
899 | cmd = Command('export') | |
898 | cmd.extend(args) |
|
900 | cmd.extend(args) | |
899 | if opts.get('unified'): |
|
901 | if opts.get('unified'): | |
900 | cmd.append('--config diff.unified=%d' % (opts['unified'],)) |
|
902 | cmd.append('--config diff.unified=%d' % (opts['unified'],)) | |
901 | elif opts.get('unified'): |
|
903 | elif opts.get('unified'): | |
902 | cmd = Command('export') |
|
904 | cmd = Command('export') | |
903 | cmd.append('--config diff.unified=%d' % (opts['unified'],)) |
|
905 | cmd.append('--config diff.unified=%d' % (opts['unified'],)) | |
904 | else: |
|
906 | else: | |
905 | cmd = Command('export') |
|
907 | cmd = Command('export') | |
906 |
|
908 | |||
907 | ui.status((bytes(cmd)), "\n") |
|
909 | ui.status((bytes(cmd)), "\n") | |
908 |
|
910 | |||
909 | def stash(ui, repo, *args, **kwargs): |
|
911 | def stash(ui, repo, *args, **kwargs): | |
910 | cmdoptions = [ |
|
912 | cmdoptions = [ | |
911 | ] |
|
913 | ] | |
912 | args, opts = parseoptions(ui, cmdoptions, args) |
|
914 | args, opts = parseoptions(ui, cmdoptions, args) | |
913 |
|
915 | |||
914 | cmd = Command('shelve') |
|
916 | cmd = Command('shelve') | |
915 | action = args[0] if len(args) > 0 else None |
|
917 | action = args[0] if len(args) > 0 else None | |
916 |
|
918 | |||
917 | if action == 'list': |
|
919 | if action == 'list': | |
918 | cmd['-l'] = None |
|
920 | cmd['-l'] = None | |
919 | elif action == 'drop': |
|
921 | elif action == 'drop': | |
920 | cmd['-d'] = None |
|
922 | cmd['-d'] = None | |
921 | if len(args) > 1: |
|
923 | if len(args) > 1: | |
922 | cmd.append(args[1]) |
|
924 | cmd.append(args[1]) | |
923 | else: |
|
925 | else: | |
924 | cmd.append('<shelve name>') |
|
926 | cmd.append('<shelve name>') | |
925 | elif action == 'pop' or action == 'apply': |
|
927 | elif action == 'pop' or action == 'apply': | |
926 | cmd = Command('unshelve') |
|
928 | cmd = Command('unshelve') | |
927 | if len(args) > 1: |
|
929 | if len(args) > 1: | |
928 | cmd.append(args[1]) |
|
930 | cmd.append(args[1]) | |
929 | if action == 'apply': |
|
931 | if action == 'apply': | |
930 | cmd['--keep'] = None |
|
932 | cmd['--keep'] = None | |
931 | elif (action == 'branch' or action == 'show' or action == 'clear' |
|
933 | elif (action == 'branch' or action == 'show' or action == 'clear' | |
932 | or action == 'create'): |
|
934 | or action == 'create'): | |
933 | ui.status(_("note: Mercurial doesn't have equivalents to the " + |
|
935 | ui.status(_("note: Mercurial doesn't have equivalents to the " + | |
934 | "git stash branch, show, clear, or create actions.\n\n")) |
|
936 | "git stash branch, show, clear, or create actions.\n\n")) | |
935 | return |
|
937 | return | |
936 | else: |
|
938 | else: | |
937 | if len(args) > 0: |
|
939 | if len(args) > 0: | |
938 | if args[0] != 'save': |
|
940 | if args[0] != 'save': | |
939 | cmd['--name'] = args[0] |
|
941 | cmd['--name'] = args[0] | |
940 | elif len(args) > 1: |
|
942 | elif len(args) > 1: | |
941 | cmd['--name'] = args[1] |
|
943 | cmd['--name'] = args[1] | |
942 |
|
944 | |||
943 | ui.status((bytes(cmd)), "\n") |
|
945 | ui.status((bytes(cmd)), "\n") | |
944 |
|
946 | |||
945 | def status(ui, repo, *args, **kwargs): |
|
947 | def status(ui, repo, *args, **kwargs): | |
946 | cmdoptions = [ |
|
948 | cmdoptions = [ | |
947 | ('', 'ignored', None, ''), |
|
949 | ('', 'ignored', None, ''), | |
948 | ] |
|
950 | ] | |
949 | args, opts = parseoptions(ui, cmdoptions, args) |
|
951 | args, opts = parseoptions(ui, cmdoptions, args) | |
950 |
|
952 | |||
951 | cmd = Command('status') |
|
953 | cmd = Command('status') | |
952 | cmd.extend(args) |
|
954 | cmd.extend(args) | |
953 |
|
955 | |||
954 | if opts.get('ignored'): |
|
956 | if opts.get('ignored'): | |
955 | cmd['-i'] = None |
|
957 | cmd['-i'] = None | |
956 |
|
958 | |||
957 | ui.status((bytes(cmd)), "\n") |
|
959 | ui.status((bytes(cmd)), "\n") | |
958 |
|
960 | |||
959 | def svn(ui, repo, *args, **kwargs): |
|
961 | def svn(ui, repo, *args, **kwargs): | |
|
962 | if not args: | |||
|
963 | raise error.Abort(_('missing svn command')) | |||
960 | svncmd = args[0] |
|
964 | svncmd = args[0] | |
961 | if not svncmd in gitsvncommands: |
|
965 | if not svncmd in gitsvncommands: | |
962 | ui.warn(_("error: unknown git svn command %s\n") % (svncmd)) |
|
966 | ui.warn(_("error: unknown git svn command %s\n") % (svncmd)) | |
963 |
|
967 | |||
964 | args = args[1:] |
|
968 | args = args[1:] | |
965 | return gitsvncommands[svncmd](ui, repo, *args, **kwargs) |
|
969 | return gitsvncommands[svncmd](ui, repo, *args, **kwargs) | |
966 |
|
970 | |||
967 | def svndcommit(ui, repo, *args, **kwargs): |
|
971 | def svndcommit(ui, repo, *args, **kwargs): | |
968 | cmdoptions = [ |
|
972 | cmdoptions = [ | |
969 | ] |
|
973 | ] | |
970 | args, opts = parseoptions(ui, cmdoptions, args) |
|
974 | args, opts = parseoptions(ui, cmdoptions, args) | |
971 |
|
975 | |||
972 | cmd = Command('push') |
|
976 | cmd = Command('push') | |
973 |
|
977 | |||
974 | ui.status((bytes(cmd)), "\n") |
|
978 | ui.status((bytes(cmd)), "\n") | |
975 |
|
979 | |||
976 | def svnfetch(ui, repo, *args, **kwargs): |
|
980 | def svnfetch(ui, repo, *args, **kwargs): | |
977 | cmdoptions = [ |
|
981 | cmdoptions = [ | |
978 | ] |
|
982 | ] | |
979 | args, opts = parseoptions(ui, cmdoptions, args) |
|
983 | args, opts = parseoptions(ui, cmdoptions, args) | |
980 |
|
984 | |||
981 | cmd = Command('pull') |
|
985 | cmd = Command('pull') | |
982 | cmd.append('default-push') |
|
986 | cmd.append('default-push') | |
983 |
|
987 | |||
984 | ui.status((bytes(cmd)), "\n") |
|
988 | ui.status((bytes(cmd)), "\n") | |
985 |
|
989 | |||
986 | def svnfindrev(ui, repo, *args, **kwargs): |
|
990 | def svnfindrev(ui, repo, *args, **kwargs): | |
987 | cmdoptions = [ |
|
991 | cmdoptions = [ | |
988 | ] |
|
992 | ] | |
989 | args, opts = parseoptions(ui, cmdoptions, args) |
|
993 | args, opts = parseoptions(ui, cmdoptions, args) | |
990 |
|
994 | |||
|
995 | if not args: | |||
|
996 | raise error.Abort(_('missing find-rev argument')) | |||
|
997 | ||||
991 | cmd = Command('log') |
|
998 | cmd = Command('log') | |
992 | cmd['-r'] = args[0] |
|
999 | cmd['-r'] = args[0] | |
993 |
|
1000 | |||
994 | ui.status((bytes(cmd)), "\n") |
|
1001 | ui.status((bytes(cmd)), "\n") | |
995 |
|
1002 | |||
996 | def svnrebase(ui, repo, *args, **kwargs): |
|
1003 | def svnrebase(ui, repo, *args, **kwargs): | |
997 | cmdoptions = [ |
|
1004 | cmdoptions = [ | |
998 | ('l', 'local', None, ''), |
|
1005 | ('l', 'local', None, ''), | |
999 | ] |
|
1006 | ] | |
1000 | args, opts = parseoptions(ui, cmdoptions, args) |
|
1007 | args, opts = parseoptions(ui, cmdoptions, args) | |
1001 |
|
1008 | |||
1002 | pullcmd = Command('pull') |
|
1009 | pullcmd = Command('pull') | |
1003 | pullcmd.append('default-push') |
|
1010 | pullcmd.append('default-push') | |
1004 | rebasecmd = Command('rebase') |
|
1011 | rebasecmd = Command('rebase') | |
1005 | rebasecmd.append('tip') |
|
1012 | rebasecmd.append('tip') | |
1006 |
|
1013 | |||
1007 | cmd = pullcmd & rebasecmd |
|
1014 | cmd = pullcmd & rebasecmd | |
1008 |
|
1015 | |||
1009 | ui.status((bytes(cmd)), "\n") |
|
1016 | ui.status((bytes(cmd)), "\n") | |
1010 |
|
1017 | |||
1011 | def tag(ui, repo, *args, **kwargs): |
|
1018 | def tag(ui, repo, *args, **kwargs): | |
1012 | cmdoptions = [ |
|
1019 | cmdoptions = [ | |
1013 | ('f', 'force', None, ''), |
|
1020 | ('f', 'force', None, ''), | |
1014 | ('l', 'list', None, ''), |
|
1021 | ('l', 'list', None, ''), | |
1015 | ('d', 'delete', None, ''), |
|
1022 | ('d', 'delete', None, ''), | |
1016 | ] |
|
1023 | ] | |
1017 | args, opts = parseoptions(ui, cmdoptions, args) |
|
1024 | args, opts = parseoptions(ui, cmdoptions, args) | |
1018 |
|
1025 | |||
1019 | if opts.get('list'): |
|
1026 | if opts.get('list'): | |
1020 | cmd = Command('tags') |
|
1027 | cmd = Command('tags') | |
1021 | else: |
|
1028 | else: | |
1022 | cmd = Command('tag') |
|
1029 | cmd = Command('tag') | |
|
1030 | ||||
|
1031 | if not args: | |||
|
1032 | raise error.Abort(_('missing tag argument')) | |||
|
1033 | ||||
1023 | cmd.append(args[0]) |
|
1034 | cmd.append(args[0]) | |
1024 | if len(args) > 1: |
|
1035 | if len(args) > 1: | |
1025 | cmd['-r'] = args[1] |
|
1036 | cmd['-r'] = args[1] | |
1026 |
|
1037 | |||
1027 | if opts.get('delete'): |
|
1038 | if opts.get('delete'): | |
1028 | cmd['--remove'] = None |
|
1039 | cmd['--remove'] = None | |
1029 |
|
1040 | |||
1030 | if opts.get('force'): |
|
1041 | if opts.get('force'): | |
1031 | cmd['-f'] = None |
|
1042 | cmd['-f'] = None | |
1032 |
|
1043 | |||
1033 | ui.status((bytes(cmd)), "\n") |
|
1044 | ui.status((bytes(cmd)), "\n") | |
1034 |
|
1045 | |||
1035 | gitcommands = { |
|
1046 | gitcommands = { | |
1036 | 'add': add, |
|
1047 | 'add': add, | |
1037 | 'am': am, |
|
1048 | 'am': am, | |
1038 | 'apply': apply, |
|
1049 | 'apply': apply, | |
1039 | 'bisect': bisect, |
|
1050 | 'bisect': bisect, | |
1040 | 'blame': blame, |
|
1051 | 'blame': blame, | |
1041 | 'branch': branch, |
|
1052 | 'branch': branch, | |
1042 | 'checkout': checkout, |
|
1053 | 'checkout': checkout, | |
1043 | 'cherry-pick': cherrypick, |
|
1054 | 'cherry-pick': cherrypick, | |
1044 | 'clean': clean, |
|
1055 | 'clean': clean, | |
1045 | 'clone': clone, |
|
1056 | 'clone': clone, | |
1046 | 'commit': commit, |
|
1057 | 'commit': commit, | |
1047 | 'diff': diff, |
|
1058 | 'diff': diff, | |
1048 | 'difftool': difftool, |
|
1059 | 'difftool': difftool, | |
1049 | 'fetch': fetch, |
|
1060 | 'fetch': fetch, | |
1050 | 'grep': grep, |
|
1061 | 'grep': grep, | |
1051 | 'init': init, |
|
1062 | 'init': init, | |
1052 | 'log': log, |
|
1063 | 'log': log, | |
1053 | 'ls-files': lsfiles, |
|
1064 | 'ls-files': lsfiles, | |
1054 | 'merge': merge, |
|
1065 | 'merge': merge, | |
1055 | 'merge-base': mergebase, |
|
1066 | 'merge-base': mergebase, | |
1056 | 'mergetool': mergetool, |
|
1067 | 'mergetool': mergetool, | |
1057 | 'mv': mv, |
|
1068 | 'mv': mv, | |
1058 | 'pull': pull, |
|
1069 | 'pull': pull, | |
1059 | 'push': push, |
|
1070 | 'push': push, | |
1060 | 'rebase': rebase, |
|
1071 | 'rebase': rebase, | |
1061 | 'reflog': reflog, |
|
1072 | 'reflog': reflog, | |
1062 | 'reset': reset, |
|
1073 | 'reset': reset, | |
1063 | 'revert': revert, |
|
1074 | 'revert': revert, | |
1064 | 'rev-parse': revparse, |
|
1075 | 'rev-parse': revparse, | |
1065 | 'rm': rm, |
|
1076 | 'rm': rm, | |
1066 | 'show': show, |
|
1077 | 'show': show, | |
1067 | 'stash': stash, |
|
1078 | 'stash': stash, | |
1068 | 'status': status, |
|
1079 | 'status': status, | |
1069 | 'svn': svn, |
|
1080 | 'svn': svn, | |
1070 | 'tag': tag, |
|
1081 | 'tag': tag, | |
1071 | 'whatchanged': deprecated, |
|
1082 | 'whatchanged': deprecated, | |
1072 | } |
|
1083 | } | |
1073 |
|
1084 | |||
1074 | gitsvncommands = { |
|
1085 | gitsvncommands = { | |
1075 | 'dcommit': svndcommit, |
|
1086 | 'dcommit': svndcommit, | |
1076 | 'fetch': svnfetch, |
|
1087 | 'fetch': svnfetch, | |
1077 | 'find-rev': svnfindrev, |
|
1088 | 'find-rev': svnfindrev, | |
1078 | 'rebase': svnrebase, |
|
1089 | 'rebase': svnrebase, | |
1079 | } |
|
1090 | } |
General Comments 0
You need to be logged in to leave comments.
Login now