Skip to content

Commit

Permalink
Squashed 'manage_externals/' changes from fc5acda..1926530
Browse files Browse the repository at this point in the history
1926530 Merge pull request #118 from mnlevy1981/svn_switch
b1b028d Updates after testing
9ea73e6 Add --svn-ignore-ancestry argument

git-subtree-dir: manage_externals
git-subtree-split: 1926530
  • Loading branch information
fischer-ncar committed Apr 18, 2019
1 parent 05e0dcc commit 7a54e81
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
9 changes: 8 additions & 1 deletion manic/checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,13 @@ def commandline_arguments(args=None):
'used up to two times, increasing the '
'verbosity level each time.')

parser.add_argument('--svn-ignore-ancestry', action='store_true', default=False,
help='By default, subversion will abort if a component is '
'already checked out and there is no common ancestry with '
'the new URL. This flag passes the "--ignore-ancestry" flag '
'to the svn switch call. (This is not recommended unless '
'you are sure about what you are doing.)')

#
# developer options
#
Expand Down Expand Up @@ -348,7 +355,7 @@ def main(args):
"No component {} found in {}".format(
comp, args.externals))

source_tree = SourceTree(root_dir, external)
source_tree = SourceTree(root_dir, external, svn_ignore_ancestry=args.svn_ignore_ancestry)
printlog('Checking status of externals: ', end='')
tree_status = source_tree.status()
printlog('')
Expand Down
4 changes: 2 additions & 2 deletions manic/repository_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from .utils import fatal_error


def create_repository(component_name, repo_info):
def create_repository(component_name, repo_info, svn_ignore_ancestry=False):
"""Determine what type of repository we have, i.e. git or svn, and
create the appropriate object.
Expand All @@ -20,7 +20,7 @@ def create_repository(component_name, repo_info):
if protocol == 'git':
repo = GitRepository(component_name, repo_info)
elif protocol == 'svn':
repo = SvnRepository(component_name, repo_info)
repo = SvnRepository(component_name, repo_info, ignore_ancestry=svn_ignore_ancestry)
elif protocol == 'externals_only':
repo = None
else:
Expand Down
12 changes: 8 additions & 4 deletions manic/repository_svn.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ class SvnRepository(Repository):
"""
RE_URLLINE = re.compile(r'^URL:')

def __init__(self, component_name, repo):
def __init__(self, component_name, repo, ignore_ancestry=False):
"""
Parse repo (a <repo> XML element).
"""
Repository.__init__(self, component_name, repo)
self._ignore_ancestry = ignore_ancestry
if self._branch:
self._url = os.path.join(self._url, self._branch)
elif self._tag:
Expand Down Expand Up @@ -69,7 +70,7 @@ def checkout(self, base_dir_path, repo_dir_name, verbosity):
if os.path.exists(repo_dir_path):
cwd = os.getcwd()
os.chdir(repo_dir_path)
self._svn_switch(self._url, verbosity)
self._svn_switch(self._url, self._ignore_ancestry, verbosity)
# svn switch can lead to a conflict state, but it gives a
# return code of 0. So now we need to make sure that we're
# in a clean (non-conflict) state.
Expand Down Expand Up @@ -270,11 +271,14 @@ def _svn_checkout(url, repo_dir_path, verbosity):
execute_subprocess(cmd)

@staticmethod
def _svn_switch(url, verbosity):
def _svn_switch(url, ignore_ancestry, verbosity):
"""
Switch branches for in an svn sandbox
"""
cmd = ['svn', 'switch', '--quiet', url]
cmd = ['svn', 'switch', '--quiet']
if ignore_ancestry:
cmd.append('--ignore-ancestry')
cmd.append(url)
if verbosity >= VERBOSITY_VERBOSE:
printlog(' {0}'.format(' '.join(cmd)))
execute_subprocess(cmd)
11 changes: 7 additions & 4 deletions manic/sourcetree.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class _External(object):

# pylint: disable=R0902

def __init__(self, root_dir, name, ext_description):
def __init__(self, root_dir, name, ext_description, svn_ignore_ancestry):
"""Parse an external description file into a dictionary of externals.
Input:
Expand All @@ -37,6 +37,8 @@ def __init__(self, root_dir, name, ext_description):
ext_description : dict - source ExternalsDescription object
svn_ignore_ancestry : bool - use --ignore-externals with svn switch
"""
self._name = name
self._repo = None
Expand All @@ -62,7 +64,8 @@ def __init__(self, root_dir, name, ext_description):
if self._externals:
self._create_externals_sourcetree()
repo = create_repository(
name, ext_description[ExternalsDescription.REPO])
name, ext_description[ExternalsDescription.REPO],
svn_ignore_ancestry=svn_ignore_ancestry)
if repo:
self._repo = repo

Expand Down Expand Up @@ -231,15 +234,15 @@ class SourceTree(object):
SourceTree represents a group of managed externals
"""

def __init__(self, root_dir, model):
def __init__(self, root_dir, model, svn_ignore_ancestry=False):
"""
Build a SourceTree object from a model description
"""
self._root_dir = os.path.abspath(root_dir)
self._all_components = {}
self._required_compnames = []
for comp in model:
src = _External(self._root_dir, comp, model[comp])
src = _External(self._root_dir, comp, model[comp], svn_ignore_ancestry)
self._all_components[comp] = src
if model[comp][ExternalsDescription.REQUIRED]:
self._required_compnames.append(comp)
Expand Down

0 comments on commit 7a54e81

Please sign in to comment.