Skip to content

Commit 1926530

Browse files
authored
Merge pull request #118 from mnlevy1981/svn_switch
Svn switch: allow ignoring ancestry Add ability to pass --ignore-ancestry to svn switch Add --svn-ignore-ancestry option to argparse, and then pass it through many calls to SvnRepository constructor. If this variable is True, run svn switch --ignore-ancestry. User interface changes?: Yes - added optional --svn-ignore-ancestry command line argument Note that omitting the option retains past behavior. Fixes #105 -- provide way to suppress svn error when switching between release tags or from development to release Testing: test removed: None unit tests: All Pass system tests: All Pass manual testing: Verified that adding --svn-ignore-ancestry suppresses previously-seen error
2 parents fc5acda + b1b028d commit 1926530

File tree

4 files changed

+25
-11
lines changed

4 files changed

+25
-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, svn_ignore_ancestry=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=False):
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, ignore_ancestry=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=False):
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: 7 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,8 @@ 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],
68+
svn_ignore_ancestry=svn_ignore_ancestry)
6669
if repo:
6770
self._repo = repo
6871

@@ -231,15 +234,15 @@ class SourceTree(object):
231234
SourceTree represents a group of managed externals
232235
"""
233236

234-
def __init__(self, root_dir, model):
237+
def __init__(self, root_dir, model, svn_ignore_ancestry=False):
235238
"""
236239
Build a SourceTree object from a model description
237240
"""
238241
self._root_dir = os.path.abspath(root_dir)
239242
self._all_components = {}
240243
self._required_compnames = []
241244
for comp in model:
242-
src = _External(self._root_dir, comp, model[comp])
245+
src = _External(self._root_dir, comp, model[comp], svn_ignore_ancestry)
243246
self._all_components[comp] = src
244247
if model[comp][ExternalsDescription.REQUIRED]:
245248
self._required_compnames.append(comp)

0 commit comments

Comments
 (0)