Debian Codegraph @

tests/pullext.py

raw
1 # pullext.py - Simple extension to test pulling
2 #
3 # Copyright 2018 Gregory Szorc <[email protected]>
4 #
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.
7
8
9 from mercurial.i18n import _
10 from mercurial import (
11 commands,
12 error,
13 extensions,
14 localrepo,
15 requirements,
16 )
17
18
19 def clonecommand(orig, ui, repo, *args, **kwargs):
20 if kwargs.get('include') or kwargs.get('exclude'):
21 kwargs['narrow'] = True
22
23 if kwargs.get('depth'):
24 try:
25 kwargs['depth'] = int(kwargs['depth'])
26 except ValueError:
27 raise error.Abort(_('--depth must be an integer'))
28
29 return orig(ui, repo, *args, **kwargs)
30
31
32 def featuresetup(ui, features):
33 features.add(requirements.NARROW_REQUIREMENT)
34
35
36 def extsetup(ui):
37 entry = extensions.wrapcommand(commands.table, b'clone', clonecommand)
38
39 hasinclude = any(x[1] == b'include' for x in entry[1])
40 hasdepth = any(x[1] == b'depth' for x in entry[1])
41
42 if not hasinclude:
43 entry[1].append(
44 (b'', b'include', [], _(b'pattern of file/directory to clone'))
45 )
46 entry[1].append(
47 (b'', b'exclude', [], _(b'pattern of file/directory to not clone'))
48 )
49
50 if not hasdepth:
51 entry[1].append(
52 (b'', b'depth', b'', _(b'ancestry depth of changesets to fetch'))
53 )
54
55 localrepo.featuresetupfuncs.add(featuresetup)