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