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