##// END OF EJS Templates
templatekw: force noprefix=False to insure diffstat consistency (issue4755)...
Matthieu Laneuville -
r30811:cf1e15f9 default
parent child Browse files
Show More
@@ -1,607 +1,607 b''
1 # templatekw.py - common changeset template keywords
1 # templatekw.py - common changeset template keywords
2 #
2 #
3 # Copyright 2005-2009 Matt Mackall <mpm@selenic.com>
3 # Copyright 2005-2009 Matt Mackall <mpm@selenic.com>
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
7
8 from __future__ import absolute_import
8 from __future__ import absolute_import
9
9
10 from .node import hex, nullid
10 from .node import hex, nullid
11 from . import (
11 from . import (
12 encoding,
12 encoding,
13 error,
13 error,
14 hbisect,
14 hbisect,
15 patch,
15 patch,
16 registrar,
16 registrar,
17 scmutil,
17 scmutil,
18 util,
18 util,
19 )
19 )
20
20
21 # This helper class allows us to handle both:
21 # This helper class allows us to handle both:
22 # "{files}" (legacy command-line-specific list hack) and
22 # "{files}" (legacy command-line-specific list hack) and
23 # "{files % '{file}\n'}" (hgweb-style with inlining and function support)
23 # "{files % '{file}\n'}" (hgweb-style with inlining and function support)
24 # and to access raw values:
24 # and to access raw values:
25 # "{ifcontains(file, files, ...)}", "{ifcontains(key, extras, ...)}"
25 # "{ifcontains(file, files, ...)}", "{ifcontains(key, extras, ...)}"
26 # "{get(extras, key)}"
26 # "{get(extras, key)}"
27
27
28 class _hybrid(object):
28 class _hybrid(object):
29 def __init__(self, gen, values, makemap, joinfmt):
29 def __init__(self, gen, values, makemap, joinfmt):
30 self.gen = gen
30 self.gen = gen
31 self.values = values
31 self.values = values
32 self._makemap = makemap
32 self._makemap = makemap
33 self.joinfmt = joinfmt
33 self.joinfmt = joinfmt
34 def __iter__(self):
34 def __iter__(self):
35 return self.gen
35 return self.gen
36 def itermaps(self):
36 def itermaps(self):
37 makemap = self._makemap
37 makemap = self._makemap
38 for x in self.values:
38 for x in self.values:
39 yield makemap(x)
39 yield makemap(x)
40 def __contains__(self, x):
40 def __contains__(self, x):
41 return x in self.values
41 return x in self.values
42 def __len__(self):
42 def __len__(self):
43 return len(self.values)
43 return len(self.values)
44 def __getattr__(self, name):
44 def __getattr__(self, name):
45 if name != 'get':
45 if name != 'get':
46 raise AttributeError(name)
46 raise AttributeError(name)
47 return getattr(self.values, name)
47 return getattr(self.values, name)
48
48
49 def showlist(name, values, plural=None, element=None, separator=' ', **args):
49 def showlist(name, values, plural=None, element=None, separator=' ', **args):
50 if not element:
50 if not element:
51 element = name
51 element = name
52 f = _showlist(name, values, plural, separator, **args)
52 f = _showlist(name, values, plural, separator, **args)
53 return _hybrid(f, values, lambda x: {element: x}, lambda d: d[element])
53 return _hybrid(f, values, lambda x: {element: x}, lambda d: d[element])
54
54
55 def _showlist(name, values, plural=None, separator=' ', **args):
55 def _showlist(name, values, plural=None, separator=' ', **args):
56 '''expand set of values.
56 '''expand set of values.
57 name is name of key in template map.
57 name is name of key in template map.
58 values is list of strings or dicts.
58 values is list of strings or dicts.
59 plural is plural of name, if not simply name + 's'.
59 plural is plural of name, if not simply name + 's'.
60 separator is used to join values as a string
60 separator is used to join values as a string
61
61
62 expansion works like this, given name 'foo'.
62 expansion works like this, given name 'foo'.
63
63
64 if values is empty, expand 'no_foos'.
64 if values is empty, expand 'no_foos'.
65
65
66 if 'foo' not in template map, return values as a string,
66 if 'foo' not in template map, return values as a string,
67 joined by 'separator'.
67 joined by 'separator'.
68
68
69 expand 'start_foos'.
69 expand 'start_foos'.
70
70
71 for each value, expand 'foo'. if 'last_foo' in template
71 for each value, expand 'foo'. if 'last_foo' in template
72 map, expand it instead of 'foo' for last key.
72 map, expand it instead of 'foo' for last key.
73
73
74 expand 'end_foos'.
74 expand 'end_foos'.
75 '''
75 '''
76 templ = args['templ']
76 templ = args['templ']
77 if plural:
77 if plural:
78 names = plural
78 names = plural
79 else: names = name + 's'
79 else: names = name + 's'
80 if not values:
80 if not values:
81 noname = 'no_' + names
81 noname = 'no_' + names
82 if noname in templ:
82 if noname in templ:
83 yield templ(noname, **args)
83 yield templ(noname, **args)
84 return
84 return
85 if name not in templ:
85 if name not in templ:
86 if isinstance(values[0], str):
86 if isinstance(values[0], str):
87 yield separator.join(values)
87 yield separator.join(values)
88 else:
88 else:
89 for v in values:
89 for v in values:
90 yield dict(v, **args)
90 yield dict(v, **args)
91 return
91 return
92 startname = 'start_' + names
92 startname = 'start_' + names
93 if startname in templ:
93 if startname in templ:
94 yield templ(startname, **args)
94 yield templ(startname, **args)
95 vargs = args.copy()
95 vargs = args.copy()
96 def one(v, tag=name):
96 def one(v, tag=name):
97 try:
97 try:
98 vargs.update(v)
98 vargs.update(v)
99 except (AttributeError, ValueError):
99 except (AttributeError, ValueError):
100 try:
100 try:
101 for a, b in v:
101 for a, b in v:
102 vargs[a] = b
102 vargs[a] = b
103 except ValueError:
103 except ValueError:
104 vargs[name] = v
104 vargs[name] = v
105 return templ(tag, **vargs)
105 return templ(tag, **vargs)
106 lastname = 'last_' + name
106 lastname = 'last_' + name
107 if lastname in templ:
107 if lastname in templ:
108 last = values.pop()
108 last = values.pop()
109 else:
109 else:
110 last = None
110 last = None
111 for v in values:
111 for v in values:
112 yield one(v)
112 yield one(v)
113 if last is not None:
113 if last is not None:
114 yield one(last, tag=lastname)
114 yield one(last, tag=lastname)
115 endname = 'end_' + names
115 endname = 'end_' + names
116 if endname in templ:
116 if endname in templ:
117 yield templ(endname, **args)
117 yield templ(endname, **args)
118
118
119 def _formatrevnode(ctx):
119 def _formatrevnode(ctx):
120 """Format changeset as '{rev}:{node|formatnode}', which is the default
120 """Format changeset as '{rev}:{node|formatnode}', which is the default
121 template provided by cmdutil.changeset_templater"""
121 template provided by cmdutil.changeset_templater"""
122 repo = ctx.repo()
122 repo = ctx.repo()
123 if repo.ui.debugflag:
123 if repo.ui.debugflag:
124 hexnode = ctx.hex()
124 hexnode = ctx.hex()
125 else:
125 else:
126 hexnode = ctx.hex()[:12]
126 hexnode = ctx.hex()[:12]
127 return '%d:%s' % (scmutil.intrev(ctx.rev()), hexnode)
127 return '%d:%s' % (scmutil.intrev(ctx.rev()), hexnode)
128
128
129 def getfiles(repo, ctx, revcache):
129 def getfiles(repo, ctx, revcache):
130 if 'files' not in revcache:
130 if 'files' not in revcache:
131 revcache['files'] = repo.status(ctx.p1(), ctx)[:3]
131 revcache['files'] = repo.status(ctx.p1(), ctx)[:3]
132 return revcache['files']
132 return revcache['files']
133
133
134 def getlatesttags(repo, ctx, cache, pattern=None):
134 def getlatesttags(repo, ctx, cache, pattern=None):
135 '''return date, distance and name for the latest tag of rev'''
135 '''return date, distance and name for the latest tag of rev'''
136
136
137 cachename = 'latesttags'
137 cachename = 'latesttags'
138 if pattern is not None:
138 if pattern is not None:
139 cachename += '-' + pattern
139 cachename += '-' + pattern
140 match = util.stringmatcher(pattern)[2]
140 match = util.stringmatcher(pattern)[2]
141 else:
141 else:
142 match = util.always
142 match = util.always
143
143
144 if cachename not in cache:
144 if cachename not in cache:
145 # Cache mapping from rev to a tuple with tag date, tag
145 # Cache mapping from rev to a tuple with tag date, tag
146 # distance and tag name
146 # distance and tag name
147 cache[cachename] = {-1: (0, 0, ['null'])}
147 cache[cachename] = {-1: (0, 0, ['null'])}
148 latesttags = cache[cachename]
148 latesttags = cache[cachename]
149
149
150 rev = ctx.rev()
150 rev = ctx.rev()
151 todo = [rev]
151 todo = [rev]
152 while todo:
152 while todo:
153 rev = todo.pop()
153 rev = todo.pop()
154 if rev in latesttags:
154 if rev in latesttags:
155 continue
155 continue
156 ctx = repo[rev]
156 ctx = repo[rev]
157 tags = [t for t in ctx.tags()
157 tags = [t for t in ctx.tags()
158 if (repo.tagtype(t) and repo.tagtype(t) != 'local'
158 if (repo.tagtype(t) and repo.tagtype(t) != 'local'
159 and match(t))]
159 and match(t))]
160 if tags:
160 if tags:
161 latesttags[rev] = ctx.date()[0], 0, [t for t in sorted(tags)]
161 latesttags[rev] = ctx.date()[0], 0, [t for t in sorted(tags)]
162 continue
162 continue
163 try:
163 try:
164 # The tuples are laid out so the right one can be found by
164 # The tuples are laid out so the right one can be found by
165 # comparison.
165 # comparison.
166 pdate, pdist, ptag = max(
166 pdate, pdist, ptag = max(
167 latesttags[p.rev()] for p in ctx.parents())
167 latesttags[p.rev()] for p in ctx.parents())
168 except KeyError:
168 except KeyError:
169 # Cache miss - recurse
169 # Cache miss - recurse
170 todo.append(rev)
170 todo.append(rev)
171 todo.extend(p.rev() for p in ctx.parents())
171 todo.extend(p.rev() for p in ctx.parents())
172 continue
172 continue
173 latesttags[rev] = pdate, pdist + 1, ptag
173 latesttags[rev] = pdate, pdist + 1, ptag
174 return latesttags[rev]
174 return latesttags[rev]
175
175
176 def getrenamedfn(repo, endrev=None):
176 def getrenamedfn(repo, endrev=None):
177 rcache = {}
177 rcache = {}
178 if endrev is None:
178 if endrev is None:
179 endrev = len(repo)
179 endrev = len(repo)
180
180
181 def getrenamed(fn, rev):
181 def getrenamed(fn, rev):
182 '''looks up all renames for a file (up to endrev) the first
182 '''looks up all renames for a file (up to endrev) the first
183 time the file is given. It indexes on the changerev and only
183 time the file is given. It indexes on the changerev and only
184 parses the manifest if linkrev != changerev.
184 parses the manifest if linkrev != changerev.
185 Returns rename info for fn at changerev rev.'''
185 Returns rename info for fn at changerev rev.'''
186 if fn not in rcache:
186 if fn not in rcache:
187 rcache[fn] = {}
187 rcache[fn] = {}
188 fl = repo.file(fn)
188 fl = repo.file(fn)
189 for i in fl:
189 for i in fl:
190 lr = fl.linkrev(i)
190 lr = fl.linkrev(i)
191 renamed = fl.renamed(fl.node(i))
191 renamed = fl.renamed(fl.node(i))
192 rcache[fn][lr] = renamed
192 rcache[fn][lr] = renamed
193 if lr >= endrev:
193 if lr >= endrev:
194 break
194 break
195 if rev in rcache[fn]:
195 if rev in rcache[fn]:
196 return rcache[fn][rev]
196 return rcache[fn][rev]
197
197
198 # If linkrev != rev (i.e. rev not found in rcache) fallback to
198 # If linkrev != rev (i.e. rev not found in rcache) fallback to
199 # filectx logic.
199 # filectx logic.
200 try:
200 try:
201 return repo[rev][fn].renamed()
201 return repo[rev][fn].renamed()
202 except error.LookupError:
202 except error.LookupError:
203 return None
203 return None
204
204
205 return getrenamed
205 return getrenamed
206
206
207 # keywords are callables like:
207 # keywords are callables like:
208 # fn(repo, ctx, templ, cache, revcache, **args)
208 # fn(repo, ctx, templ, cache, revcache, **args)
209 # with:
209 # with:
210 # repo - current repository instance
210 # repo - current repository instance
211 # ctx - the changectx being displayed
211 # ctx - the changectx being displayed
212 # templ - the templater instance
212 # templ - the templater instance
213 # cache - a cache dictionary for the whole templater run
213 # cache - a cache dictionary for the whole templater run
214 # revcache - a cache dictionary for the current revision
214 # revcache - a cache dictionary for the current revision
215 keywords = {}
215 keywords = {}
216
216
217 templatekeyword = registrar.templatekeyword(keywords)
217 templatekeyword = registrar.templatekeyword(keywords)
218
218
219 @templatekeyword('author')
219 @templatekeyword('author')
220 def showauthor(repo, ctx, templ, **args):
220 def showauthor(repo, ctx, templ, **args):
221 """String. The unmodified author of the changeset."""
221 """String. The unmodified author of the changeset."""
222 return ctx.user()
222 return ctx.user()
223
223
224 @templatekeyword('bisect')
224 @templatekeyword('bisect')
225 def showbisect(repo, ctx, templ, **args):
225 def showbisect(repo, ctx, templ, **args):
226 """String. The changeset bisection status."""
226 """String. The changeset bisection status."""
227 return hbisect.label(repo, ctx.node())
227 return hbisect.label(repo, ctx.node())
228
228
229 @templatekeyword('branch')
229 @templatekeyword('branch')
230 def showbranch(**args):
230 def showbranch(**args):
231 """String. The name of the branch on which the changeset was
231 """String. The name of the branch on which the changeset was
232 committed.
232 committed.
233 """
233 """
234 return args['ctx'].branch()
234 return args['ctx'].branch()
235
235
236 @templatekeyword('branches')
236 @templatekeyword('branches')
237 def showbranches(**args):
237 def showbranches(**args):
238 """List of strings. The name of the branch on which the
238 """List of strings. The name of the branch on which the
239 changeset was committed. Will be empty if the branch name was
239 changeset was committed. Will be empty if the branch name was
240 default. (DEPRECATED)
240 default. (DEPRECATED)
241 """
241 """
242 branch = args['ctx'].branch()
242 branch = args['ctx'].branch()
243 if branch != 'default':
243 if branch != 'default':
244 return showlist('branch', [branch], plural='branches', **args)
244 return showlist('branch', [branch], plural='branches', **args)
245 return showlist('branch', [], plural='branches', **args)
245 return showlist('branch', [], plural='branches', **args)
246
246
247 @templatekeyword('bookmarks')
247 @templatekeyword('bookmarks')
248 def showbookmarks(**args):
248 def showbookmarks(**args):
249 """List of strings. Any bookmarks associated with the
249 """List of strings. Any bookmarks associated with the
250 changeset. Also sets 'active', the name of the active bookmark.
250 changeset. Also sets 'active', the name of the active bookmark.
251 """
251 """
252 repo = args['ctx']._repo
252 repo = args['ctx']._repo
253 bookmarks = args['ctx'].bookmarks()
253 bookmarks = args['ctx'].bookmarks()
254 active = repo._activebookmark
254 active = repo._activebookmark
255 makemap = lambda v: {'bookmark': v, 'active': active, 'current': active}
255 makemap = lambda v: {'bookmark': v, 'active': active, 'current': active}
256 f = _showlist('bookmark', bookmarks, **args)
256 f = _showlist('bookmark', bookmarks, **args)
257 return _hybrid(f, bookmarks, makemap, lambda x: x['bookmark'])
257 return _hybrid(f, bookmarks, makemap, lambda x: x['bookmark'])
258
258
259 @templatekeyword('children')
259 @templatekeyword('children')
260 def showchildren(**args):
260 def showchildren(**args):
261 """List of strings. The children of the changeset."""
261 """List of strings. The children of the changeset."""
262 ctx = args['ctx']
262 ctx = args['ctx']
263 childrevs = ['%d:%s' % (cctx, cctx) for cctx in ctx.children()]
263 childrevs = ['%d:%s' % (cctx, cctx) for cctx in ctx.children()]
264 return showlist('children', childrevs, element='child', **args)
264 return showlist('children', childrevs, element='child', **args)
265
265
266 # Deprecated, but kept alive for help generation a purpose.
266 # Deprecated, but kept alive for help generation a purpose.
267 @templatekeyword('currentbookmark')
267 @templatekeyword('currentbookmark')
268 def showcurrentbookmark(**args):
268 def showcurrentbookmark(**args):
269 """String. The active bookmark, if it is
269 """String. The active bookmark, if it is
270 associated with the changeset (DEPRECATED)"""
270 associated with the changeset (DEPRECATED)"""
271 return showactivebookmark(**args)
271 return showactivebookmark(**args)
272
272
273 @templatekeyword('activebookmark')
273 @templatekeyword('activebookmark')
274 def showactivebookmark(**args):
274 def showactivebookmark(**args):
275 """String. The active bookmark, if it is
275 """String. The active bookmark, if it is
276 associated with the changeset"""
276 associated with the changeset"""
277 active = args['repo']._activebookmark
277 active = args['repo']._activebookmark
278 if active and active in args['ctx'].bookmarks():
278 if active and active in args['ctx'].bookmarks():
279 return active
279 return active
280 return ''
280 return ''
281
281
282 @templatekeyword('date')
282 @templatekeyword('date')
283 def showdate(repo, ctx, templ, **args):
283 def showdate(repo, ctx, templ, **args):
284 """Date information. The date when the changeset was committed."""
284 """Date information. The date when the changeset was committed."""
285 return ctx.date()
285 return ctx.date()
286
286
287 @templatekeyword('desc')
287 @templatekeyword('desc')
288 def showdescription(repo, ctx, templ, **args):
288 def showdescription(repo, ctx, templ, **args):
289 """String. The text of the changeset description."""
289 """String. The text of the changeset description."""
290 s = ctx.description()
290 s = ctx.description()
291 if isinstance(s, encoding.localstr):
291 if isinstance(s, encoding.localstr):
292 # try hard to preserve utf-8 bytes
292 # try hard to preserve utf-8 bytes
293 return encoding.tolocal(encoding.fromlocal(s).strip())
293 return encoding.tolocal(encoding.fromlocal(s).strip())
294 else:
294 else:
295 return s.strip()
295 return s.strip()
296
296
297 @templatekeyword('diffstat')
297 @templatekeyword('diffstat')
298 def showdiffstat(repo, ctx, templ, **args):
298 def showdiffstat(repo, ctx, templ, **args):
299 """String. Statistics of changes with the following format:
299 """String. Statistics of changes with the following format:
300 "modified files: +added/-removed lines"
300 "modified files: +added/-removed lines"
301 """
301 """
302 stats = patch.diffstatdata(util.iterlines(ctx.diff()))
302 stats = patch.diffstatdata(util.iterlines(ctx.diff(noprefix=False)))
303 maxname, maxtotal, adds, removes, binary = patch.diffstatsum(stats)
303 maxname, maxtotal, adds, removes, binary = patch.diffstatsum(stats)
304 return '%s: +%s/-%s' % (len(stats), adds, removes)
304 return '%s: +%s/-%s' % (len(stats), adds, removes)
305
305
306 @templatekeyword('extras')
306 @templatekeyword('extras')
307 def showextras(**args):
307 def showextras(**args):
308 """List of dicts with key, value entries of the 'extras'
308 """List of dicts with key, value entries of the 'extras'
309 field of this changeset."""
309 field of this changeset."""
310 extras = args['ctx'].extra()
310 extras = args['ctx'].extra()
311 extras = util.sortdict((k, extras[k]) for k in sorted(extras))
311 extras = util.sortdict((k, extras[k]) for k in sorted(extras))
312 makemap = lambda k: {'key': k, 'value': extras[k]}
312 makemap = lambda k: {'key': k, 'value': extras[k]}
313 c = [makemap(k) for k in extras]
313 c = [makemap(k) for k in extras]
314 f = _showlist('extra', c, plural='extras', **args)
314 f = _showlist('extra', c, plural='extras', **args)
315 return _hybrid(f, extras, makemap,
315 return _hybrid(f, extras, makemap,
316 lambda x: '%s=%s' % (x['key'], x['value']))
316 lambda x: '%s=%s' % (x['key'], x['value']))
317
317
318 @templatekeyword('file_adds')
318 @templatekeyword('file_adds')
319 def showfileadds(**args):
319 def showfileadds(**args):
320 """List of strings. Files added by this changeset."""
320 """List of strings. Files added by this changeset."""
321 repo, ctx, revcache = args['repo'], args['ctx'], args['revcache']
321 repo, ctx, revcache = args['repo'], args['ctx'], args['revcache']
322 return showlist('file_add', getfiles(repo, ctx, revcache)[1],
322 return showlist('file_add', getfiles(repo, ctx, revcache)[1],
323 element='file', **args)
323 element='file', **args)
324
324
325 @templatekeyword('file_copies')
325 @templatekeyword('file_copies')
326 def showfilecopies(**args):
326 def showfilecopies(**args):
327 """List of strings. Files copied in this changeset with
327 """List of strings. Files copied in this changeset with
328 their sources.
328 their sources.
329 """
329 """
330 cache, ctx = args['cache'], args['ctx']
330 cache, ctx = args['cache'], args['ctx']
331 copies = args['revcache'].get('copies')
331 copies = args['revcache'].get('copies')
332 if copies is None:
332 if copies is None:
333 if 'getrenamed' not in cache:
333 if 'getrenamed' not in cache:
334 cache['getrenamed'] = getrenamedfn(args['repo'])
334 cache['getrenamed'] = getrenamedfn(args['repo'])
335 copies = []
335 copies = []
336 getrenamed = cache['getrenamed']
336 getrenamed = cache['getrenamed']
337 for fn in ctx.files():
337 for fn in ctx.files():
338 rename = getrenamed(fn, ctx.rev())
338 rename = getrenamed(fn, ctx.rev())
339 if rename:
339 if rename:
340 copies.append((fn, rename[0]))
340 copies.append((fn, rename[0]))
341
341
342 copies = util.sortdict(copies)
342 copies = util.sortdict(copies)
343 makemap = lambda k: {'name': k, 'source': copies[k]}
343 makemap = lambda k: {'name': k, 'source': copies[k]}
344 c = [makemap(k) for k in copies]
344 c = [makemap(k) for k in copies]
345 f = _showlist('file_copy', c, plural='file_copies', **args)
345 f = _showlist('file_copy', c, plural='file_copies', **args)
346 return _hybrid(f, copies, makemap,
346 return _hybrid(f, copies, makemap,
347 lambda x: '%s (%s)' % (x['name'], x['source']))
347 lambda x: '%s (%s)' % (x['name'], x['source']))
348
348
349 # showfilecopiesswitch() displays file copies only if copy records are
349 # showfilecopiesswitch() displays file copies only if copy records are
350 # provided before calling the templater, usually with a --copies
350 # provided before calling the templater, usually with a --copies
351 # command line switch.
351 # command line switch.
352 @templatekeyword('file_copies_switch')
352 @templatekeyword('file_copies_switch')
353 def showfilecopiesswitch(**args):
353 def showfilecopiesswitch(**args):
354 """List of strings. Like "file_copies" but displayed
354 """List of strings. Like "file_copies" but displayed
355 only if the --copied switch is set.
355 only if the --copied switch is set.
356 """
356 """
357 copies = args['revcache'].get('copies') or []
357 copies = args['revcache'].get('copies') or []
358 copies = util.sortdict(copies)
358 copies = util.sortdict(copies)
359 makemap = lambda k: {'name': k, 'source': copies[k]}
359 makemap = lambda k: {'name': k, 'source': copies[k]}
360 c = [makemap(k) for k in copies]
360 c = [makemap(k) for k in copies]
361 f = _showlist('file_copy', c, plural='file_copies', **args)
361 f = _showlist('file_copy', c, plural='file_copies', **args)
362 return _hybrid(f, copies, makemap,
362 return _hybrid(f, copies, makemap,
363 lambda x: '%s (%s)' % (x['name'], x['source']))
363 lambda x: '%s (%s)' % (x['name'], x['source']))
364
364
365 @templatekeyword('file_dels')
365 @templatekeyword('file_dels')
366 def showfiledels(**args):
366 def showfiledels(**args):
367 """List of strings. Files removed by this changeset."""
367 """List of strings. Files removed by this changeset."""
368 repo, ctx, revcache = args['repo'], args['ctx'], args['revcache']
368 repo, ctx, revcache = args['repo'], args['ctx'], args['revcache']
369 return showlist('file_del', getfiles(repo, ctx, revcache)[2],
369 return showlist('file_del', getfiles(repo, ctx, revcache)[2],
370 element='file', **args)
370 element='file', **args)
371
371
372 @templatekeyword('file_mods')
372 @templatekeyword('file_mods')
373 def showfilemods(**args):
373 def showfilemods(**args):
374 """List of strings. Files modified by this changeset."""
374 """List of strings. Files modified by this changeset."""
375 repo, ctx, revcache = args['repo'], args['ctx'], args['revcache']
375 repo, ctx, revcache = args['repo'], args['ctx'], args['revcache']
376 return showlist('file_mod', getfiles(repo, ctx, revcache)[0],
376 return showlist('file_mod', getfiles(repo, ctx, revcache)[0],
377 element='file', **args)
377 element='file', **args)
378
378
379 @templatekeyword('files')
379 @templatekeyword('files')
380 def showfiles(**args):
380 def showfiles(**args):
381 """List of strings. All files modified, added, or removed by this
381 """List of strings. All files modified, added, or removed by this
382 changeset.
382 changeset.
383 """
383 """
384 return showlist('file', args['ctx'].files(), **args)
384 return showlist('file', args['ctx'].files(), **args)
385
385
386 @templatekeyword('graphnode')
386 @templatekeyword('graphnode')
387 def showgraphnode(repo, ctx, **args):
387 def showgraphnode(repo, ctx, **args):
388 """String. The character representing the changeset node in
388 """String. The character representing the changeset node in
389 an ASCII revision graph"""
389 an ASCII revision graph"""
390 wpnodes = repo.dirstate.parents()
390 wpnodes = repo.dirstate.parents()
391 if wpnodes[1] == nullid:
391 if wpnodes[1] == nullid:
392 wpnodes = wpnodes[:1]
392 wpnodes = wpnodes[:1]
393 if ctx.node() in wpnodes:
393 if ctx.node() in wpnodes:
394 return '@'
394 return '@'
395 elif ctx.obsolete():
395 elif ctx.obsolete():
396 return 'x'
396 return 'x'
397 elif ctx.closesbranch():
397 elif ctx.closesbranch():
398 return '_'
398 return '_'
399 else:
399 else:
400 return 'o'
400 return 'o'
401
401
402 @templatekeyword('latesttag')
402 @templatekeyword('latesttag')
403 def showlatesttag(**args):
403 def showlatesttag(**args):
404 """List of strings. The global tags on the most recent globally
404 """List of strings. The global tags on the most recent globally
405 tagged ancestor of this changeset.
405 tagged ancestor of this changeset.
406 """
406 """
407 return showlatesttags(None, **args)
407 return showlatesttags(None, **args)
408
408
409 def showlatesttags(pattern, **args):
409 def showlatesttags(pattern, **args):
410 """helper method for the latesttag keyword and function"""
410 """helper method for the latesttag keyword and function"""
411 repo, ctx = args['repo'], args['ctx']
411 repo, ctx = args['repo'], args['ctx']
412 cache = args['cache']
412 cache = args['cache']
413 latesttags = getlatesttags(repo, ctx, cache, pattern)
413 latesttags = getlatesttags(repo, ctx, cache, pattern)
414
414
415 # latesttag[0] is an implementation detail for sorting csets on different
415 # latesttag[0] is an implementation detail for sorting csets on different
416 # branches in a stable manner- it is the date the tagged cset was created,
416 # branches in a stable manner- it is the date the tagged cset was created,
417 # not the date the tag was created. Therefore it isn't made visible here.
417 # not the date the tag was created. Therefore it isn't made visible here.
418 makemap = lambda v: {
418 makemap = lambda v: {
419 'changes': _showchangessincetag,
419 'changes': _showchangessincetag,
420 'distance': latesttags[1],
420 'distance': latesttags[1],
421 'latesttag': v, # BC with {latesttag % '{latesttag}'}
421 'latesttag': v, # BC with {latesttag % '{latesttag}'}
422 'tag': v
422 'tag': v
423 }
423 }
424
424
425 tags = latesttags[2]
425 tags = latesttags[2]
426 f = _showlist('latesttag', tags, separator=':', **args)
426 f = _showlist('latesttag', tags, separator=':', **args)
427 return _hybrid(f, tags, makemap, lambda x: x['latesttag'])
427 return _hybrid(f, tags, makemap, lambda x: x['latesttag'])
428
428
429 @templatekeyword('latesttagdistance')
429 @templatekeyword('latesttagdistance')
430 def showlatesttagdistance(repo, ctx, templ, cache, **args):
430 def showlatesttagdistance(repo, ctx, templ, cache, **args):
431 """Integer. Longest path to the latest tag."""
431 """Integer. Longest path to the latest tag."""
432 return getlatesttags(repo, ctx, cache)[1]
432 return getlatesttags(repo, ctx, cache)[1]
433
433
434 @templatekeyword('changessincelatesttag')
434 @templatekeyword('changessincelatesttag')
435 def showchangessincelatesttag(repo, ctx, templ, cache, **args):
435 def showchangessincelatesttag(repo, ctx, templ, cache, **args):
436 """Integer. All ancestors not in the latest tag."""
436 """Integer. All ancestors not in the latest tag."""
437 latesttag = getlatesttags(repo, ctx, cache)[2][0]
437 latesttag = getlatesttags(repo, ctx, cache)[2][0]
438
438
439 return _showchangessincetag(repo, ctx, tag=latesttag, **args)
439 return _showchangessincetag(repo, ctx, tag=latesttag, **args)
440
440
441 def _showchangessincetag(repo, ctx, **args):
441 def _showchangessincetag(repo, ctx, **args):
442 offset = 0
442 offset = 0
443 revs = [ctx.rev()]
443 revs = [ctx.rev()]
444 tag = args['tag']
444 tag = args['tag']
445
445
446 # The only() revset doesn't currently support wdir()
446 # The only() revset doesn't currently support wdir()
447 if ctx.rev() is None:
447 if ctx.rev() is None:
448 offset = 1
448 offset = 1
449 revs = [p.rev() for p in ctx.parents()]
449 revs = [p.rev() for p in ctx.parents()]
450
450
451 return len(repo.revs('only(%ld, %s)', revs, tag)) + offset
451 return len(repo.revs('only(%ld, %s)', revs, tag)) + offset
452
452
453 @templatekeyword('manifest')
453 @templatekeyword('manifest')
454 def showmanifest(**args):
454 def showmanifest(**args):
455 repo, ctx, templ = args['repo'], args['ctx'], args['templ']
455 repo, ctx, templ = args['repo'], args['ctx'], args['templ']
456 mnode = ctx.manifestnode()
456 mnode = ctx.manifestnode()
457 if mnode is None:
457 if mnode is None:
458 # just avoid crash, we might want to use the 'ff...' hash in future
458 # just avoid crash, we might want to use the 'ff...' hash in future
459 return
459 return
460 args = args.copy()
460 args = args.copy()
461 args.update({'rev': repo.manifestlog._revlog.rev(mnode),
461 args.update({'rev': repo.manifestlog._revlog.rev(mnode),
462 'node': hex(mnode)})
462 'node': hex(mnode)})
463 return templ('manifest', **args)
463 return templ('manifest', **args)
464
464
465 def shownames(namespace, **args):
465 def shownames(namespace, **args):
466 """helper method to generate a template keyword for a namespace"""
466 """helper method to generate a template keyword for a namespace"""
467 ctx = args['ctx']
467 ctx = args['ctx']
468 repo = ctx.repo()
468 repo = ctx.repo()
469 ns = repo.names[namespace]
469 ns = repo.names[namespace]
470 names = ns.names(repo, ctx.node())
470 names = ns.names(repo, ctx.node())
471 return showlist(ns.templatename, names, plural=namespace, **args)
471 return showlist(ns.templatename, names, plural=namespace, **args)
472
472
473 @templatekeyword('namespaces')
473 @templatekeyword('namespaces')
474 def shownamespaces(**args):
474 def shownamespaces(**args):
475 """Dict of lists. Names attached to this changeset per
475 """Dict of lists. Names attached to this changeset per
476 namespace."""
476 namespace."""
477 ctx = args['ctx']
477 ctx = args['ctx']
478 repo = ctx.repo()
478 repo = ctx.repo()
479 namespaces = util.sortdict((k, showlist('name', ns.names(repo, ctx.node()),
479 namespaces = util.sortdict((k, showlist('name', ns.names(repo, ctx.node()),
480 **args))
480 **args))
481 for k, ns in repo.names.iteritems())
481 for k, ns in repo.names.iteritems())
482 f = _showlist('namespace', list(namespaces), **args)
482 f = _showlist('namespace', list(namespaces), **args)
483 return _hybrid(f, namespaces,
483 return _hybrid(f, namespaces,
484 lambda k: {'namespace': k, 'names': namespaces[k]},
484 lambda k: {'namespace': k, 'names': namespaces[k]},
485 lambda x: x['namespace'])
485 lambda x: x['namespace'])
486
486
487 @templatekeyword('node')
487 @templatekeyword('node')
488 def shownode(repo, ctx, templ, **args):
488 def shownode(repo, ctx, templ, **args):
489 """String. The changeset identification hash, as a 40 hexadecimal
489 """String. The changeset identification hash, as a 40 hexadecimal
490 digit string.
490 digit string.
491 """
491 """
492 return ctx.hex()
492 return ctx.hex()
493
493
494 @templatekeyword('p1rev')
494 @templatekeyword('p1rev')
495 def showp1rev(repo, ctx, templ, **args):
495 def showp1rev(repo, ctx, templ, **args):
496 """Integer. The repository-local revision number of the changeset's
496 """Integer. The repository-local revision number of the changeset's
497 first parent, or -1 if the changeset has no parents."""
497 first parent, or -1 if the changeset has no parents."""
498 return ctx.p1().rev()
498 return ctx.p1().rev()
499
499
500 @templatekeyword('p2rev')
500 @templatekeyword('p2rev')
501 def showp2rev(repo, ctx, templ, **args):
501 def showp2rev(repo, ctx, templ, **args):
502 """Integer. The repository-local revision number of the changeset's
502 """Integer. The repository-local revision number of the changeset's
503 second parent, or -1 if the changeset has no second parent."""
503 second parent, or -1 if the changeset has no second parent."""
504 return ctx.p2().rev()
504 return ctx.p2().rev()
505
505
506 @templatekeyword('p1node')
506 @templatekeyword('p1node')
507 def showp1node(repo, ctx, templ, **args):
507 def showp1node(repo, ctx, templ, **args):
508 """String. The identification hash of the changeset's first parent,
508 """String. The identification hash of the changeset's first parent,
509 as a 40 digit hexadecimal string. If the changeset has no parents, all
509 as a 40 digit hexadecimal string. If the changeset has no parents, all
510 digits are 0."""
510 digits are 0."""
511 return ctx.p1().hex()
511 return ctx.p1().hex()
512
512
513 @templatekeyword('p2node')
513 @templatekeyword('p2node')
514 def showp2node(repo, ctx, templ, **args):
514 def showp2node(repo, ctx, templ, **args):
515 """String. The identification hash of the changeset's second
515 """String. The identification hash of the changeset's second
516 parent, as a 40 digit hexadecimal string. If the changeset has no second
516 parent, as a 40 digit hexadecimal string. If the changeset has no second
517 parent, all digits are 0."""
517 parent, all digits are 0."""
518 return ctx.p2().hex()
518 return ctx.p2().hex()
519
519
520 @templatekeyword('parents')
520 @templatekeyword('parents')
521 def showparents(**args):
521 def showparents(**args):
522 """List of strings. The parents of the changeset in "rev:node"
522 """List of strings. The parents of the changeset in "rev:node"
523 format. If the changeset has only one "natural" parent (the predecessor
523 format. If the changeset has only one "natural" parent (the predecessor
524 revision) nothing is shown."""
524 revision) nothing is shown."""
525 repo = args['repo']
525 repo = args['repo']
526 ctx = args['ctx']
526 ctx = args['ctx']
527 pctxs = scmutil.meaningfulparents(repo, ctx)
527 pctxs = scmutil.meaningfulparents(repo, ctx)
528 prevs = [str(p.rev()) for p in pctxs] # ifcontains() needs a list of str
528 prevs = [str(p.rev()) for p in pctxs] # ifcontains() needs a list of str
529 parents = [[('rev', p.rev()),
529 parents = [[('rev', p.rev()),
530 ('node', p.hex()),
530 ('node', p.hex()),
531 ('phase', p.phasestr())]
531 ('phase', p.phasestr())]
532 for p in pctxs]
532 for p in pctxs]
533 f = _showlist('parent', parents, **args)
533 f = _showlist('parent', parents, **args)
534 return _hybrid(f, prevs, lambda x: {'ctx': repo[int(x)], 'revcache': {}},
534 return _hybrid(f, prevs, lambda x: {'ctx': repo[int(x)], 'revcache': {}},
535 lambda d: _formatrevnode(d['ctx']))
535 lambda d: _formatrevnode(d['ctx']))
536
536
537 @templatekeyword('phase')
537 @templatekeyword('phase')
538 def showphase(repo, ctx, templ, **args):
538 def showphase(repo, ctx, templ, **args):
539 """String. The changeset phase name."""
539 """String. The changeset phase name."""
540 return ctx.phasestr()
540 return ctx.phasestr()
541
541
542 @templatekeyword('phaseidx')
542 @templatekeyword('phaseidx')
543 def showphaseidx(repo, ctx, templ, **args):
543 def showphaseidx(repo, ctx, templ, **args):
544 """Integer. The changeset phase index."""
544 """Integer. The changeset phase index."""
545 return ctx.phase()
545 return ctx.phase()
546
546
547 @templatekeyword('rev')
547 @templatekeyword('rev')
548 def showrev(repo, ctx, templ, **args):
548 def showrev(repo, ctx, templ, **args):
549 """Integer. The repository-local changeset revision number."""
549 """Integer. The repository-local changeset revision number."""
550 return scmutil.intrev(ctx.rev())
550 return scmutil.intrev(ctx.rev())
551
551
552 def showrevslist(name, revs, **args):
552 def showrevslist(name, revs, **args):
553 """helper to generate a list of revisions in which a mapped template will
553 """helper to generate a list of revisions in which a mapped template will
554 be evaluated"""
554 be evaluated"""
555 repo = args['ctx'].repo()
555 repo = args['ctx'].repo()
556 revs = [str(r) for r in revs] # ifcontains() needs a list of str
556 revs = [str(r) for r in revs] # ifcontains() needs a list of str
557 f = _showlist(name, revs, **args)
557 f = _showlist(name, revs, **args)
558 return _hybrid(f, revs,
558 return _hybrid(f, revs,
559 lambda x: {name: x, 'ctx': repo[int(x)], 'revcache': {}},
559 lambda x: {name: x, 'ctx': repo[int(x)], 'revcache': {}},
560 lambda d: d[name])
560 lambda d: d[name])
561
561
562 @templatekeyword('subrepos')
562 @templatekeyword('subrepos')
563 def showsubrepos(**args):
563 def showsubrepos(**args):
564 """List of strings. Updated subrepositories in the changeset."""
564 """List of strings. Updated subrepositories in the changeset."""
565 ctx = args['ctx']
565 ctx = args['ctx']
566 substate = ctx.substate
566 substate = ctx.substate
567 if not substate:
567 if not substate:
568 return showlist('subrepo', [], **args)
568 return showlist('subrepo', [], **args)
569 psubstate = ctx.parents()[0].substate or {}
569 psubstate = ctx.parents()[0].substate or {}
570 subrepos = []
570 subrepos = []
571 for sub in substate:
571 for sub in substate:
572 if sub not in psubstate or substate[sub] != psubstate[sub]:
572 if sub not in psubstate or substate[sub] != psubstate[sub]:
573 subrepos.append(sub) # modified or newly added in ctx
573 subrepos.append(sub) # modified or newly added in ctx
574 for sub in psubstate:
574 for sub in psubstate:
575 if sub not in substate:
575 if sub not in substate:
576 subrepos.append(sub) # removed in ctx
576 subrepos.append(sub) # removed in ctx
577 return showlist('subrepo', sorted(subrepos), **args)
577 return showlist('subrepo', sorted(subrepos), **args)
578
578
579 # don't remove "showtags" definition, even though namespaces will put
579 # don't remove "showtags" definition, even though namespaces will put
580 # a helper function for "tags" keyword into "keywords" map automatically,
580 # a helper function for "tags" keyword into "keywords" map automatically,
581 # because online help text is built without namespaces initialization
581 # because online help text is built without namespaces initialization
582 @templatekeyword('tags')
582 @templatekeyword('tags')
583 def showtags(**args):
583 def showtags(**args):
584 """List of strings. Any tags associated with the changeset."""
584 """List of strings. Any tags associated with the changeset."""
585 return shownames('tags', **args)
585 return shownames('tags', **args)
586
586
587 def loadkeyword(ui, extname, registrarobj):
587 def loadkeyword(ui, extname, registrarobj):
588 """Load template keyword from specified registrarobj
588 """Load template keyword from specified registrarobj
589 """
589 """
590 for name, func in registrarobj._table.iteritems():
590 for name, func in registrarobj._table.iteritems():
591 keywords[name] = func
591 keywords[name] = func
592
592
593 @templatekeyword('termwidth')
593 @templatekeyword('termwidth')
594 def termwidth(repo, ctx, templ, **args):
594 def termwidth(repo, ctx, templ, **args):
595 """Integer. The width of the current terminal."""
595 """Integer. The width of the current terminal."""
596 return repo.ui.termwidth()
596 return repo.ui.termwidth()
597
597
598 @templatekeyword('troubles')
598 @templatekeyword('troubles')
599 def showtroubles(**args):
599 def showtroubles(**args):
600 """List of strings. Evolution troubles affecting the changeset.
600 """List of strings. Evolution troubles affecting the changeset.
601
601
602 (EXPERIMENTAL)
602 (EXPERIMENTAL)
603 """
603 """
604 return showlist('trouble', args['ctx'].troubles(), **args)
604 return showlist('trouble', args['ctx'].troubles(), **args)
605
605
606 # tell hggettext to extract docstrings from these functions:
606 # tell hggettext to extract docstrings from these functions:
607 i18nfunctions = keywords.values()
607 i18nfunctions = keywords.values()
@@ -1,1805 +1,1812 b''
1 $ hg init a
1 $ hg init a
2 $ mkdir a/d1
2 $ mkdir a/d1
3 $ mkdir a/d1/d2
3 $ mkdir a/d1/d2
4 $ echo line 1 > a/a
4 $ echo line 1 > a/a
5 $ echo line 1 > a/d1/d2/a
5 $ echo line 1 > a/d1/d2/a
6 $ hg --cwd a ci -Ama
6 $ hg --cwd a ci -Ama
7 adding a
7 adding a
8 adding d1/d2/a
8 adding d1/d2/a
9
9
10 $ echo line 2 >> a/a
10 $ echo line 2 >> a/a
11 $ hg --cwd a ci -u someone -d '1 0' -m'second change'
11 $ hg --cwd a ci -u someone -d '1 0' -m'second change'
12
12
13 import with no args:
13 import with no args:
14
14
15 $ hg --cwd a import
15 $ hg --cwd a import
16 abort: need at least one patch to import
16 abort: need at least one patch to import
17 [255]
17 [255]
18
18
19 generate patches for the test
19 generate patches for the test
20
20
21 $ hg --cwd a export tip > exported-tip.patch
21 $ hg --cwd a export tip > exported-tip.patch
22 $ hg --cwd a diff -r0:1 > diffed-tip.patch
22 $ hg --cwd a diff -r0:1 > diffed-tip.patch
23
23
24
24
25 import exported patch
25 import exported patch
26 (this also tests that editor is not invoked, if the patch contains the
26 (this also tests that editor is not invoked, if the patch contains the
27 commit message and '--edit' is not specified)
27 commit message and '--edit' is not specified)
28
28
29 $ hg clone -r0 a b
29 $ hg clone -r0 a b
30 adding changesets
30 adding changesets
31 adding manifests
31 adding manifests
32 adding file changes
32 adding file changes
33 added 1 changesets with 2 changes to 2 files
33 added 1 changesets with 2 changes to 2 files
34 updating to branch default
34 updating to branch default
35 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
35 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
36 $ HGEDITOR=cat hg --cwd b import ../exported-tip.patch
36 $ HGEDITOR=cat hg --cwd b import ../exported-tip.patch
37 applying ../exported-tip.patch
37 applying ../exported-tip.patch
38
38
39 message and committer and date should be same
39 message and committer and date should be same
40
40
41 $ hg --cwd b tip
41 $ hg --cwd b tip
42 changeset: 1:1d4bd90af0e4
42 changeset: 1:1d4bd90af0e4
43 tag: tip
43 tag: tip
44 user: someone
44 user: someone
45 date: Thu Jan 01 00:00:01 1970 +0000
45 date: Thu Jan 01 00:00:01 1970 +0000
46 summary: second change
46 summary: second change
47
47
48 $ rm -r b
48 $ rm -r b
49
49
50
50
51 import exported patch with external patcher
51 import exported patch with external patcher
52 (this also tests that editor is invoked, if the '--edit' is specified,
52 (this also tests that editor is invoked, if the '--edit' is specified,
53 regardless of the commit message in the patch)
53 regardless of the commit message in the patch)
54
54
55 $ cat > dummypatch.py <<EOF
55 $ cat > dummypatch.py <<EOF
56 > from __future__ import print_function
56 > from __future__ import print_function
57 > print('patching file a')
57 > print('patching file a')
58 > file('a', 'wb').write('line2\n')
58 > file('a', 'wb').write('line2\n')
59 > EOF
59 > EOF
60 $ hg clone -r0 a b
60 $ hg clone -r0 a b
61 adding changesets
61 adding changesets
62 adding manifests
62 adding manifests
63 adding file changes
63 adding file changes
64 added 1 changesets with 2 changes to 2 files
64 added 1 changesets with 2 changes to 2 files
65 updating to branch default
65 updating to branch default
66 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
66 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
67 $ HGEDITOR=cat hg --config ui.patch='python ../dummypatch.py' --cwd b import --edit ../exported-tip.patch
67 $ HGEDITOR=cat hg --config ui.patch='python ../dummypatch.py' --cwd b import --edit ../exported-tip.patch
68 applying ../exported-tip.patch
68 applying ../exported-tip.patch
69 second change
69 second change
70
70
71
71
72 HG: Enter commit message. Lines beginning with 'HG:' are removed.
72 HG: Enter commit message. Lines beginning with 'HG:' are removed.
73 HG: Leave message empty to abort commit.
73 HG: Leave message empty to abort commit.
74 HG: --
74 HG: --
75 HG: user: someone
75 HG: user: someone
76 HG: branch 'default'
76 HG: branch 'default'
77 HG: changed a
77 HG: changed a
78 $ cat b/a
78 $ cat b/a
79 line2
79 line2
80 $ rm -r b
80 $ rm -r b
81
81
82
82
83 import of plain diff should fail without message
83 import of plain diff should fail without message
84 (this also tests that editor is invoked, if the patch doesn't contain
84 (this also tests that editor is invoked, if the patch doesn't contain
85 the commit message, regardless of '--edit')
85 the commit message, regardless of '--edit')
86
86
87 $ hg clone -r0 a b
87 $ hg clone -r0 a b
88 adding changesets
88 adding changesets
89 adding manifests
89 adding manifests
90 adding file changes
90 adding file changes
91 added 1 changesets with 2 changes to 2 files
91 added 1 changesets with 2 changes to 2 files
92 updating to branch default
92 updating to branch default
93 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
93 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
94 $ cat > $TESTTMP/editor.sh <<EOF
94 $ cat > $TESTTMP/editor.sh <<EOF
95 > env | grep HGEDITFORM
95 > env | grep HGEDITFORM
96 > cat \$1
96 > cat \$1
97 > EOF
97 > EOF
98 $ HGEDITOR="sh $TESTTMP/editor.sh" hg --cwd b import ../diffed-tip.patch
98 $ HGEDITOR="sh $TESTTMP/editor.sh" hg --cwd b import ../diffed-tip.patch
99 applying ../diffed-tip.patch
99 applying ../diffed-tip.patch
100 HGEDITFORM=import.normal.normal
100 HGEDITFORM=import.normal.normal
101
101
102
102
103 HG: Enter commit message. Lines beginning with 'HG:' are removed.
103 HG: Enter commit message. Lines beginning with 'HG:' are removed.
104 HG: Leave message empty to abort commit.
104 HG: Leave message empty to abort commit.
105 HG: --
105 HG: --
106 HG: user: test
106 HG: user: test
107 HG: branch 'default'
107 HG: branch 'default'
108 HG: changed a
108 HG: changed a
109 abort: empty commit message
109 abort: empty commit message
110 [255]
110 [255]
111
111
112 Test avoiding editor invocation at applying the patch with --exact,
112 Test avoiding editor invocation at applying the patch with --exact,
113 even if commit message is empty
113 even if commit message is empty
114
114
115 $ echo a >> b/a
115 $ echo a >> b/a
116 $ hg --cwd b commit -m ' '
116 $ hg --cwd b commit -m ' '
117 $ hg --cwd b tip -T "{node}\n"
117 $ hg --cwd b tip -T "{node}\n"
118 d8804f3f5396d800812f579c8452796a5993bdb2
118 d8804f3f5396d800812f579c8452796a5993bdb2
119 $ hg --cwd b export -o ../empty-log.diff .
119 $ hg --cwd b export -o ../empty-log.diff .
120 $ hg --cwd b update -q -C ".^1"
120 $ hg --cwd b update -q -C ".^1"
121 $ hg --cwd b --config extensions.strip= strip -q tip
121 $ hg --cwd b --config extensions.strip= strip -q tip
122 $ HGEDITOR=cat hg --cwd b import --exact ../empty-log.diff
122 $ HGEDITOR=cat hg --cwd b import --exact ../empty-log.diff
123 applying ../empty-log.diff
123 applying ../empty-log.diff
124 $ hg --cwd b tip -T "{node}\n"
124 $ hg --cwd b tip -T "{node}\n"
125 d8804f3f5396d800812f579c8452796a5993bdb2
125 d8804f3f5396d800812f579c8452796a5993bdb2
126
126
127 $ rm -r b
127 $ rm -r b
128
128
129
129
130 import of plain diff should be ok with message
130 import of plain diff should be ok with message
131
131
132 $ hg clone -r0 a b
132 $ hg clone -r0 a b
133 adding changesets
133 adding changesets
134 adding manifests
134 adding manifests
135 adding file changes
135 adding file changes
136 added 1 changesets with 2 changes to 2 files
136 added 1 changesets with 2 changes to 2 files
137 updating to branch default
137 updating to branch default
138 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
138 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
139 $ hg --cwd b import -mpatch ../diffed-tip.patch
139 $ hg --cwd b import -mpatch ../diffed-tip.patch
140 applying ../diffed-tip.patch
140 applying ../diffed-tip.patch
141 $ rm -r b
141 $ rm -r b
142
142
143
143
144 import of plain diff with specific date and user
144 import of plain diff with specific date and user
145 (this also tests that editor is not invoked, if
145 (this also tests that editor is not invoked, if
146 '--message'/'--logfile' is specified and '--edit' is not)
146 '--message'/'--logfile' is specified and '--edit' is not)
147
147
148 $ hg clone -r0 a b
148 $ hg clone -r0 a b
149 adding changesets
149 adding changesets
150 adding manifests
150 adding manifests
151 adding file changes
151 adding file changes
152 added 1 changesets with 2 changes to 2 files
152 added 1 changesets with 2 changes to 2 files
153 updating to branch default
153 updating to branch default
154 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
154 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
155 $ hg --cwd b import -mpatch -d '1 0' -u 'user@nowhere.net' ../diffed-tip.patch
155 $ hg --cwd b import -mpatch -d '1 0' -u 'user@nowhere.net' ../diffed-tip.patch
156 applying ../diffed-tip.patch
156 applying ../diffed-tip.patch
157 $ hg -R b tip -pv
157 $ hg -R b tip -pv
158 changeset: 1:ca68f19f3a40
158 changeset: 1:ca68f19f3a40
159 tag: tip
159 tag: tip
160 user: user@nowhere.net
160 user: user@nowhere.net
161 date: Thu Jan 01 00:00:01 1970 +0000
161 date: Thu Jan 01 00:00:01 1970 +0000
162 files: a
162 files: a
163 description:
163 description:
164 patch
164 patch
165
165
166
166
167 diff -r 80971e65b431 -r ca68f19f3a40 a
167 diff -r 80971e65b431 -r ca68f19f3a40 a
168 --- a/a Thu Jan 01 00:00:00 1970 +0000
168 --- a/a Thu Jan 01 00:00:00 1970 +0000
169 +++ b/a Thu Jan 01 00:00:01 1970 +0000
169 +++ b/a Thu Jan 01 00:00:01 1970 +0000
170 @@ -1,1 +1,2 @@
170 @@ -1,1 +1,2 @@
171 line 1
171 line 1
172 +line 2
172 +line 2
173
173
174 $ rm -r b
174 $ rm -r b
175
175
176
176
177 import of plain diff should be ok with --no-commit
177 import of plain diff should be ok with --no-commit
178 (this also tests that editor is not invoked, if '--no-commit' is
178 (this also tests that editor is not invoked, if '--no-commit' is
179 specified, regardless of '--edit')
179 specified, regardless of '--edit')
180
180
181 $ hg clone -r0 a b
181 $ hg clone -r0 a b
182 adding changesets
182 adding changesets
183 adding manifests
183 adding manifests
184 adding file changes
184 adding file changes
185 added 1 changesets with 2 changes to 2 files
185 added 1 changesets with 2 changes to 2 files
186 updating to branch default
186 updating to branch default
187 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
187 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
188 $ HGEDITOR=cat hg --cwd b import --no-commit --edit ../diffed-tip.patch
188 $ HGEDITOR=cat hg --cwd b import --no-commit --edit ../diffed-tip.patch
189 applying ../diffed-tip.patch
189 applying ../diffed-tip.patch
190 $ hg --cwd b diff --nodates
190 $ hg --cwd b diff --nodates
191 diff -r 80971e65b431 a
191 diff -r 80971e65b431 a
192 --- a/a
192 --- a/a
193 +++ b/a
193 +++ b/a
194 @@ -1,1 +1,2 @@
194 @@ -1,1 +1,2 @@
195 line 1
195 line 1
196 +line 2
196 +line 2
197 $ rm -r b
197 $ rm -r b
198
198
199
199
200 import of malformed plain diff should fail
200 import of malformed plain diff should fail
201
201
202 $ hg clone -r0 a b
202 $ hg clone -r0 a b
203 adding changesets
203 adding changesets
204 adding manifests
204 adding manifests
205 adding file changes
205 adding file changes
206 added 1 changesets with 2 changes to 2 files
206 added 1 changesets with 2 changes to 2 files
207 updating to branch default
207 updating to branch default
208 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
208 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
209 $ sed 's/1,1/foo/' < diffed-tip.patch > broken.patch
209 $ sed 's/1,1/foo/' < diffed-tip.patch > broken.patch
210 $ hg --cwd b import -mpatch ../broken.patch
210 $ hg --cwd b import -mpatch ../broken.patch
211 applying ../broken.patch
211 applying ../broken.patch
212 abort: bad hunk #1
212 abort: bad hunk #1
213 [255]
213 [255]
214 $ rm -r b
214 $ rm -r b
215
215
216
216
217 hg -R repo import
217 hg -R repo import
218 put the clone in a subdir - having a directory named "a"
218 put the clone in a subdir - having a directory named "a"
219 used to hide a bug.
219 used to hide a bug.
220
220
221 $ mkdir dir
221 $ mkdir dir
222 $ hg clone -r0 a dir/b
222 $ hg clone -r0 a dir/b
223 adding changesets
223 adding changesets
224 adding manifests
224 adding manifests
225 adding file changes
225 adding file changes
226 added 1 changesets with 2 changes to 2 files
226 added 1 changesets with 2 changes to 2 files
227 updating to branch default
227 updating to branch default
228 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
228 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
229 $ cd dir
229 $ cd dir
230 $ hg -R b import ../exported-tip.patch
230 $ hg -R b import ../exported-tip.patch
231 applying ../exported-tip.patch
231 applying ../exported-tip.patch
232 $ cd ..
232 $ cd ..
233 $ rm -r dir
233 $ rm -r dir
234
234
235
235
236 import from stdin
236 import from stdin
237
237
238 $ hg clone -r0 a b
238 $ hg clone -r0 a b
239 adding changesets
239 adding changesets
240 adding manifests
240 adding manifests
241 adding file changes
241 adding file changes
242 added 1 changesets with 2 changes to 2 files
242 added 1 changesets with 2 changes to 2 files
243 updating to branch default
243 updating to branch default
244 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
244 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
245 $ hg --cwd b import - < exported-tip.patch
245 $ hg --cwd b import - < exported-tip.patch
246 applying patch from stdin
246 applying patch from stdin
247 $ rm -r b
247 $ rm -r b
248
248
249
249
250 import two patches in one stream
250 import two patches in one stream
251
251
252 $ hg init b
252 $ hg init b
253 $ hg --cwd a export 0:tip | hg --cwd b import -
253 $ hg --cwd a export 0:tip | hg --cwd b import -
254 applying patch from stdin
254 applying patch from stdin
255 $ hg --cwd a id
255 $ hg --cwd a id
256 1d4bd90af0e4 tip
256 1d4bd90af0e4 tip
257 $ hg --cwd b id
257 $ hg --cwd b id
258 1d4bd90af0e4 tip
258 1d4bd90af0e4 tip
259 $ rm -r b
259 $ rm -r b
260
260
261
261
262 override commit message
262 override commit message
263
263
264 $ hg clone -r0 a b
264 $ hg clone -r0 a b
265 adding changesets
265 adding changesets
266 adding manifests
266 adding manifests
267 adding file changes
267 adding file changes
268 added 1 changesets with 2 changes to 2 files
268 added 1 changesets with 2 changes to 2 files
269 updating to branch default
269 updating to branch default
270 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
270 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
271 $ hg --cwd b import -m 'override' - < exported-tip.patch
271 $ hg --cwd b import -m 'override' - < exported-tip.patch
272 applying patch from stdin
272 applying patch from stdin
273 $ hg --cwd b tip | grep override
273 $ hg --cwd b tip | grep override
274 summary: override
274 summary: override
275 $ rm -r b
275 $ rm -r b
276
276
277 $ cat > mkmsg.py <<EOF
277 $ cat > mkmsg.py <<EOF
278 > import email.Message, sys
278 > import email.Message, sys
279 > msg = email.Message.Message()
279 > msg = email.Message.Message()
280 > patch = open(sys.argv[1], 'rb').read()
280 > patch = open(sys.argv[1], 'rb').read()
281 > msg.set_payload('email commit message\n' + patch)
281 > msg.set_payload('email commit message\n' + patch)
282 > msg['Subject'] = 'email patch'
282 > msg['Subject'] = 'email patch'
283 > msg['From'] = 'email patcher'
283 > msg['From'] = 'email patcher'
284 > file(sys.argv[2], 'wb').write(msg.as_string())
284 > file(sys.argv[2], 'wb').write(msg.as_string())
285 > EOF
285 > EOF
286
286
287
287
288 plain diff in email, subject, message body
288 plain diff in email, subject, message body
289
289
290 $ hg clone -r0 a b
290 $ hg clone -r0 a b
291 adding changesets
291 adding changesets
292 adding manifests
292 adding manifests
293 adding file changes
293 adding file changes
294 added 1 changesets with 2 changes to 2 files
294 added 1 changesets with 2 changes to 2 files
295 updating to branch default
295 updating to branch default
296 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
296 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
297 $ python mkmsg.py diffed-tip.patch msg.patch
297 $ python mkmsg.py diffed-tip.patch msg.patch
298 $ hg --cwd b import ../msg.patch
298 $ hg --cwd b import ../msg.patch
299 applying ../msg.patch
299 applying ../msg.patch
300 $ hg --cwd b tip | grep email
300 $ hg --cwd b tip | grep email
301 user: email patcher
301 user: email patcher
302 summary: email patch
302 summary: email patch
303 $ rm -r b
303 $ rm -r b
304
304
305
305
306 plain diff in email, no subject, message body
306 plain diff in email, no subject, message body
307
307
308 $ hg clone -r0 a b
308 $ hg clone -r0 a b
309 adding changesets
309 adding changesets
310 adding manifests
310 adding manifests
311 adding file changes
311 adding file changes
312 added 1 changesets with 2 changes to 2 files
312 added 1 changesets with 2 changes to 2 files
313 updating to branch default
313 updating to branch default
314 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
314 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
315 $ grep -v '^Subject:' msg.patch | hg --cwd b import -
315 $ grep -v '^Subject:' msg.patch | hg --cwd b import -
316 applying patch from stdin
316 applying patch from stdin
317 $ rm -r b
317 $ rm -r b
318
318
319
319
320 plain diff in email, subject, no message body
320 plain diff in email, subject, no message body
321
321
322 $ hg clone -r0 a b
322 $ hg clone -r0 a b
323 adding changesets
323 adding changesets
324 adding manifests
324 adding manifests
325 adding file changes
325 adding file changes
326 added 1 changesets with 2 changes to 2 files
326 added 1 changesets with 2 changes to 2 files
327 updating to branch default
327 updating to branch default
328 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
328 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
329 $ grep -v '^email ' msg.patch | hg --cwd b import -
329 $ grep -v '^email ' msg.patch | hg --cwd b import -
330 applying patch from stdin
330 applying patch from stdin
331 $ rm -r b
331 $ rm -r b
332
332
333
333
334 plain diff in email, no subject, no message body, should fail
334 plain diff in email, no subject, no message body, should fail
335
335
336 $ hg clone -r0 a b
336 $ hg clone -r0 a b
337 adding changesets
337 adding changesets
338 adding manifests
338 adding manifests
339 adding file changes
339 adding file changes
340 added 1 changesets with 2 changes to 2 files
340 added 1 changesets with 2 changes to 2 files
341 updating to branch default
341 updating to branch default
342 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
342 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
343 $ egrep -v '^(Subject|email)' msg.patch | hg --cwd b import -
343 $ egrep -v '^(Subject|email)' msg.patch | hg --cwd b import -
344 applying patch from stdin
344 applying patch from stdin
345 abort: empty commit message
345 abort: empty commit message
346 [255]
346 [255]
347 $ rm -r b
347 $ rm -r b
348
348
349
349
350 hg export in email, should use patch header
350 hg export in email, should use patch header
351
351
352 $ hg clone -r0 a b
352 $ hg clone -r0 a b
353 adding changesets
353 adding changesets
354 adding manifests
354 adding manifests
355 adding file changes
355 adding file changes
356 added 1 changesets with 2 changes to 2 files
356 added 1 changesets with 2 changes to 2 files
357 updating to branch default
357 updating to branch default
358 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
358 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
359 $ python mkmsg.py exported-tip.patch msg.patch
359 $ python mkmsg.py exported-tip.patch msg.patch
360 $ cat msg.patch | hg --cwd b import -
360 $ cat msg.patch | hg --cwd b import -
361 applying patch from stdin
361 applying patch from stdin
362 $ hg --cwd b tip | grep second
362 $ hg --cwd b tip | grep second
363 summary: second change
363 summary: second change
364 $ rm -r b
364 $ rm -r b
365
365
366
366
367 subject: duplicate detection, removal of [PATCH]
367 subject: duplicate detection, removal of [PATCH]
368 The '---' tests the gitsendmail handling without proper mail headers
368 The '---' tests the gitsendmail handling without proper mail headers
369
369
370 $ cat > mkmsg2.py <<EOF
370 $ cat > mkmsg2.py <<EOF
371 > import email.Message, sys
371 > import email.Message, sys
372 > msg = email.Message.Message()
372 > msg = email.Message.Message()
373 > patch = open(sys.argv[1], 'rb').read()
373 > patch = open(sys.argv[1], 'rb').read()
374 > msg.set_payload('email patch\n\nnext line\n---\n' + patch)
374 > msg.set_payload('email patch\n\nnext line\n---\n' + patch)
375 > msg['Subject'] = '[PATCH] email patch'
375 > msg['Subject'] = '[PATCH] email patch'
376 > msg['From'] = 'email patcher'
376 > msg['From'] = 'email patcher'
377 > file(sys.argv[2], 'wb').write(msg.as_string())
377 > file(sys.argv[2], 'wb').write(msg.as_string())
378 > EOF
378 > EOF
379
379
380
380
381 plain diff in email, [PATCH] subject, message body with subject
381 plain diff in email, [PATCH] subject, message body with subject
382
382
383 $ hg clone -r0 a b
383 $ hg clone -r0 a b
384 adding changesets
384 adding changesets
385 adding manifests
385 adding manifests
386 adding file changes
386 adding file changes
387 added 1 changesets with 2 changes to 2 files
387 added 1 changesets with 2 changes to 2 files
388 updating to branch default
388 updating to branch default
389 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
389 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
390 $ python mkmsg2.py diffed-tip.patch msg.patch
390 $ python mkmsg2.py diffed-tip.patch msg.patch
391 $ cat msg.patch | hg --cwd b import -
391 $ cat msg.patch | hg --cwd b import -
392 applying patch from stdin
392 applying patch from stdin
393 $ hg --cwd b tip --template '{desc}\n'
393 $ hg --cwd b tip --template '{desc}\n'
394 email patch
394 email patch
395
395
396 next line
396 next line
397 $ rm -r b
397 $ rm -r b
398
398
399
399
400 Issue963: Parent of working dir incorrect after import of multiple
400 Issue963: Parent of working dir incorrect after import of multiple
401 patches and rollback
401 patches and rollback
402
402
403 We weren't backing up the correct dirstate file when importing many
403 We weren't backing up the correct dirstate file when importing many
404 patches: import patch1 patch2; rollback
404 patches: import patch1 patch2; rollback
405
405
406 $ echo line 3 >> a/a
406 $ echo line 3 >> a/a
407 $ hg --cwd a ci -m'third change'
407 $ hg --cwd a ci -m'third change'
408 $ hg --cwd a export -o '../patch%R' 1 2
408 $ hg --cwd a export -o '../patch%R' 1 2
409 $ hg clone -qr0 a b
409 $ hg clone -qr0 a b
410 $ hg --cwd b parents --template 'parent: {rev}\n'
410 $ hg --cwd b parents --template 'parent: {rev}\n'
411 parent: 0
411 parent: 0
412 $ hg --cwd b import -v ../patch1 ../patch2
412 $ hg --cwd b import -v ../patch1 ../patch2
413 applying ../patch1
413 applying ../patch1
414 patching file a
414 patching file a
415 committing files:
415 committing files:
416 a
416 a
417 committing manifest
417 committing manifest
418 committing changelog
418 committing changelog
419 created 1d4bd90af0e4
419 created 1d4bd90af0e4
420 applying ../patch2
420 applying ../patch2
421 patching file a
421 patching file a
422 committing files:
422 committing files:
423 a
423 a
424 committing manifest
424 committing manifest
425 committing changelog
425 committing changelog
426 created 6d019af21222
426 created 6d019af21222
427 $ hg --cwd b rollback
427 $ hg --cwd b rollback
428 repository tip rolled back to revision 0 (undo import)
428 repository tip rolled back to revision 0 (undo import)
429 working directory now based on revision 0
429 working directory now based on revision 0
430 $ hg --cwd b parents --template 'parent: {rev}\n'
430 $ hg --cwd b parents --template 'parent: {rev}\n'
431 parent: 0
431 parent: 0
432
432
433 Test that "hg rollback" doesn't restore dirstate to one at the
433 Test that "hg rollback" doesn't restore dirstate to one at the
434 beginning of the rolled back transaction in not-"parent-gone" case.
434 beginning of the rolled back transaction in not-"parent-gone" case.
435
435
436 invoking pretxncommit hook will cause marking '.hg/dirstate' as a file
436 invoking pretxncommit hook will cause marking '.hg/dirstate' as a file
437 to be restored when rolling back, after DirstateTransactionPlan (see wiki
437 to be restored when rolling back, after DirstateTransactionPlan (see wiki
438 page for detail).
438 page for detail).
439
439
440 $ hg --cwd b branch -q foobar
440 $ hg --cwd b branch -q foobar
441 $ hg --cwd b commit -m foobar
441 $ hg --cwd b commit -m foobar
442 $ hg --cwd b update 0 -q
442 $ hg --cwd b update 0 -q
443 $ hg --cwd b import ../patch1 ../patch2 --config hooks.pretxncommit=true
443 $ hg --cwd b import ../patch1 ../patch2 --config hooks.pretxncommit=true
444 applying ../patch1
444 applying ../patch1
445 applying ../patch2
445 applying ../patch2
446 $ hg --cwd b update -q 1
446 $ hg --cwd b update -q 1
447 $ hg --cwd b rollback -q
447 $ hg --cwd b rollback -q
448 $ hg --cwd b parents --template 'parent: {rev}\n'
448 $ hg --cwd b parents --template 'parent: {rev}\n'
449 parent: 1
449 parent: 1
450
450
451 $ hg --cwd b update -q -C 0
451 $ hg --cwd b update -q -C 0
452 $ hg --cwd b --config extensions.strip= strip -q 1
452 $ hg --cwd b --config extensions.strip= strip -q 1
453
453
454 Test visibility of in-memory dirstate changes inside transaction to
454 Test visibility of in-memory dirstate changes inside transaction to
455 external process
455 external process
456
456
457 $ echo foo > a/foo
457 $ echo foo > a/foo
458 $ hg --cwd a commit -A -m 'adding foo' foo
458 $ hg --cwd a commit -A -m 'adding foo' foo
459 $ hg --cwd a export -o '../patch%R' 3
459 $ hg --cwd a export -o '../patch%R' 3
460
460
461 $ cat > $TESTTMP/checkvisibility.sh <<EOF
461 $ cat > $TESTTMP/checkvisibility.sh <<EOF
462 > echo "===="
462 > echo "===="
463 > hg parents --template "VISIBLE {rev}:{node|short}\n"
463 > hg parents --template "VISIBLE {rev}:{node|short}\n"
464 > hg status -amr
464 > hg status -amr
465 > # test that pending changes are hidden
465 > # test that pending changes are hidden
466 > unset HG_PENDING
466 > unset HG_PENDING
467 > hg parents --template "ACTUAL {rev}:{node|short}\n"
467 > hg parents --template "ACTUAL {rev}:{node|short}\n"
468 > hg status -amr
468 > hg status -amr
469 > echo "===="
469 > echo "===="
470 > EOF
470 > EOF
471
471
472 == test visibility to external editor
472 == test visibility to external editor
473
473
474 $ (cd b && sh "$TESTTMP/checkvisibility.sh")
474 $ (cd b && sh "$TESTTMP/checkvisibility.sh")
475 ====
475 ====
476 VISIBLE 0:80971e65b431
476 VISIBLE 0:80971e65b431
477 ACTUAL 0:80971e65b431
477 ACTUAL 0:80971e65b431
478 ====
478 ====
479
479
480 $ HGEDITOR="sh $TESTTMP/checkvisibility.sh" hg --cwd b import -v --edit ../patch1 ../patch2 ../patch3
480 $ HGEDITOR="sh $TESTTMP/checkvisibility.sh" hg --cwd b import -v --edit ../patch1 ../patch2 ../patch3
481 applying ../patch1
481 applying ../patch1
482 patching file a
482 patching file a
483 ====
483 ====
484 VISIBLE 0:80971e65b431
484 VISIBLE 0:80971e65b431
485 M a
485 M a
486 ACTUAL 0:80971e65b431
486 ACTUAL 0:80971e65b431
487 M a
487 M a
488 ====
488 ====
489 committing files:
489 committing files:
490 a
490 a
491 committing manifest
491 committing manifest
492 committing changelog
492 committing changelog
493 created 1d4bd90af0e4
493 created 1d4bd90af0e4
494 applying ../patch2
494 applying ../patch2
495 patching file a
495 patching file a
496 ====
496 ====
497 VISIBLE 1:1d4bd90af0e4
497 VISIBLE 1:1d4bd90af0e4
498 M a
498 M a
499 ACTUAL 0:80971e65b431
499 ACTUAL 0:80971e65b431
500 M a
500 M a
501 ====
501 ====
502 committing files:
502 committing files:
503 a
503 a
504 committing manifest
504 committing manifest
505 committing changelog
505 committing changelog
506 created 6d019af21222
506 created 6d019af21222
507 applying ../patch3
507 applying ../patch3
508 patching file foo
508 patching file foo
509 adding foo
509 adding foo
510 ====
510 ====
511 VISIBLE 2:6d019af21222
511 VISIBLE 2:6d019af21222
512 A foo
512 A foo
513 ACTUAL 0:80971e65b431
513 ACTUAL 0:80971e65b431
514 M a
514 M a
515 ====
515 ====
516 committing files:
516 committing files:
517 foo
517 foo
518 committing manifest
518 committing manifest
519 committing changelog
519 committing changelog
520 created 55e3f75b2378
520 created 55e3f75b2378
521
521
522 $ hg --cwd b rollback -q
522 $ hg --cwd b rollback -q
523
523
524 (content of file "a" is already changed and it should be recognized as
524 (content of file "a" is already changed and it should be recognized as
525 "M", even though dirstate is restored to one before "hg import")
525 "M", even though dirstate is restored to one before "hg import")
526
526
527 $ (cd b && sh "$TESTTMP/checkvisibility.sh")
527 $ (cd b && sh "$TESTTMP/checkvisibility.sh")
528 ====
528 ====
529 VISIBLE 0:80971e65b431
529 VISIBLE 0:80971e65b431
530 M a
530 M a
531 ACTUAL 0:80971e65b431
531 ACTUAL 0:80971e65b431
532 M a
532 M a
533 ====
533 ====
534 $ hg --cwd b revert --no-backup a
534 $ hg --cwd b revert --no-backup a
535 $ rm -f b/foo
535 $ rm -f b/foo
536
536
537 == test visibility to precommit external hook
537 == test visibility to precommit external hook
538
538
539 $ cat >> b/.hg/hgrc <<EOF
539 $ cat >> b/.hg/hgrc <<EOF
540 > [hooks]
540 > [hooks]
541 > precommit.visibility = sh $TESTTMP/checkvisibility.sh
541 > precommit.visibility = sh $TESTTMP/checkvisibility.sh
542 > EOF
542 > EOF
543
543
544 $ (cd b && sh "$TESTTMP/checkvisibility.sh")
544 $ (cd b && sh "$TESTTMP/checkvisibility.sh")
545 ====
545 ====
546 VISIBLE 0:80971e65b431
546 VISIBLE 0:80971e65b431
547 ACTUAL 0:80971e65b431
547 ACTUAL 0:80971e65b431
548 ====
548 ====
549
549
550 $ hg --cwd b import ../patch1 ../patch2 ../patch3
550 $ hg --cwd b import ../patch1 ../patch2 ../patch3
551 applying ../patch1
551 applying ../patch1
552 ====
552 ====
553 VISIBLE 0:80971e65b431
553 VISIBLE 0:80971e65b431
554 M a
554 M a
555 ACTUAL 0:80971e65b431
555 ACTUAL 0:80971e65b431
556 M a
556 M a
557 ====
557 ====
558 applying ../patch2
558 applying ../patch2
559 ====
559 ====
560 VISIBLE 1:1d4bd90af0e4
560 VISIBLE 1:1d4bd90af0e4
561 M a
561 M a
562 ACTUAL 0:80971e65b431
562 ACTUAL 0:80971e65b431
563 M a
563 M a
564 ====
564 ====
565 applying ../patch3
565 applying ../patch3
566 ====
566 ====
567 VISIBLE 2:6d019af21222
567 VISIBLE 2:6d019af21222
568 A foo
568 A foo
569 ACTUAL 0:80971e65b431
569 ACTUAL 0:80971e65b431
570 M a
570 M a
571 ====
571 ====
572
572
573 $ hg --cwd b rollback -q
573 $ hg --cwd b rollback -q
574 $ (cd b && sh "$TESTTMP/checkvisibility.sh")
574 $ (cd b && sh "$TESTTMP/checkvisibility.sh")
575 ====
575 ====
576 VISIBLE 0:80971e65b431
576 VISIBLE 0:80971e65b431
577 M a
577 M a
578 ACTUAL 0:80971e65b431
578 ACTUAL 0:80971e65b431
579 M a
579 M a
580 ====
580 ====
581 $ hg --cwd b revert --no-backup a
581 $ hg --cwd b revert --no-backup a
582 $ rm -f b/foo
582 $ rm -f b/foo
583
583
584 $ cat >> b/.hg/hgrc <<EOF
584 $ cat >> b/.hg/hgrc <<EOF
585 > [hooks]
585 > [hooks]
586 > precommit.visibility =
586 > precommit.visibility =
587 > EOF
587 > EOF
588
588
589 == test visibility to pretxncommit external hook
589 == test visibility to pretxncommit external hook
590
590
591 $ cat >> b/.hg/hgrc <<EOF
591 $ cat >> b/.hg/hgrc <<EOF
592 > [hooks]
592 > [hooks]
593 > pretxncommit.visibility = sh $TESTTMP/checkvisibility.sh
593 > pretxncommit.visibility = sh $TESTTMP/checkvisibility.sh
594 > EOF
594 > EOF
595
595
596 $ (cd b && sh "$TESTTMP/checkvisibility.sh")
596 $ (cd b && sh "$TESTTMP/checkvisibility.sh")
597 ====
597 ====
598 VISIBLE 0:80971e65b431
598 VISIBLE 0:80971e65b431
599 ACTUAL 0:80971e65b431
599 ACTUAL 0:80971e65b431
600 ====
600 ====
601
601
602 $ hg --cwd b import ../patch1 ../patch2 ../patch3
602 $ hg --cwd b import ../patch1 ../patch2 ../patch3
603 applying ../patch1
603 applying ../patch1
604 ====
604 ====
605 VISIBLE 0:80971e65b431
605 VISIBLE 0:80971e65b431
606 M a
606 M a
607 ACTUAL 0:80971e65b431
607 ACTUAL 0:80971e65b431
608 M a
608 M a
609 ====
609 ====
610 applying ../patch2
610 applying ../patch2
611 ====
611 ====
612 VISIBLE 1:1d4bd90af0e4
612 VISIBLE 1:1d4bd90af0e4
613 M a
613 M a
614 ACTUAL 0:80971e65b431
614 ACTUAL 0:80971e65b431
615 M a
615 M a
616 ====
616 ====
617 applying ../patch3
617 applying ../patch3
618 ====
618 ====
619 VISIBLE 2:6d019af21222
619 VISIBLE 2:6d019af21222
620 A foo
620 A foo
621 ACTUAL 0:80971e65b431
621 ACTUAL 0:80971e65b431
622 M a
622 M a
623 ====
623 ====
624
624
625 $ hg --cwd b rollback -q
625 $ hg --cwd b rollback -q
626 $ (cd b && sh "$TESTTMP/checkvisibility.sh")
626 $ (cd b && sh "$TESTTMP/checkvisibility.sh")
627 ====
627 ====
628 VISIBLE 0:80971e65b431
628 VISIBLE 0:80971e65b431
629 M a
629 M a
630 ACTUAL 0:80971e65b431
630 ACTUAL 0:80971e65b431
631 M a
631 M a
632 ====
632 ====
633 $ hg --cwd b revert --no-backup a
633 $ hg --cwd b revert --no-backup a
634 $ rm -f b/foo
634 $ rm -f b/foo
635
635
636 $ cat >> b/.hg/hgrc <<EOF
636 $ cat >> b/.hg/hgrc <<EOF
637 > [hooks]
637 > [hooks]
638 > pretxncommit.visibility =
638 > pretxncommit.visibility =
639 > EOF
639 > EOF
640
640
641 $ rm -r b
641 $ rm -r b
642
642
643
643
644 importing a patch in a subdirectory failed at the commit stage
644 importing a patch in a subdirectory failed at the commit stage
645
645
646 $ echo line 2 >> a/d1/d2/a
646 $ echo line 2 >> a/d1/d2/a
647 $ hg --cwd a ci -u someoneelse -d '1 0' -m'subdir change'
647 $ hg --cwd a ci -u someoneelse -d '1 0' -m'subdir change'
648
648
649 hg import in a subdirectory
649 hg import in a subdirectory
650
650
651 $ hg clone -r0 a b
651 $ hg clone -r0 a b
652 adding changesets
652 adding changesets
653 adding manifests
653 adding manifests
654 adding file changes
654 adding file changes
655 added 1 changesets with 2 changes to 2 files
655 added 1 changesets with 2 changes to 2 files
656 updating to branch default
656 updating to branch default
657 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
657 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
658 $ hg --cwd a export tip > tmp
658 $ hg --cwd a export tip > tmp
659 $ sed -e 's/d1\/d2\///' < tmp > subdir-tip.patch
659 $ sed -e 's/d1\/d2\///' < tmp > subdir-tip.patch
660 $ dir=`pwd`
660 $ dir=`pwd`
661 $ cd b/d1/d2 2>&1 > /dev/null
661 $ cd b/d1/d2 2>&1 > /dev/null
662 $ hg import ../../../subdir-tip.patch
662 $ hg import ../../../subdir-tip.patch
663 applying ../../../subdir-tip.patch
663 applying ../../../subdir-tip.patch
664 $ cd "$dir"
664 $ cd "$dir"
665
665
666 message should be 'subdir change'
666 message should be 'subdir change'
667 committer should be 'someoneelse'
667 committer should be 'someoneelse'
668
668
669 $ hg --cwd b tip
669 $ hg --cwd b tip
670 changeset: 1:3577f5aea227
670 changeset: 1:3577f5aea227
671 tag: tip
671 tag: tip
672 user: someoneelse
672 user: someoneelse
673 date: Thu Jan 01 00:00:01 1970 +0000
673 date: Thu Jan 01 00:00:01 1970 +0000
674 summary: subdir change
674 summary: subdir change
675
675
676
676
677 should be empty
677 should be empty
678
678
679 $ hg --cwd b status
679 $ hg --cwd b status
680
680
681
681
682 Test fuzziness (ambiguous patch location, fuzz=2)
682 Test fuzziness (ambiguous patch location, fuzz=2)
683
683
684 $ hg init fuzzy
684 $ hg init fuzzy
685 $ cd fuzzy
685 $ cd fuzzy
686 $ echo line1 > a
686 $ echo line1 > a
687 $ echo line0 >> a
687 $ echo line0 >> a
688 $ echo line3 >> a
688 $ echo line3 >> a
689 $ hg ci -Am adda
689 $ hg ci -Am adda
690 adding a
690 adding a
691 $ echo line1 > a
691 $ echo line1 > a
692 $ echo line2 >> a
692 $ echo line2 >> a
693 $ echo line0 >> a
693 $ echo line0 >> a
694 $ echo line3 >> a
694 $ echo line3 >> a
695 $ hg ci -m change a
695 $ hg ci -m change a
696 $ hg export tip > fuzzy-tip.patch
696 $ hg export tip > fuzzy-tip.patch
697 $ hg up -C 0
697 $ hg up -C 0
698 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
698 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
699 $ echo line1 > a
699 $ echo line1 > a
700 $ echo line0 >> a
700 $ echo line0 >> a
701 $ echo line1 >> a
701 $ echo line1 >> a
702 $ echo line0 >> a
702 $ echo line0 >> a
703 $ hg ci -m brancha
703 $ hg ci -m brancha
704 created new head
704 created new head
705 $ hg import --config patch.fuzz=0 -v fuzzy-tip.patch
705 $ hg import --config patch.fuzz=0 -v fuzzy-tip.patch
706 applying fuzzy-tip.patch
706 applying fuzzy-tip.patch
707 patching file a
707 patching file a
708 Hunk #1 FAILED at 0
708 Hunk #1 FAILED at 0
709 1 out of 1 hunks FAILED -- saving rejects to file a.rej
709 1 out of 1 hunks FAILED -- saving rejects to file a.rej
710 abort: patch failed to apply
710 abort: patch failed to apply
711 [255]
711 [255]
712 $ hg import --no-commit -v fuzzy-tip.patch
712 $ hg import --no-commit -v fuzzy-tip.patch
713 applying fuzzy-tip.patch
713 applying fuzzy-tip.patch
714 patching file a
714 patching file a
715 Hunk #1 succeeded at 2 with fuzz 1 (offset 0 lines).
715 Hunk #1 succeeded at 2 with fuzz 1 (offset 0 lines).
716 applied to working directory
716 applied to working directory
717 $ hg revert -a
717 $ hg revert -a
718 reverting a
718 reverting a
719
719
720
720
721 import with --no-commit should have written .hg/last-message.txt
721 import with --no-commit should have written .hg/last-message.txt
722
722
723 $ cat .hg/last-message.txt
723 $ cat .hg/last-message.txt
724 change (no-eol)
724 change (no-eol)
725
725
726
726
727 test fuzziness with eol=auto
727 test fuzziness with eol=auto
728
728
729 $ hg --config patch.eol=auto import --no-commit -v fuzzy-tip.patch
729 $ hg --config patch.eol=auto import --no-commit -v fuzzy-tip.patch
730 applying fuzzy-tip.patch
730 applying fuzzy-tip.patch
731 patching file a
731 patching file a
732 Hunk #1 succeeded at 2 with fuzz 1 (offset 0 lines).
732 Hunk #1 succeeded at 2 with fuzz 1 (offset 0 lines).
733 applied to working directory
733 applied to working directory
734 $ cd ..
734 $ cd ..
735
735
736
736
737 Test hunk touching empty files (issue906)
737 Test hunk touching empty files (issue906)
738
738
739 $ hg init empty
739 $ hg init empty
740 $ cd empty
740 $ cd empty
741 $ touch a
741 $ touch a
742 $ touch b1
742 $ touch b1
743 $ touch c1
743 $ touch c1
744 $ echo d > d
744 $ echo d > d
745 $ hg ci -Am init
745 $ hg ci -Am init
746 adding a
746 adding a
747 adding b1
747 adding b1
748 adding c1
748 adding c1
749 adding d
749 adding d
750 $ echo a > a
750 $ echo a > a
751 $ echo b > b1
751 $ echo b > b1
752 $ hg mv b1 b2
752 $ hg mv b1 b2
753 $ echo c > c1
753 $ echo c > c1
754 $ hg copy c1 c2
754 $ hg copy c1 c2
755 $ rm d
755 $ rm d
756 $ touch d
756 $ touch d
757 $ hg diff --git
757 $ hg diff --git
758 diff --git a/a b/a
758 diff --git a/a b/a
759 --- a/a
759 --- a/a
760 +++ b/a
760 +++ b/a
761 @@ -0,0 +1,1 @@
761 @@ -0,0 +1,1 @@
762 +a
762 +a
763 diff --git a/b1 b/b2
763 diff --git a/b1 b/b2
764 rename from b1
764 rename from b1
765 rename to b2
765 rename to b2
766 --- a/b1
766 --- a/b1
767 +++ b/b2
767 +++ b/b2
768 @@ -0,0 +1,1 @@
768 @@ -0,0 +1,1 @@
769 +b
769 +b
770 diff --git a/c1 b/c1
770 diff --git a/c1 b/c1
771 --- a/c1
771 --- a/c1
772 +++ b/c1
772 +++ b/c1
773 @@ -0,0 +1,1 @@
773 @@ -0,0 +1,1 @@
774 +c
774 +c
775 diff --git a/c1 b/c2
775 diff --git a/c1 b/c2
776 copy from c1
776 copy from c1
777 copy to c2
777 copy to c2
778 --- a/c1
778 --- a/c1
779 +++ b/c2
779 +++ b/c2
780 @@ -0,0 +1,1 @@
780 @@ -0,0 +1,1 @@
781 +c
781 +c
782 diff --git a/d b/d
782 diff --git a/d b/d
783 --- a/d
783 --- a/d
784 +++ b/d
784 +++ b/d
785 @@ -1,1 +0,0 @@
785 @@ -1,1 +0,0 @@
786 -d
786 -d
787 $ hg ci -m empty
787 $ hg ci -m empty
788 $ hg export --git tip > empty.diff
788 $ hg export --git tip > empty.diff
789 $ hg up -C 0
789 $ hg up -C 0
790 4 files updated, 0 files merged, 2 files removed, 0 files unresolved
790 4 files updated, 0 files merged, 2 files removed, 0 files unresolved
791 $ hg import empty.diff
791 $ hg import empty.diff
792 applying empty.diff
792 applying empty.diff
793 $ for name in a b1 b2 c1 c2 d; do
793 $ for name in a b1 b2 c1 c2 d; do
794 > echo % $name file
794 > echo % $name file
795 > test -f $name && cat $name
795 > test -f $name && cat $name
796 > done
796 > done
797 % a file
797 % a file
798 a
798 a
799 % b1 file
799 % b1 file
800 % b2 file
800 % b2 file
801 b
801 b
802 % c1 file
802 % c1 file
803 c
803 c
804 % c2 file
804 % c2 file
805 c
805 c
806 % d file
806 % d file
807 $ cd ..
807 $ cd ..
808
808
809
809
810 Test importing a patch ending with a binary file removal
810 Test importing a patch ending with a binary file removal
811
811
812 $ hg init binaryremoval
812 $ hg init binaryremoval
813 $ cd binaryremoval
813 $ cd binaryremoval
814 $ echo a > a
814 $ echo a > a
815 $ $PYTHON -c "file('b', 'wb').write('a\x00b')"
815 $ $PYTHON -c "file('b', 'wb').write('a\x00b')"
816 $ hg ci -Am addall
816 $ hg ci -Am addall
817 adding a
817 adding a
818 adding b
818 adding b
819 $ hg rm a
819 $ hg rm a
820 $ hg rm b
820 $ hg rm b
821 $ hg st
821 $ hg st
822 R a
822 R a
823 R b
823 R b
824 $ hg ci -m remove
824 $ hg ci -m remove
825 $ hg export --git . > remove.diff
825 $ hg export --git . > remove.diff
826 $ cat remove.diff | grep git
826 $ cat remove.diff | grep git
827 diff --git a/a b/a
827 diff --git a/a b/a
828 diff --git a/b b/b
828 diff --git a/b b/b
829 $ hg up -C 0
829 $ hg up -C 0
830 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
830 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
831 $ hg import remove.diff
831 $ hg import remove.diff
832 applying remove.diff
832 applying remove.diff
833 $ hg manifest
833 $ hg manifest
834 $ cd ..
834 $ cd ..
835
835
836
836
837 Issue927: test update+rename with common name
837 Issue927: test update+rename with common name
838
838
839 $ hg init t
839 $ hg init t
840 $ cd t
840 $ cd t
841 $ touch a
841 $ touch a
842 $ hg ci -Am t
842 $ hg ci -Am t
843 adding a
843 adding a
844 $ echo a > a
844 $ echo a > a
845
845
846 Here, bfile.startswith(afile)
846 Here, bfile.startswith(afile)
847
847
848 $ hg copy a a2
848 $ hg copy a a2
849 $ hg ci -m copya
849 $ hg ci -m copya
850 $ hg export --git tip > copy.diff
850 $ hg export --git tip > copy.diff
851 $ hg up -C 0
851 $ hg up -C 0
852 1 files updated, 0 files merged, 1 files removed, 0 files unresolved
852 1 files updated, 0 files merged, 1 files removed, 0 files unresolved
853 $ hg import copy.diff
853 $ hg import copy.diff
854 applying copy.diff
854 applying copy.diff
855
855
856 a should contain an 'a'
856 a should contain an 'a'
857
857
858 $ cat a
858 $ cat a
859 a
859 a
860
860
861 and a2 should have duplicated it
861 and a2 should have duplicated it
862
862
863 $ cat a2
863 $ cat a2
864 a
864 a
865 $ cd ..
865 $ cd ..
866
866
867
867
868 test -p0
868 test -p0
869
869
870 $ hg init p0
870 $ hg init p0
871 $ cd p0
871 $ cd p0
872 $ echo a > a
872 $ echo a > a
873 $ hg ci -Am t
873 $ hg ci -Am t
874 adding a
874 adding a
875 $ hg import -p foo
875 $ hg import -p foo
876 abort: invalid value 'foo' for option -p, expected int
876 abort: invalid value 'foo' for option -p, expected int
877 [255]
877 [255]
878 $ hg import -p0 - << EOF
878 $ hg import -p0 - << EOF
879 > foobar
879 > foobar
880 > --- a Sat Apr 12 22:43:58 2008 -0400
880 > --- a Sat Apr 12 22:43:58 2008 -0400
881 > +++ a Sat Apr 12 22:44:05 2008 -0400
881 > +++ a Sat Apr 12 22:44:05 2008 -0400
882 > @@ -1,1 +1,1 @@
882 > @@ -1,1 +1,1 @@
883 > -a
883 > -a
884 > +bb
884 > +bb
885 > EOF
885 > EOF
886 applying patch from stdin
886 applying patch from stdin
887 $ hg status
887 $ hg status
888 $ cat a
888 $ cat a
889 bb
889 bb
890
890
891 test --prefix
891 test --prefix
892
892
893 $ mkdir -p dir/dir2
893 $ mkdir -p dir/dir2
894 $ echo b > dir/dir2/b
894 $ echo b > dir/dir2/b
895 $ hg ci -Am b
895 $ hg ci -Am b
896 adding dir/dir2/b
896 adding dir/dir2/b
897 $ hg import -p2 --prefix dir - << EOF
897 $ hg import -p2 --prefix dir - << EOF
898 > foobar
898 > foobar
899 > --- drop1/drop2/dir2/b
899 > --- drop1/drop2/dir2/b
900 > +++ drop1/drop2/dir2/b
900 > +++ drop1/drop2/dir2/b
901 > @@ -1,1 +1,1 @@
901 > @@ -1,1 +1,1 @@
902 > -b
902 > -b
903 > +cc
903 > +cc
904 > EOF
904 > EOF
905 applying patch from stdin
905 applying patch from stdin
906 $ hg status
906 $ hg status
907 $ cat dir/dir2/b
907 $ cat dir/dir2/b
908 cc
908 cc
909 $ cd ..
909 $ cd ..
910
910
911
911
912 test paths outside repo root
912 test paths outside repo root
913
913
914 $ mkdir outside
914 $ mkdir outside
915 $ touch outside/foo
915 $ touch outside/foo
916 $ hg init inside
916 $ hg init inside
917 $ cd inside
917 $ cd inside
918 $ hg import - <<EOF
918 $ hg import - <<EOF
919 > diff --git a/a b/b
919 > diff --git a/a b/b
920 > rename from ../outside/foo
920 > rename from ../outside/foo
921 > rename to bar
921 > rename to bar
922 > EOF
922 > EOF
923 applying patch from stdin
923 applying patch from stdin
924 abort: path contains illegal component: ../outside/foo (glob)
924 abort: path contains illegal component: ../outside/foo (glob)
925 [255]
925 [255]
926 $ cd ..
926 $ cd ..
927
927
928
928
929 test import with similarity and git and strip (issue295 et al.)
929 test import with similarity and git and strip (issue295 et al.)
930
930
931 $ hg init sim
931 $ hg init sim
932 $ cd sim
932 $ cd sim
933 $ echo 'this is a test' > a
933 $ echo 'this is a test' > a
934 $ hg ci -Ama
934 $ hg ci -Ama
935 adding a
935 adding a
936 $ cat > ../rename.diff <<EOF
936 $ cat > ../rename.diff <<EOF
937 > diff --git a/foo/a b/foo/a
937 > diff --git a/foo/a b/foo/a
938 > deleted file mode 100644
938 > deleted file mode 100644
939 > --- a/foo/a
939 > --- a/foo/a
940 > +++ /dev/null
940 > +++ /dev/null
941 > @@ -1,1 +0,0 @@
941 > @@ -1,1 +0,0 @@
942 > -this is a test
942 > -this is a test
943 > diff --git a/foo/b b/foo/b
943 > diff --git a/foo/b b/foo/b
944 > new file mode 100644
944 > new file mode 100644
945 > --- /dev/null
945 > --- /dev/null
946 > +++ b/foo/b
946 > +++ b/foo/b
947 > @@ -0,0 +1,2 @@
947 > @@ -0,0 +1,2 @@
948 > +this is a test
948 > +this is a test
949 > +foo
949 > +foo
950 > EOF
950 > EOF
951 $ hg import --no-commit -v -s 1 ../rename.diff -p2
951 $ hg import --no-commit -v -s 1 ../rename.diff -p2
952 applying ../rename.diff
952 applying ../rename.diff
953 patching file a
953 patching file a
954 patching file b
954 patching file b
955 adding b
955 adding b
956 recording removal of a as rename to b (88% similar)
956 recording removal of a as rename to b (88% similar)
957 applied to working directory
957 applied to working directory
958 $ hg st -C
958 $ hg st -C
959 A b
959 A b
960 a
960 a
961 R a
961 R a
962 $ hg revert -a
962 $ hg revert -a
963 undeleting a
963 undeleting a
964 forgetting b
964 forgetting b
965 $ rm b
965 $ rm b
966 $ hg import --no-commit -v -s 100 ../rename.diff -p2
966 $ hg import --no-commit -v -s 100 ../rename.diff -p2
967 applying ../rename.diff
967 applying ../rename.diff
968 patching file a
968 patching file a
969 patching file b
969 patching file b
970 adding b
970 adding b
971 applied to working directory
971 applied to working directory
972 $ hg st -C
972 $ hg st -C
973 A b
973 A b
974 R a
974 R a
975 $ cd ..
975 $ cd ..
976
976
977
977
978 Issue1495: add empty file from the end of patch
978 Issue1495: add empty file from the end of patch
979
979
980 $ hg init addemptyend
980 $ hg init addemptyend
981 $ cd addemptyend
981 $ cd addemptyend
982 $ touch a
982 $ touch a
983 $ hg addremove
983 $ hg addremove
984 adding a
984 adding a
985 $ hg ci -m "commit"
985 $ hg ci -m "commit"
986 $ cat > a.patch <<EOF
986 $ cat > a.patch <<EOF
987 > add a, b
987 > add a, b
988 > diff --git a/a b/a
988 > diff --git a/a b/a
989 > --- a/a
989 > --- a/a
990 > +++ b/a
990 > +++ b/a
991 > @@ -0,0 +1,1 @@
991 > @@ -0,0 +1,1 @@
992 > +a
992 > +a
993 > diff --git a/b b/b
993 > diff --git a/b b/b
994 > new file mode 100644
994 > new file mode 100644
995 > EOF
995 > EOF
996 $ hg import --no-commit a.patch
996 $ hg import --no-commit a.patch
997 applying a.patch
997 applying a.patch
998
998
999 apply a good patch followed by an empty patch (mainly to ensure
999 apply a good patch followed by an empty patch (mainly to ensure
1000 that dirstate is *not* updated when import crashes)
1000 that dirstate is *not* updated when import crashes)
1001 $ hg update -q -C .
1001 $ hg update -q -C .
1002 $ rm b
1002 $ rm b
1003 $ touch empty.patch
1003 $ touch empty.patch
1004 $ hg import a.patch empty.patch
1004 $ hg import a.patch empty.patch
1005 applying a.patch
1005 applying a.patch
1006 applying empty.patch
1006 applying empty.patch
1007 transaction abort!
1007 transaction abort!
1008 rollback completed
1008 rollback completed
1009 abort: empty.patch: no diffs found
1009 abort: empty.patch: no diffs found
1010 [255]
1010 [255]
1011 $ hg tip --template '{rev} {desc|firstline}\n'
1011 $ hg tip --template '{rev} {desc|firstline}\n'
1012 0 commit
1012 0 commit
1013 $ hg -q status
1013 $ hg -q status
1014 M a
1014 M a
1015 $ cd ..
1015 $ cd ..
1016
1016
1017 create file when source is not /dev/null
1017 create file when source is not /dev/null
1018
1018
1019 $ cat > create.patch <<EOF
1019 $ cat > create.patch <<EOF
1020 > diff -Naur proj-orig/foo proj-new/foo
1020 > diff -Naur proj-orig/foo proj-new/foo
1021 > --- proj-orig/foo 1969-12-31 16:00:00.000000000 -0800
1021 > --- proj-orig/foo 1969-12-31 16:00:00.000000000 -0800
1022 > +++ proj-new/foo 2009-07-17 16:50:45.801368000 -0700
1022 > +++ proj-new/foo 2009-07-17 16:50:45.801368000 -0700
1023 > @@ -0,0 +1,1 @@
1023 > @@ -0,0 +1,1 @@
1024 > +a
1024 > +a
1025 > EOF
1025 > EOF
1026
1026
1027 some people have patches like the following too
1027 some people have patches like the following too
1028
1028
1029 $ cat > create2.patch <<EOF
1029 $ cat > create2.patch <<EOF
1030 > diff -Naur proj-orig/foo proj-new/foo
1030 > diff -Naur proj-orig/foo proj-new/foo
1031 > --- proj-orig/foo.orig 1969-12-31 16:00:00.000000000 -0800
1031 > --- proj-orig/foo.orig 1969-12-31 16:00:00.000000000 -0800
1032 > +++ proj-new/foo 2009-07-17 16:50:45.801368000 -0700
1032 > +++ proj-new/foo 2009-07-17 16:50:45.801368000 -0700
1033 > @@ -0,0 +1,1 @@
1033 > @@ -0,0 +1,1 @@
1034 > +a
1034 > +a
1035 > EOF
1035 > EOF
1036 $ hg init oddcreate
1036 $ hg init oddcreate
1037 $ cd oddcreate
1037 $ cd oddcreate
1038 $ hg import --no-commit ../create.patch
1038 $ hg import --no-commit ../create.patch
1039 applying ../create.patch
1039 applying ../create.patch
1040 $ cat foo
1040 $ cat foo
1041 a
1041 a
1042 $ rm foo
1042 $ rm foo
1043 $ hg revert foo
1043 $ hg revert foo
1044 $ hg import --no-commit ../create2.patch
1044 $ hg import --no-commit ../create2.patch
1045 applying ../create2.patch
1045 applying ../create2.patch
1046 $ cat foo
1046 $ cat foo
1047 a
1047 a
1048
1048
1049 $ cd ..
1049 $ cd ..
1050
1050
1051 Issue1859: first line mistaken for email headers
1051 Issue1859: first line mistaken for email headers
1052
1052
1053 $ hg init emailconfusion
1053 $ hg init emailconfusion
1054 $ cd emailconfusion
1054 $ cd emailconfusion
1055 $ cat > a.patch <<EOF
1055 $ cat > a.patch <<EOF
1056 > module: summary
1056 > module: summary
1057 >
1057 >
1058 > description
1058 > description
1059 >
1059 >
1060 >
1060 >
1061 > diff -r 000000000000 -r 9b4c1e343b55 test.txt
1061 > diff -r 000000000000 -r 9b4c1e343b55 test.txt
1062 > --- /dev/null
1062 > --- /dev/null
1063 > +++ b/a
1063 > +++ b/a
1064 > @@ -0,0 +1,1 @@
1064 > @@ -0,0 +1,1 @@
1065 > +a
1065 > +a
1066 > EOF
1066 > EOF
1067 $ hg import -d '0 0' a.patch
1067 $ hg import -d '0 0' a.patch
1068 applying a.patch
1068 applying a.patch
1069 $ hg parents -v
1069 $ hg parents -v
1070 changeset: 0:5a681217c0ad
1070 changeset: 0:5a681217c0ad
1071 tag: tip
1071 tag: tip
1072 user: test
1072 user: test
1073 date: Thu Jan 01 00:00:00 1970 +0000
1073 date: Thu Jan 01 00:00:00 1970 +0000
1074 files: a
1074 files: a
1075 description:
1075 description:
1076 module: summary
1076 module: summary
1077
1077
1078 description
1078 description
1079
1079
1080
1080
1081 $ cd ..
1081 $ cd ..
1082
1082
1083
1083
1084 in commit message
1084 in commit message
1085
1085
1086 $ hg init commitconfusion
1086 $ hg init commitconfusion
1087 $ cd commitconfusion
1087 $ cd commitconfusion
1088 $ cat > a.patch <<EOF
1088 $ cat > a.patch <<EOF
1089 > module: summary
1089 > module: summary
1090 >
1090 >
1091 > --- description
1091 > --- description
1092 >
1092 >
1093 > diff --git a/a b/a
1093 > diff --git a/a b/a
1094 > new file mode 100644
1094 > new file mode 100644
1095 > --- /dev/null
1095 > --- /dev/null
1096 > +++ b/a
1096 > +++ b/a
1097 > @@ -0,0 +1,1 @@
1097 > @@ -0,0 +1,1 @@
1098 > +a
1098 > +a
1099 > EOF
1099 > EOF
1100 > hg import -d '0 0' a.patch
1100 > hg import -d '0 0' a.patch
1101 > hg parents -v
1101 > hg parents -v
1102 > cd ..
1102 > cd ..
1103 >
1103 >
1104 > echo '% tricky header splitting'
1104 > echo '% tricky header splitting'
1105 > cat > trickyheaders.patch <<EOF
1105 > cat > trickyheaders.patch <<EOF
1106 > From: User A <user@a>
1106 > From: User A <user@a>
1107 > Subject: [PATCH] from: tricky!
1107 > Subject: [PATCH] from: tricky!
1108 >
1108 >
1109 > # HG changeset patch
1109 > # HG changeset patch
1110 > # User User B
1110 > # User User B
1111 > # Date 1266264441 18000
1111 > # Date 1266264441 18000
1112 > # Branch stable
1112 > # Branch stable
1113 > # Node ID f2be6a1170ac83bf31cb4ae0bad00d7678115bc0
1113 > # Node ID f2be6a1170ac83bf31cb4ae0bad00d7678115bc0
1114 > # Parent 0000000000000000000000000000000000000000
1114 > # Parent 0000000000000000000000000000000000000000
1115 > from: tricky!
1115 > from: tricky!
1116 >
1116 >
1117 > That is not a header.
1117 > That is not a header.
1118 >
1118 >
1119 > diff -r 000000000000 -r f2be6a1170ac foo
1119 > diff -r 000000000000 -r f2be6a1170ac foo
1120 > --- /dev/null
1120 > --- /dev/null
1121 > +++ b/foo
1121 > +++ b/foo
1122 > @@ -0,0 +1,1 @@
1122 > @@ -0,0 +1,1 @@
1123 > +foo
1123 > +foo
1124 > EOF
1124 > EOF
1125 applying a.patch
1125 applying a.patch
1126 changeset: 0:f34d9187897d
1126 changeset: 0:f34d9187897d
1127 tag: tip
1127 tag: tip
1128 user: test
1128 user: test
1129 date: Thu Jan 01 00:00:00 1970 +0000
1129 date: Thu Jan 01 00:00:00 1970 +0000
1130 files: a
1130 files: a
1131 description:
1131 description:
1132 module: summary
1132 module: summary
1133
1133
1134
1134
1135 % tricky header splitting
1135 % tricky header splitting
1136
1136
1137 $ hg init trickyheaders
1137 $ hg init trickyheaders
1138 $ cd trickyheaders
1138 $ cd trickyheaders
1139 $ hg import -d '0 0' ../trickyheaders.patch
1139 $ hg import -d '0 0' ../trickyheaders.patch
1140 applying ../trickyheaders.patch
1140 applying ../trickyheaders.patch
1141 $ hg export --git tip
1141 $ hg export --git tip
1142 # HG changeset patch
1142 # HG changeset patch
1143 # User User B
1143 # User User B
1144 # Date 0 0
1144 # Date 0 0
1145 # Thu Jan 01 00:00:00 1970 +0000
1145 # Thu Jan 01 00:00:00 1970 +0000
1146 # Node ID eb56ab91903632294ac504838508cb370c0901d2
1146 # Node ID eb56ab91903632294ac504838508cb370c0901d2
1147 # Parent 0000000000000000000000000000000000000000
1147 # Parent 0000000000000000000000000000000000000000
1148 from: tricky!
1148 from: tricky!
1149
1149
1150 That is not a header.
1150 That is not a header.
1151
1151
1152 diff --git a/foo b/foo
1152 diff --git a/foo b/foo
1153 new file mode 100644
1153 new file mode 100644
1154 --- /dev/null
1154 --- /dev/null
1155 +++ b/foo
1155 +++ b/foo
1156 @@ -0,0 +1,1 @@
1156 @@ -0,0 +1,1 @@
1157 +foo
1157 +foo
1158 $ cd ..
1158 $ cd ..
1159
1159
1160
1160
1161 Issue2102: hg export and hg import speak different languages
1161 Issue2102: hg export and hg import speak different languages
1162
1162
1163 $ hg init issue2102
1163 $ hg init issue2102
1164 $ cd issue2102
1164 $ cd issue2102
1165 $ mkdir -p src/cmd/gc
1165 $ mkdir -p src/cmd/gc
1166 $ touch src/cmd/gc/mksys.bash
1166 $ touch src/cmd/gc/mksys.bash
1167 $ hg ci -Am init
1167 $ hg ci -Am init
1168 adding src/cmd/gc/mksys.bash
1168 adding src/cmd/gc/mksys.bash
1169 $ hg import - <<EOF
1169 $ hg import - <<EOF
1170 > # HG changeset patch
1170 > # HG changeset patch
1171 > # User Rob Pike
1171 > # User Rob Pike
1172 > # Date 1216685449 25200
1172 > # Date 1216685449 25200
1173 > # Node ID 03aa2b206f499ad6eb50e6e207b9e710d6409c98
1173 > # Node ID 03aa2b206f499ad6eb50e6e207b9e710d6409c98
1174 > # Parent 93d10138ad8df586827ca90b4ddb5033e21a3a84
1174 > # Parent 93d10138ad8df586827ca90b4ddb5033e21a3a84
1175 > help management of empty pkg and lib directories in perforce
1175 > help management of empty pkg and lib directories in perforce
1176 >
1176 >
1177 > R=gri
1177 > R=gri
1178 > DELTA=4 (4 added, 0 deleted, 0 changed)
1178 > DELTA=4 (4 added, 0 deleted, 0 changed)
1179 > OCL=13328
1179 > OCL=13328
1180 > CL=13328
1180 > CL=13328
1181 >
1181 >
1182 > diff --git a/lib/place-holder b/lib/place-holder
1182 > diff --git a/lib/place-holder b/lib/place-holder
1183 > new file mode 100644
1183 > new file mode 100644
1184 > --- /dev/null
1184 > --- /dev/null
1185 > +++ b/lib/place-holder
1185 > +++ b/lib/place-holder
1186 > @@ -0,0 +1,2 @@
1186 > @@ -0,0 +1,2 @@
1187 > +perforce does not maintain empty directories.
1187 > +perforce does not maintain empty directories.
1188 > +this file helps.
1188 > +this file helps.
1189 > diff --git a/pkg/place-holder b/pkg/place-holder
1189 > diff --git a/pkg/place-holder b/pkg/place-holder
1190 > new file mode 100644
1190 > new file mode 100644
1191 > --- /dev/null
1191 > --- /dev/null
1192 > +++ b/pkg/place-holder
1192 > +++ b/pkg/place-holder
1193 > @@ -0,0 +1,2 @@
1193 > @@ -0,0 +1,2 @@
1194 > +perforce does not maintain empty directories.
1194 > +perforce does not maintain empty directories.
1195 > +this file helps.
1195 > +this file helps.
1196 > diff --git a/src/cmd/gc/mksys.bash b/src/cmd/gc/mksys.bash
1196 > diff --git a/src/cmd/gc/mksys.bash b/src/cmd/gc/mksys.bash
1197 > old mode 100644
1197 > old mode 100644
1198 > new mode 100755
1198 > new mode 100755
1199 > EOF
1199 > EOF
1200 applying patch from stdin
1200 applying patch from stdin
1201
1201
1202 #if execbit
1202 #if execbit
1203
1203
1204 $ hg sum
1204 $ hg sum
1205 parent: 1:d59915696727 tip
1205 parent: 1:d59915696727 tip
1206 help management of empty pkg and lib directories in perforce
1206 help management of empty pkg and lib directories in perforce
1207 branch: default
1207 branch: default
1208 commit: (clean)
1208 commit: (clean)
1209 update: (current)
1209 update: (current)
1210 phases: 2 draft
1210 phases: 2 draft
1211
1211
1212 $ hg diff --git -c tip
1212 $ hg diff --git -c tip
1213 diff --git a/lib/place-holder b/lib/place-holder
1213 diff --git a/lib/place-holder b/lib/place-holder
1214 new file mode 100644
1214 new file mode 100644
1215 --- /dev/null
1215 --- /dev/null
1216 +++ b/lib/place-holder
1216 +++ b/lib/place-holder
1217 @@ -0,0 +1,2 @@
1217 @@ -0,0 +1,2 @@
1218 +perforce does not maintain empty directories.
1218 +perforce does not maintain empty directories.
1219 +this file helps.
1219 +this file helps.
1220 diff --git a/pkg/place-holder b/pkg/place-holder
1220 diff --git a/pkg/place-holder b/pkg/place-holder
1221 new file mode 100644
1221 new file mode 100644
1222 --- /dev/null
1222 --- /dev/null
1223 +++ b/pkg/place-holder
1223 +++ b/pkg/place-holder
1224 @@ -0,0 +1,2 @@
1224 @@ -0,0 +1,2 @@
1225 +perforce does not maintain empty directories.
1225 +perforce does not maintain empty directories.
1226 +this file helps.
1226 +this file helps.
1227 diff --git a/src/cmd/gc/mksys.bash b/src/cmd/gc/mksys.bash
1227 diff --git a/src/cmd/gc/mksys.bash b/src/cmd/gc/mksys.bash
1228 old mode 100644
1228 old mode 100644
1229 new mode 100755
1229 new mode 100755
1230
1230
1231 #else
1231 #else
1232
1232
1233 $ hg sum
1233 $ hg sum
1234 parent: 1:28f089cc9ccc tip
1234 parent: 1:28f089cc9ccc tip
1235 help management of empty pkg and lib directories in perforce
1235 help management of empty pkg and lib directories in perforce
1236 branch: default
1236 branch: default
1237 commit: (clean)
1237 commit: (clean)
1238 update: (current)
1238 update: (current)
1239 phases: 2 draft
1239 phases: 2 draft
1240
1240
1241 $ hg diff --git -c tip
1241 $ hg diff --git -c tip
1242 diff --git a/lib/place-holder b/lib/place-holder
1242 diff --git a/lib/place-holder b/lib/place-holder
1243 new file mode 100644
1243 new file mode 100644
1244 --- /dev/null
1244 --- /dev/null
1245 +++ b/lib/place-holder
1245 +++ b/lib/place-holder
1246 @@ -0,0 +1,2 @@
1246 @@ -0,0 +1,2 @@
1247 +perforce does not maintain empty directories.
1247 +perforce does not maintain empty directories.
1248 +this file helps.
1248 +this file helps.
1249 diff --git a/pkg/place-holder b/pkg/place-holder
1249 diff --git a/pkg/place-holder b/pkg/place-holder
1250 new file mode 100644
1250 new file mode 100644
1251 --- /dev/null
1251 --- /dev/null
1252 +++ b/pkg/place-holder
1252 +++ b/pkg/place-holder
1253 @@ -0,0 +1,2 @@
1253 @@ -0,0 +1,2 @@
1254 +perforce does not maintain empty directories.
1254 +perforce does not maintain empty directories.
1255 +this file helps.
1255 +this file helps.
1256
1256
1257 /* The mode change for mksys.bash is missing here, because on platforms */
1257 /* The mode change for mksys.bash is missing here, because on platforms */
1258 /* that don't support execbits, mode changes in patches are ignored when */
1258 /* that don't support execbits, mode changes in patches are ignored when */
1259 /* they are imported. This is obviously also the reason for why the hash */
1259 /* they are imported. This is obviously also the reason for why the hash */
1260 /* in the created changeset is different to the one you see above the */
1260 /* in the created changeset is different to the one you see above the */
1261 /* #else clause */
1261 /* #else clause */
1262
1262
1263 #endif
1263 #endif
1264 $ cd ..
1264 $ cd ..
1265
1265
1266
1266
1267 diff lines looking like headers
1267 diff lines looking like headers
1268
1268
1269 $ hg init difflineslikeheaders
1269 $ hg init difflineslikeheaders
1270 $ cd difflineslikeheaders
1270 $ cd difflineslikeheaders
1271 $ echo a >a
1271 $ echo a >a
1272 $ echo b >b
1272 $ echo b >b
1273 $ echo c >c
1273 $ echo c >c
1274 $ hg ci -Am1
1274 $ hg ci -Am1
1275 adding a
1275 adding a
1276 adding b
1276 adding b
1277 adding c
1277 adding c
1278
1278
1279 $ echo "key: value" >>a
1279 $ echo "key: value" >>a
1280 $ echo "key: value" >>b
1280 $ echo "key: value" >>b
1281 $ echo "foo" >>c
1281 $ echo "foo" >>c
1282 $ hg ci -m2
1282 $ hg ci -m2
1283
1283
1284 $ hg up -C 0
1284 $ hg up -C 0
1285 3 files updated, 0 files merged, 0 files removed, 0 files unresolved
1285 3 files updated, 0 files merged, 0 files removed, 0 files unresolved
1286 $ hg diff --git -c1 >want
1286 $ hg diff --git -c1 >want
1287 $ hg diff -c1 | hg import --no-commit -
1287 $ hg diff -c1 | hg import --no-commit -
1288 applying patch from stdin
1288 applying patch from stdin
1289 $ hg diff --git >have
1289 $ hg diff --git >have
1290 $ diff want have
1290 $ diff want have
1291 $ cd ..
1291 $ cd ..
1292
1292
1293 import a unified diff with no lines of context (diff -U0)
1293 import a unified diff with no lines of context (diff -U0)
1294
1294
1295 $ hg init diffzero
1295 $ hg init diffzero
1296 $ cd diffzero
1296 $ cd diffzero
1297 $ cat > f << EOF
1297 $ cat > f << EOF
1298 > c2
1298 > c2
1299 > c4
1299 > c4
1300 > c5
1300 > c5
1301 > EOF
1301 > EOF
1302 $ hg commit -Am0
1302 $ hg commit -Am0
1303 adding f
1303 adding f
1304
1304
1305 $ hg import --no-commit - << EOF
1305 $ hg import --no-commit - << EOF
1306 > # HG changeset patch
1306 > # HG changeset patch
1307 > # User test
1307 > # User test
1308 > # Date 0 0
1308 > # Date 0 0
1309 > # Node ID f4974ab632f3dee767567b0576c0ec9a4508575c
1309 > # Node ID f4974ab632f3dee767567b0576c0ec9a4508575c
1310 > # Parent 8679a12a975b819fae5f7ad3853a2886d143d794
1310 > # Parent 8679a12a975b819fae5f7ad3853a2886d143d794
1311 > 1
1311 > 1
1312 > diff -r 8679a12a975b -r f4974ab632f3 f
1312 > diff -r 8679a12a975b -r f4974ab632f3 f
1313 > --- a/f Thu Jan 01 00:00:00 1970 +0000
1313 > --- a/f Thu Jan 01 00:00:00 1970 +0000
1314 > +++ b/f Thu Jan 01 00:00:00 1970 +0000
1314 > +++ b/f Thu Jan 01 00:00:00 1970 +0000
1315 > @@ -0,0 +1,1 @@
1315 > @@ -0,0 +1,1 @@
1316 > +c1
1316 > +c1
1317 > @@ -1,0 +3,1 @@
1317 > @@ -1,0 +3,1 @@
1318 > +c3
1318 > +c3
1319 > @@ -3,1 +4,0 @@
1319 > @@ -3,1 +4,0 @@
1320 > -c5
1320 > -c5
1321 > EOF
1321 > EOF
1322 applying patch from stdin
1322 applying patch from stdin
1323
1323
1324 $ cat f
1324 $ cat f
1325 c1
1325 c1
1326 c2
1326 c2
1327 c3
1327 c3
1328 c4
1328 c4
1329
1329
1330 $ cd ..
1330 $ cd ..
1331
1331
1332 no segfault while importing a unified diff which start line is zero but chunk
1332 no segfault while importing a unified diff which start line is zero but chunk
1333 size is non-zero
1333 size is non-zero
1334
1334
1335 $ hg init startlinezero
1335 $ hg init startlinezero
1336 $ cd startlinezero
1336 $ cd startlinezero
1337 $ echo foo > foo
1337 $ echo foo > foo
1338 $ hg commit -Amfoo
1338 $ hg commit -Amfoo
1339 adding foo
1339 adding foo
1340
1340
1341 $ hg import --no-commit - << EOF
1341 $ hg import --no-commit - << EOF
1342 > diff a/foo b/foo
1342 > diff a/foo b/foo
1343 > --- a/foo
1343 > --- a/foo
1344 > +++ b/foo
1344 > +++ b/foo
1345 > @@ -0,1 +0,1 @@
1345 > @@ -0,1 +0,1 @@
1346 > foo
1346 > foo
1347 > EOF
1347 > EOF
1348 applying patch from stdin
1348 applying patch from stdin
1349
1349
1350 $ cd ..
1350 $ cd ..
1351
1351
1352 Test corner case involving fuzz and skew
1352 Test corner case involving fuzz and skew
1353
1353
1354 $ hg init morecornercases
1354 $ hg init morecornercases
1355 $ cd morecornercases
1355 $ cd morecornercases
1356
1356
1357 $ cat > 01-no-context-beginning-of-file.diff <<EOF
1357 $ cat > 01-no-context-beginning-of-file.diff <<EOF
1358 > diff --git a/a b/a
1358 > diff --git a/a b/a
1359 > --- a/a
1359 > --- a/a
1360 > +++ b/a
1360 > +++ b/a
1361 > @@ -1,0 +1,1 @@
1361 > @@ -1,0 +1,1 @@
1362 > +line
1362 > +line
1363 > EOF
1363 > EOF
1364
1364
1365 $ cat > 02-no-context-middle-of-file.diff <<EOF
1365 $ cat > 02-no-context-middle-of-file.diff <<EOF
1366 > diff --git a/a b/a
1366 > diff --git a/a b/a
1367 > --- a/a
1367 > --- a/a
1368 > +++ b/a
1368 > +++ b/a
1369 > @@ -1,1 +1,1 @@
1369 > @@ -1,1 +1,1 @@
1370 > -2
1370 > -2
1371 > +add some skew
1371 > +add some skew
1372 > @@ -2,0 +2,1 @@
1372 > @@ -2,0 +2,1 @@
1373 > +line
1373 > +line
1374 > EOF
1374 > EOF
1375
1375
1376 $ cat > 03-no-context-end-of-file.diff <<EOF
1376 $ cat > 03-no-context-end-of-file.diff <<EOF
1377 > diff --git a/a b/a
1377 > diff --git a/a b/a
1378 > --- a/a
1378 > --- a/a
1379 > +++ b/a
1379 > +++ b/a
1380 > @@ -10,0 +10,1 @@
1380 > @@ -10,0 +10,1 @@
1381 > +line
1381 > +line
1382 > EOF
1382 > EOF
1383
1383
1384 $ cat > 04-middle-of-file-completely-fuzzed.diff <<EOF
1384 $ cat > 04-middle-of-file-completely-fuzzed.diff <<EOF
1385 > diff --git a/a b/a
1385 > diff --git a/a b/a
1386 > --- a/a
1386 > --- a/a
1387 > +++ b/a
1387 > +++ b/a
1388 > @@ -1,1 +1,1 @@
1388 > @@ -1,1 +1,1 @@
1389 > -2
1389 > -2
1390 > +add some skew
1390 > +add some skew
1391 > @@ -2,2 +2,3 @@
1391 > @@ -2,2 +2,3 @@
1392 > not matching, should fuzz
1392 > not matching, should fuzz
1393 > ... a bit
1393 > ... a bit
1394 > +line
1394 > +line
1395 > EOF
1395 > EOF
1396
1396
1397 $ cat > a <<EOF
1397 $ cat > a <<EOF
1398 > 1
1398 > 1
1399 > 2
1399 > 2
1400 > 3
1400 > 3
1401 > 4
1401 > 4
1402 > EOF
1402 > EOF
1403 $ hg ci -Am adda a
1403 $ hg ci -Am adda a
1404 $ for p in *.diff; do
1404 $ for p in *.diff; do
1405 > hg import -v --no-commit $p
1405 > hg import -v --no-commit $p
1406 > cat a
1406 > cat a
1407 > hg revert -aqC a
1407 > hg revert -aqC a
1408 > # patch -p1 < $p
1408 > # patch -p1 < $p
1409 > # cat a
1409 > # cat a
1410 > # hg revert -aC a
1410 > # hg revert -aC a
1411 > done
1411 > done
1412 applying 01-no-context-beginning-of-file.diff
1412 applying 01-no-context-beginning-of-file.diff
1413 patching file a
1413 patching file a
1414 applied to working directory
1414 applied to working directory
1415 1
1415 1
1416 line
1416 line
1417 2
1417 2
1418 3
1418 3
1419 4
1419 4
1420 applying 02-no-context-middle-of-file.diff
1420 applying 02-no-context-middle-of-file.diff
1421 patching file a
1421 patching file a
1422 Hunk #1 succeeded at 2 (offset 1 lines).
1422 Hunk #1 succeeded at 2 (offset 1 lines).
1423 Hunk #2 succeeded at 4 (offset 1 lines).
1423 Hunk #2 succeeded at 4 (offset 1 lines).
1424 applied to working directory
1424 applied to working directory
1425 1
1425 1
1426 add some skew
1426 add some skew
1427 3
1427 3
1428 line
1428 line
1429 4
1429 4
1430 applying 03-no-context-end-of-file.diff
1430 applying 03-no-context-end-of-file.diff
1431 patching file a
1431 patching file a
1432 Hunk #1 succeeded at 5 (offset -6 lines).
1432 Hunk #1 succeeded at 5 (offset -6 lines).
1433 applied to working directory
1433 applied to working directory
1434 1
1434 1
1435 2
1435 2
1436 3
1436 3
1437 4
1437 4
1438 line
1438 line
1439 applying 04-middle-of-file-completely-fuzzed.diff
1439 applying 04-middle-of-file-completely-fuzzed.diff
1440 patching file a
1440 patching file a
1441 Hunk #1 succeeded at 2 (offset 1 lines).
1441 Hunk #1 succeeded at 2 (offset 1 lines).
1442 Hunk #2 succeeded at 5 with fuzz 2 (offset 1 lines).
1442 Hunk #2 succeeded at 5 with fuzz 2 (offset 1 lines).
1443 applied to working directory
1443 applied to working directory
1444 1
1444 1
1445 add some skew
1445 add some skew
1446 3
1446 3
1447 4
1447 4
1448 line
1448 line
1449 $ cd ..
1449 $ cd ..
1450
1450
1451 Test partial application
1451 Test partial application
1452 ------------------------
1452 ------------------------
1453
1453
1454 prepare a stack of patches depending on each other
1454 prepare a stack of patches depending on each other
1455
1455
1456 $ hg init partial
1456 $ hg init partial
1457 $ cd partial
1457 $ cd partial
1458 $ cat << EOF > a
1458 $ cat << EOF > a
1459 > one
1459 > one
1460 > two
1460 > two
1461 > three
1461 > three
1462 > four
1462 > four
1463 > five
1463 > five
1464 > six
1464 > six
1465 > seven
1465 > seven
1466 > EOF
1466 > EOF
1467 $ hg add a
1467 $ hg add a
1468 $ echo 'b' > b
1468 $ echo 'b' > b
1469 $ hg add b
1469 $ hg add b
1470 $ hg commit -m 'initial' -u Babar
1470 $ hg commit -m 'initial' -u Babar
1471 $ cat << EOF > a
1471 $ cat << EOF > a
1472 > one
1472 > one
1473 > two
1473 > two
1474 > 3
1474 > 3
1475 > four
1475 > four
1476 > five
1476 > five
1477 > six
1477 > six
1478 > seven
1478 > seven
1479 > EOF
1479 > EOF
1480 $ hg commit -m 'three' -u Celeste
1480 $ hg commit -m 'three' -u Celeste
1481 $ cat << EOF > a
1481 $ cat << EOF > a
1482 > one
1482 > one
1483 > two
1483 > two
1484 > 3
1484 > 3
1485 > 4
1485 > 4
1486 > five
1486 > five
1487 > six
1487 > six
1488 > seven
1488 > seven
1489 > EOF
1489 > EOF
1490 $ hg commit -m 'four' -u Rataxes
1490 $ hg commit -m 'four' -u Rataxes
1491 $ cat << EOF > a
1491 $ cat << EOF > a
1492 > one
1492 > one
1493 > two
1493 > two
1494 > 3
1494 > 3
1495 > 4
1495 > 4
1496 > 5
1496 > 5
1497 > six
1497 > six
1498 > seven
1498 > seven
1499 > EOF
1499 > EOF
1500 $ echo bb >> b
1500 $ echo bb >> b
1501 $ hg commit -m 'five' -u Arthur
1501 $ hg commit -m 'five' -u Arthur
1502 $ echo 'Babar' > jungle
1502 $ echo 'Babar' > jungle
1503 $ hg add jungle
1503 $ hg add jungle
1504 $ hg ci -m 'jungle' -u Zephir
1504 $ hg ci -m 'jungle' -u Zephir
1505 $ echo 'Celeste' >> jungle
1505 $ echo 'Celeste' >> jungle
1506 $ hg ci -m 'extended jungle' -u Cornelius
1506 $ hg ci -m 'extended jungle' -u Cornelius
1507 $ hg log -G --template '{desc|firstline} [{author}] {diffstat}\n'
1507 $ hg log -G --template '{desc|firstline} [{author}] {diffstat}\n'
1508 @ extended jungle [Cornelius] 1: +1/-0
1508 @ extended jungle [Cornelius] 1: +1/-0
1509 |
1509 |
1510 o jungle [Zephir] 1: +1/-0
1510 o jungle [Zephir] 1: +1/-0
1511 |
1511 |
1512 o five [Arthur] 2: +2/-1
1512 o five [Arthur] 2: +2/-1
1513 |
1513 |
1514 o four [Rataxes] 1: +1/-1
1514 o four [Rataxes] 1: +1/-1
1515 |
1515 |
1516 o three [Celeste] 1: +1/-1
1516 o three [Celeste] 1: +1/-1
1517 |
1517 |
1518 o initial [Babar] 2: +8/-0
1518 o initial [Babar] 2: +8/-0
1519
1519
1520 Adding those config options should not change the output of diffstat. Bugfix #4755.
1521
1522 $ hg log -r . --template '{diffstat}\n'
1523 1: +1/-0
1524 $ hg log -r . --template '{diffstat}\n' --config diff.git=1 \
1525 > --config diff.noprefix=1
1526 1: +1/-0
1520
1527
1521 Importing with some success and some errors:
1528 Importing with some success and some errors:
1522
1529
1523 $ hg update --rev 'desc(initial)'
1530 $ hg update --rev 'desc(initial)'
1524 2 files updated, 0 files merged, 1 files removed, 0 files unresolved
1531 2 files updated, 0 files merged, 1 files removed, 0 files unresolved
1525 $ hg export --rev 'desc(five)' | hg import --partial -
1532 $ hg export --rev 'desc(five)' | hg import --partial -
1526 applying patch from stdin
1533 applying patch from stdin
1527 patching file a
1534 patching file a
1528 Hunk #1 FAILED at 1
1535 Hunk #1 FAILED at 1
1529 1 out of 1 hunks FAILED -- saving rejects to file a.rej
1536 1 out of 1 hunks FAILED -- saving rejects to file a.rej
1530 patch applied partially
1537 patch applied partially
1531 (fix the .rej files and run `hg commit --amend`)
1538 (fix the .rej files and run `hg commit --amend`)
1532 [1]
1539 [1]
1533
1540
1534 $ hg log -G --template '{desc|firstline} [{author}] {diffstat}\n'
1541 $ hg log -G --template '{desc|firstline} [{author}] {diffstat}\n'
1535 @ five [Arthur] 1: +1/-0
1542 @ five [Arthur] 1: +1/-0
1536 |
1543 |
1537 | o extended jungle [Cornelius] 1: +1/-0
1544 | o extended jungle [Cornelius] 1: +1/-0
1538 | |
1545 | |
1539 | o jungle [Zephir] 1: +1/-0
1546 | o jungle [Zephir] 1: +1/-0
1540 | |
1547 | |
1541 | o five [Arthur] 2: +2/-1
1548 | o five [Arthur] 2: +2/-1
1542 | |
1549 | |
1543 | o four [Rataxes] 1: +1/-1
1550 | o four [Rataxes] 1: +1/-1
1544 | |
1551 | |
1545 | o three [Celeste] 1: +1/-1
1552 | o three [Celeste] 1: +1/-1
1546 |/
1553 |/
1547 o initial [Babar] 2: +8/-0
1554 o initial [Babar] 2: +8/-0
1548
1555
1549 $ hg export
1556 $ hg export
1550 # HG changeset patch
1557 # HG changeset patch
1551 # User Arthur
1558 # User Arthur
1552 # Date 0 0
1559 # Date 0 0
1553 # Thu Jan 01 00:00:00 1970 +0000
1560 # Thu Jan 01 00:00:00 1970 +0000
1554 # Node ID 26e6446bb2526e2be1037935f5fca2b2706f1509
1561 # Node ID 26e6446bb2526e2be1037935f5fca2b2706f1509
1555 # Parent 8e4f0351909eae6b9cf68c2c076cb54c42b54b2e
1562 # Parent 8e4f0351909eae6b9cf68c2c076cb54c42b54b2e
1556 five
1563 five
1557
1564
1558 diff -r 8e4f0351909e -r 26e6446bb252 b
1565 diff -r 8e4f0351909e -r 26e6446bb252 b
1559 --- a/b Thu Jan 01 00:00:00 1970 +0000
1566 --- a/b Thu Jan 01 00:00:00 1970 +0000
1560 +++ b/b Thu Jan 01 00:00:00 1970 +0000
1567 +++ b/b Thu Jan 01 00:00:00 1970 +0000
1561 @@ -1,1 +1,2 @@
1568 @@ -1,1 +1,2 @@
1562 b
1569 b
1563 +bb
1570 +bb
1564 $ hg status -c .
1571 $ hg status -c .
1565 C a
1572 C a
1566 C b
1573 C b
1567 $ ls
1574 $ ls
1568 a
1575 a
1569 a.rej
1576 a.rej
1570 b
1577 b
1571
1578
1572 Importing with zero success:
1579 Importing with zero success:
1573
1580
1574 $ hg update --rev 'desc(initial)'
1581 $ hg update --rev 'desc(initial)'
1575 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
1582 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
1576 $ hg export --rev 'desc(four)' | hg import --partial -
1583 $ hg export --rev 'desc(four)' | hg import --partial -
1577 applying patch from stdin
1584 applying patch from stdin
1578 patching file a
1585 patching file a
1579 Hunk #1 FAILED at 0
1586 Hunk #1 FAILED at 0
1580 1 out of 1 hunks FAILED -- saving rejects to file a.rej
1587 1 out of 1 hunks FAILED -- saving rejects to file a.rej
1581 patch applied partially
1588 patch applied partially
1582 (fix the .rej files and run `hg commit --amend`)
1589 (fix the .rej files and run `hg commit --amend`)
1583 [1]
1590 [1]
1584
1591
1585 $ hg log -G --template '{desc|firstline} [{author}] {diffstat}\n'
1592 $ hg log -G --template '{desc|firstline} [{author}] {diffstat}\n'
1586 @ four [Rataxes] 0: +0/-0
1593 @ four [Rataxes] 0: +0/-0
1587 |
1594 |
1588 | o five [Arthur] 1: +1/-0
1595 | o five [Arthur] 1: +1/-0
1589 |/
1596 |/
1590 | o extended jungle [Cornelius] 1: +1/-0
1597 | o extended jungle [Cornelius] 1: +1/-0
1591 | |
1598 | |
1592 | o jungle [Zephir] 1: +1/-0
1599 | o jungle [Zephir] 1: +1/-0
1593 | |
1600 | |
1594 | o five [Arthur] 2: +2/-1
1601 | o five [Arthur] 2: +2/-1
1595 | |
1602 | |
1596 | o four [Rataxes] 1: +1/-1
1603 | o four [Rataxes] 1: +1/-1
1597 | |
1604 | |
1598 | o three [Celeste] 1: +1/-1
1605 | o three [Celeste] 1: +1/-1
1599 |/
1606 |/
1600 o initial [Babar] 2: +8/-0
1607 o initial [Babar] 2: +8/-0
1601
1608
1602 $ hg export
1609 $ hg export
1603 # HG changeset patch
1610 # HG changeset patch
1604 # User Rataxes
1611 # User Rataxes
1605 # Date 0 0
1612 # Date 0 0
1606 # Thu Jan 01 00:00:00 1970 +0000
1613 # Thu Jan 01 00:00:00 1970 +0000
1607 # Node ID cb9b1847a74d9ad52e93becaf14b98dbcc274e1e
1614 # Node ID cb9b1847a74d9ad52e93becaf14b98dbcc274e1e
1608 # Parent 8e4f0351909eae6b9cf68c2c076cb54c42b54b2e
1615 # Parent 8e4f0351909eae6b9cf68c2c076cb54c42b54b2e
1609 four
1616 four
1610
1617
1611 $ hg status -c .
1618 $ hg status -c .
1612 C a
1619 C a
1613 C b
1620 C b
1614 $ ls
1621 $ ls
1615 a
1622 a
1616 a.rej
1623 a.rej
1617 b
1624 b
1618
1625
1619 Importing with unknown file:
1626 Importing with unknown file:
1620
1627
1621 $ hg update --rev 'desc(initial)'
1628 $ hg update --rev 'desc(initial)'
1622 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
1629 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
1623 $ hg export --rev 'desc("extended jungle")' | hg import --partial -
1630 $ hg export --rev 'desc("extended jungle")' | hg import --partial -
1624 applying patch from stdin
1631 applying patch from stdin
1625 unable to find 'jungle' for patching
1632 unable to find 'jungle' for patching
1626 (use '--prefix' to apply patch relative to the current directory)
1633 (use '--prefix' to apply patch relative to the current directory)
1627 1 out of 1 hunks FAILED -- saving rejects to file jungle.rej
1634 1 out of 1 hunks FAILED -- saving rejects to file jungle.rej
1628 patch applied partially
1635 patch applied partially
1629 (fix the .rej files and run `hg commit --amend`)
1636 (fix the .rej files and run `hg commit --amend`)
1630 [1]
1637 [1]
1631
1638
1632 $ hg log -G --template '{desc|firstline} [{author}] {diffstat}\n'
1639 $ hg log -G --template '{desc|firstline} [{author}] {diffstat}\n'
1633 @ extended jungle [Cornelius] 0: +0/-0
1640 @ extended jungle [Cornelius] 0: +0/-0
1634 |
1641 |
1635 | o four [Rataxes] 0: +0/-0
1642 | o four [Rataxes] 0: +0/-0
1636 |/
1643 |/
1637 | o five [Arthur] 1: +1/-0
1644 | o five [Arthur] 1: +1/-0
1638 |/
1645 |/
1639 | o extended jungle [Cornelius] 1: +1/-0
1646 | o extended jungle [Cornelius] 1: +1/-0
1640 | |
1647 | |
1641 | o jungle [Zephir] 1: +1/-0
1648 | o jungle [Zephir] 1: +1/-0
1642 | |
1649 | |
1643 | o five [Arthur] 2: +2/-1
1650 | o five [Arthur] 2: +2/-1
1644 | |
1651 | |
1645 | o four [Rataxes] 1: +1/-1
1652 | o four [Rataxes] 1: +1/-1
1646 | |
1653 | |
1647 | o three [Celeste] 1: +1/-1
1654 | o three [Celeste] 1: +1/-1
1648 |/
1655 |/
1649 o initial [Babar] 2: +8/-0
1656 o initial [Babar] 2: +8/-0
1650
1657
1651 $ hg export
1658 $ hg export
1652 # HG changeset patch
1659 # HG changeset patch
1653 # User Cornelius
1660 # User Cornelius
1654 # Date 0 0
1661 # Date 0 0
1655 # Thu Jan 01 00:00:00 1970 +0000
1662 # Thu Jan 01 00:00:00 1970 +0000
1656 # Node ID 1fb1f86bef43c5a75918178f8d23c29fb0a7398d
1663 # Node ID 1fb1f86bef43c5a75918178f8d23c29fb0a7398d
1657 # Parent 8e4f0351909eae6b9cf68c2c076cb54c42b54b2e
1664 # Parent 8e4f0351909eae6b9cf68c2c076cb54c42b54b2e
1658 extended jungle
1665 extended jungle
1659
1666
1660 $ hg status -c .
1667 $ hg status -c .
1661 C a
1668 C a
1662 C b
1669 C b
1663 $ ls
1670 $ ls
1664 a
1671 a
1665 a.rej
1672 a.rej
1666 b
1673 b
1667 jungle.rej
1674 jungle.rej
1668
1675
1669 Importing multiple failing patches:
1676 Importing multiple failing patches:
1670
1677
1671 $ hg update --rev 'desc(initial)'
1678 $ hg update --rev 'desc(initial)'
1672 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
1679 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
1673 $ echo 'B' > b # just to make another commit
1680 $ echo 'B' > b # just to make another commit
1674 $ hg commit -m "a new base"
1681 $ hg commit -m "a new base"
1675 created new head
1682 created new head
1676 $ hg export --rev 'desc("four") + desc("extended jungle")' | hg import --partial -
1683 $ hg export --rev 'desc("four") + desc("extended jungle")' | hg import --partial -
1677 applying patch from stdin
1684 applying patch from stdin
1678 patching file a
1685 patching file a
1679 Hunk #1 FAILED at 0
1686 Hunk #1 FAILED at 0
1680 1 out of 1 hunks FAILED -- saving rejects to file a.rej
1687 1 out of 1 hunks FAILED -- saving rejects to file a.rej
1681 patch applied partially
1688 patch applied partially
1682 (fix the .rej files and run `hg commit --amend`)
1689 (fix the .rej files and run `hg commit --amend`)
1683 [1]
1690 [1]
1684 $ hg log -G --template '{desc|firstline} [{author}] {diffstat}\n'
1691 $ hg log -G --template '{desc|firstline} [{author}] {diffstat}\n'
1685 @ four [Rataxes] 0: +0/-0
1692 @ four [Rataxes] 0: +0/-0
1686 |
1693 |
1687 o a new base [test] 1: +1/-1
1694 o a new base [test] 1: +1/-1
1688 |
1695 |
1689 | o extended jungle [Cornelius] 0: +0/-0
1696 | o extended jungle [Cornelius] 0: +0/-0
1690 |/
1697 |/
1691 | o four [Rataxes] 0: +0/-0
1698 | o four [Rataxes] 0: +0/-0
1692 |/
1699 |/
1693 | o five [Arthur] 1: +1/-0
1700 | o five [Arthur] 1: +1/-0
1694 |/
1701 |/
1695 | o extended jungle [Cornelius] 1: +1/-0
1702 | o extended jungle [Cornelius] 1: +1/-0
1696 | |
1703 | |
1697 | o jungle [Zephir] 1: +1/-0
1704 | o jungle [Zephir] 1: +1/-0
1698 | |
1705 | |
1699 | o five [Arthur] 2: +2/-1
1706 | o five [Arthur] 2: +2/-1
1700 | |
1707 | |
1701 | o four [Rataxes] 1: +1/-1
1708 | o four [Rataxes] 1: +1/-1
1702 | |
1709 | |
1703 | o three [Celeste] 1: +1/-1
1710 | o three [Celeste] 1: +1/-1
1704 |/
1711 |/
1705 o initial [Babar] 2: +8/-0
1712 o initial [Babar] 2: +8/-0
1706
1713
1707 $ hg export
1714 $ hg export
1708 # HG changeset patch
1715 # HG changeset patch
1709 # User Rataxes
1716 # User Rataxes
1710 # Date 0 0
1717 # Date 0 0
1711 # Thu Jan 01 00:00:00 1970 +0000
1718 # Thu Jan 01 00:00:00 1970 +0000
1712 # Node ID a9d7b6d0ffbb4eb12b7d5939250fcd42e8930a1d
1719 # Node ID a9d7b6d0ffbb4eb12b7d5939250fcd42e8930a1d
1713 # Parent f59f8d2e95a8ca5b1b4ca64320140da85f3b44fd
1720 # Parent f59f8d2e95a8ca5b1b4ca64320140da85f3b44fd
1714 four
1721 four
1715
1722
1716 $ hg status -c .
1723 $ hg status -c .
1717 C a
1724 C a
1718 C b
1725 C b
1719
1726
1720 Importing some extra header
1727 Importing some extra header
1721 ===========================
1728 ===========================
1722
1729
1723 $ cat > $TESTTMP/parseextra.py <<EOF
1730 $ cat > $TESTTMP/parseextra.py <<EOF
1724 > import mercurial.patch
1731 > import mercurial.patch
1725 > import mercurial.cmdutil
1732 > import mercurial.cmdutil
1726 >
1733 >
1727 > def processfoo(repo, data, extra, opts):
1734 > def processfoo(repo, data, extra, opts):
1728 > if 'foo' in data:
1735 > if 'foo' in data:
1729 > extra['foo'] = data['foo']
1736 > extra['foo'] = data['foo']
1730 > def postimport(ctx):
1737 > def postimport(ctx):
1731 > if 'foo' in ctx.extra():
1738 > if 'foo' in ctx.extra():
1732 > ctx.repo().ui.write('imported-foo: %s\n' % ctx.extra()['foo'])
1739 > ctx.repo().ui.write('imported-foo: %s\n' % ctx.extra()['foo'])
1733 >
1740 >
1734 > mercurial.patch.patchheadermap.append(('Foo', 'foo'))
1741 > mercurial.patch.patchheadermap.append(('Foo', 'foo'))
1735 > mercurial.cmdutil.extrapreimport.append('foo')
1742 > mercurial.cmdutil.extrapreimport.append('foo')
1736 > mercurial.cmdutil.extrapreimportmap['foo'] = processfoo
1743 > mercurial.cmdutil.extrapreimportmap['foo'] = processfoo
1737 > mercurial.cmdutil.extrapostimport.append('foo')
1744 > mercurial.cmdutil.extrapostimport.append('foo')
1738 > mercurial.cmdutil.extrapostimportmap['foo'] = postimport
1745 > mercurial.cmdutil.extrapostimportmap['foo'] = postimport
1739 > EOF
1746 > EOF
1740 $ cat >> $HGRCPATH <<EOF
1747 $ cat >> $HGRCPATH <<EOF
1741 > [extensions]
1748 > [extensions]
1742 > parseextra=$TESTTMP/parseextra.py
1749 > parseextra=$TESTTMP/parseextra.py
1743 > EOF
1750 > EOF
1744 $ hg up -C tip
1751 $ hg up -C tip
1745 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
1752 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
1746 $ cat > $TESTTMP/foo.patch <<EOF
1753 $ cat > $TESTTMP/foo.patch <<EOF
1747 > # HG changeset patch
1754 > # HG changeset patch
1748 > # User Rataxes
1755 > # User Rataxes
1749 > # Date 0 0
1756 > # Date 0 0
1750 > # Thu Jan 01 00:00:00 1970 +0000
1757 > # Thu Jan 01 00:00:00 1970 +0000
1751 > # Foo bar
1758 > # Foo bar
1752 > height
1759 > height
1753 >
1760 >
1754 > --- a/a Thu Jan 01 00:00:00 1970 +0000
1761 > --- a/a Thu Jan 01 00:00:00 1970 +0000
1755 > +++ b/a Wed Oct 07 09:17:44 2015 +0000
1762 > +++ b/a Wed Oct 07 09:17:44 2015 +0000
1756 > @@ -5,3 +5,4 @@
1763 > @@ -5,3 +5,4 @@
1757 > five
1764 > five
1758 > six
1765 > six
1759 > seven
1766 > seven
1760 > +heigt
1767 > +heigt
1761 > EOF
1768 > EOF
1762 $ hg import $TESTTMP/foo.patch
1769 $ hg import $TESTTMP/foo.patch
1763 applying $TESTTMP/foo.patch
1770 applying $TESTTMP/foo.patch
1764 imported-foo: bar
1771 imported-foo: bar
1765 $ hg log --debug -r . | grep extra
1772 $ hg log --debug -r . | grep extra
1766 extra: branch=default
1773 extra: branch=default
1767 extra: foo=bar
1774 extra: foo=bar
1768
1775
1769 Warn the user that paths are relative to the root of
1776 Warn the user that paths are relative to the root of
1770 repository when file not found for patching
1777 repository when file not found for patching
1771
1778
1772 $ mkdir filedir
1779 $ mkdir filedir
1773 $ echo "file1" >> filedir/file1
1780 $ echo "file1" >> filedir/file1
1774 $ hg add filedir/file1
1781 $ hg add filedir/file1
1775 $ hg commit -m "file1"
1782 $ hg commit -m "file1"
1776 $ cd filedir
1783 $ cd filedir
1777 $ hg import -p 2 - <<EOF
1784 $ hg import -p 2 - <<EOF
1778 > # HG changeset patch
1785 > # HG changeset patch
1779 > # User test
1786 > # User test
1780 > # Date 0 0
1787 > # Date 0 0
1781 > file2
1788 > file2
1782 >
1789 >
1783 > diff --git a/filedir/file1 b/filedir/file1
1790 > diff --git a/filedir/file1 b/filedir/file1
1784 > --- a/filedir/file1
1791 > --- a/filedir/file1
1785 > +++ b/filedir/file1
1792 > +++ b/filedir/file1
1786 > @@ -1,1 +1,2 @@
1793 > @@ -1,1 +1,2 @@
1787 > file1
1794 > file1
1788 > +file2
1795 > +file2
1789 > EOF
1796 > EOF
1790 applying patch from stdin
1797 applying patch from stdin
1791 unable to find 'file1' for patching
1798 unable to find 'file1' for patching
1792 (use '--prefix' to apply patch relative to the current directory)
1799 (use '--prefix' to apply patch relative to the current directory)
1793 1 out of 1 hunks FAILED -- saving rejects to file file1.rej
1800 1 out of 1 hunks FAILED -- saving rejects to file file1.rej
1794 abort: patch failed to apply
1801 abort: patch failed to apply
1795 [255]
1802 [255]
1796
1803
1797 test import crash (issue5375)
1804 test import crash (issue5375)
1798 $ cd ..
1805 $ cd ..
1799 $ hg init repo
1806 $ hg init repo
1800 $ cd repo
1807 $ cd repo
1801 $ printf "diff --git a/a b/b\nrename from a\nrename to b" | hg import -
1808 $ printf "diff --git a/a b/b\nrename from a\nrename to b" | hg import -
1802 applying patch from stdin
1809 applying patch from stdin
1803 a not tracked!
1810 a not tracked!
1804 abort: source file 'a' does not exist
1811 abort: source file 'a' does not exist
1805 [255]
1812 [255]
General Comments 0
You need to be logged in to leave comments. Login now