Skip to content

Commit 9ea73e6

Browse files
committed
Add --svn-ignore-ancestry argument
Add ability to pass --ignore-ancestry to svn switch calls
1 parent fc5acda commit 9ea73e6

File tree

4 files changed

+24
-11
lines changed

4 files changed

+24
-11
lines changed

manic/checkout.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,13 @@ def commandline_arguments(args=None):
280280
'used up to two times, increasing the '
281281
'verbosity level each time.')
282282

283+
parser.add_argument('--svn-ignore-ancestry', action='store_true', default=False,
284+
help='By default, subversion will abort if a component is '
285+
'already checked out and there is no common ancestry with '
286+
'the new URL. This flag passes the "--ignore-ancestry" flag '
287+
'to the svn switch call. (This is not recommended unless '
288+
'you are sure about what you are doing.)')
289+
283290
#
284291
# developer options
285292
#
@@ -348,7 +355,7 @@ def main(args):
348355
"No component {} found in {}".format(
349356
comp, args.externals))
350357

351-
source_tree = SourceTree(root_dir, external)
358+
source_tree = SourceTree(root_dir, external, args.svn_ignore_ancestry)
352359
printlog('Checking status of externals: ', end='')
353360
tree_status = source_tree.status()
354361
printlog('')

manic/repository_factory.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from .utils import fatal_error
1212

1313

14-
def create_repository(component_name, repo_info):
14+
def create_repository(component_name, repo_info, svn_ignore_ancestry):
1515
"""Determine what type of repository we have, i.e. git or svn, and
1616
create the appropriate object.
1717
@@ -20,7 +20,7 @@ def create_repository(component_name, repo_info):
2020
if protocol == 'git':
2121
repo = GitRepository(component_name, repo_info)
2222
elif protocol == 'svn':
23-
repo = SvnRepository(component_name, repo_info)
23+
repo = SvnRepository(component_name, repo_info, svn_ignore_ancestry)
2424
elif protocol == 'externals_only':
2525
repo = None
2626
else:

manic/repository_svn.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,12 @@ class SvnRepository(Repository):
3737
"""
3838
RE_URLLINE = re.compile(r'^URL:')
3939

40-
def __init__(self, component_name, repo):
40+
def __init__(self, component_name, repo, ignore_ancestry):
4141
"""
4242
Parse repo (a <repo> XML element).
4343
"""
4444
Repository.__init__(self, component_name, repo)
45+
self._ignore_ancestry = ignore_ancestry
4546
if self._branch:
4647
self._url = os.path.join(self._url, self._branch)
4748
elif self._tag:
@@ -69,7 +70,7 @@ def checkout(self, base_dir_path, repo_dir_name, verbosity):
6970
if os.path.exists(repo_dir_path):
7071
cwd = os.getcwd()
7172
os.chdir(repo_dir_path)
72-
self._svn_switch(self._url, verbosity)
73+
self._svn_switch(self._url, self._ignore_ancestry, verbosity)
7374
# svn switch can lead to a conflict state, but it gives a
7475
# return code of 0. So now we need to make sure that we're
7576
# in a clean (non-conflict) state.
@@ -270,11 +271,14 @@ def _svn_checkout(url, repo_dir_path, verbosity):
270271
execute_subprocess(cmd)
271272

272273
@staticmethod
273-
def _svn_switch(url, verbosity):
274+
def _svn_switch(url, ignore_ancestry, verbosity):
274275
"""
275276
Switch branches for in an svn sandbox
276277
"""
277-
cmd = ['svn', 'switch', '--quiet', url]
278+
cmd = ['svn', 'switch', '--quiet']
279+
if ignore_ancestry:
280+
cmd.append('--ignore-ancestry')
281+
cmd.append(url)
278282
if verbosity >= VERBOSITY_VERBOSE:
279283
printlog(' {0}'.format(' '.join(cmd)))
280284
execute_subprocess(cmd)

manic/sourcetree.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class _External(object):
2424

2525
# pylint: disable=R0902
2626

27-
def __init__(self, root_dir, name, ext_description):
27+
def __init__(self, root_dir, name, ext_description, svn_ignore_ancestry):
2828
"""Parse an external description file into a dictionary of externals.
2929
3030
Input:
@@ -37,6 +37,8 @@ def __init__(self, root_dir, name, ext_description):
3737
3838
ext_description : dict - source ExternalsDescription object
3939
40+
svn_ignore_ancestry : bool - use --ignore-externals with svn switch
41+
4042
"""
4143
self._name = name
4244
self._repo = None
@@ -62,7 +64,7 @@ def __init__(self, root_dir, name, ext_description):
6264
if self._externals:
6365
self._create_externals_sourcetree()
6466
repo = create_repository(
65-
name, ext_description[ExternalsDescription.REPO])
67+
name, ext_description[ExternalsDescription.REPO], svn_ignore_ancestry)
6668
if repo:
6769
self._repo = repo
6870

@@ -231,15 +233,15 @@ class SourceTree(object):
231233
SourceTree represents a group of managed externals
232234
"""
233235

234-
def __init__(self, root_dir, model):
236+
def __init__(self, root_dir, model, svn_ignore_ancestry=False):
235237
"""
236238
Build a SourceTree object from a model description
237239
"""
238240
self._root_dir = os.path.abspath(root_dir)
239241
self._all_components = {}
240242
self._required_compnames = []
241243
for comp in model:
242-
src = _External(self._root_dir, comp, model[comp])
244+
src = _External(self._root_dir, comp, model[comp], svn_ignore_ancestry)
243245
self._all_components[comp] = src
244246
if model[comp][ExternalsDescription.REQUIRED]:
245247
self._required_compnames.append(comp)

0 commit comments

Comments
 (0)