From 20f76d76a84635dbc62254b635fa31ebf4e8e96d Mon Sep 17 00:00:00 2001 From: Benjamin Baumer Date: Mon, 29 Jun 2015 13:45:08 +0200 Subject: [PATCH 1/2] Fix: Calling svn info to determine if dest is an svn Working Copy, to support updates in Subfolders with Subversion > 1.8 Fix: Ignoring svn:externals on local Modification Check. Add: Added Argument switch to alow skipping the svn switch call. --- source_control/subversion.py | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/source_control/subversion.py b/source_control/subversion.py index cae4702e174..84154d6dff0 100644 --- a/source_control/subversion.py +++ b/source_control/subversion.py @@ -78,6 +78,13 @@ options: version_added: "1.6" description: - If C(yes), do export instead of checkout/update. + switch: + required: false + default: "yes" + choices: [ "yes", "no" ] + version_added: "1.6" + description: + - If C(no), do not call svn switch before update. ''' EXAMPLES = ''' @@ -103,7 +110,7 @@ class Subversion(object): self.password = password self.svn_path = svn_path - def _exec(self, args): + def _exec(self, args, check_rc=True): bits = [ self.svn_path, '--non-interactive', @@ -115,8 +122,20 @@ class Subversion(object): if self.password: bits.extend(["--password", self.password]) bits.extend(args) - rc, out, err = self.module.run_command(bits, check_rc=True) - return out.splitlines() + if check_rc: + rc, out, err = self.module.run_command(bits, check_rc) + return out.splitlines() + else: + rc, out, err = self.module.run_command(bits, check_rc) + return rc + + def is_svn_repo(self): + '''Checks if path is a SVN Repo.''' + rc = self._exec(["info", self.dest], check_rc=False) + if rc == 0: + return True + else: + return False def checkout(self): '''Creates new svn working directory if it does not already exist.''' @@ -153,8 +172,9 @@ class Subversion(object): def has_local_mods(self): '''True if revisioned files have been added or modified. Unrevisioned files are ignored.''' - lines = self._exec(["status", "--quiet", self.dest]) + lines = self._exec(["status", "--quiet", "--ignore-externals", self.dest]) # The --quiet option will return only modified files. + # Has local mods if more than 0 modifed revisioned files. return len(filter(len, lines)) > 0 @@ -183,6 +203,7 @@ def main(): password=dict(required=False), executable=dict(default=None), export=dict(default=False, required=False, type='bool'), + switch=dict(default=True, required=False, type='bool'), ), supports_check_mode=True ) @@ -195,6 +216,7 @@ def main(): password = module.params['password'] svn_path = module.params['executable'] or module.get_bin_path('svn', True) export = module.params['export'] + switch = module.params['switch'] os.environ['LANG'] = 'C' svn = Subversion(module, dest, repo, revision, username, password, svn_path) @@ -208,7 +230,7 @@ def main(): svn.checkout() else: svn.export(force=force) - elif os.path.exists("%s/.svn" % (dest, )): + elif svn.is_svn_repo(): # Order matters. Need to get local mods before switch to avoid false # positives. Need to switch before revert to ensure we are reverting to # correct repo. @@ -217,7 +239,8 @@ def main(): module.exit_json(changed=check, before=before, after=after) before = svn.get_revision() local_mods = svn.has_local_mods() - svn.switch() + if switch: + svn.switch() if local_mods: if force: svn.revert() From 8255657ac9d2f9e1622ecd877109132c1db3c5f4 Mon Sep 17 00:00:00 2001 From: Benjamin Baumer Date: Tue, 7 Jul 2015 13:38:19 +0200 Subject: [PATCH 2/2] version_added for switch Parameter changed to 2.0 Add comment to explain check_rc Parameter in _exec Function Optimize code and clean up is_svn_repo Function --- source_control/subversion.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/source_control/subversion.py b/source_control/subversion.py index 84154d6dff0..24cc065c5a4 100644 --- a/source_control/subversion.py +++ b/source_control/subversion.py @@ -82,7 +82,7 @@ options: required: false default: "yes" choices: [ "yes", "no" ] - version_added: "1.6" + version_added: "2.0" description: - If C(no), do not call svn switch before update. ''' @@ -111,6 +111,7 @@ class Subversion(object): self.svn_path = svn_path def _exec(self, args, check_rc=True): + '''Execute a subversion command, and return output. If check_rc is False, returns the return code instead of the output.''' bits = [ self.svn_path, '--non-interactive', @@ -122,20 +123,16 @@ class Subversion(object): if self.password: bits.extend(["--password", self.password]) bits.extend(args) + rc, out, err = self.module.run_command(bits, check_rc) if check_rc: - rc, out, err = self.module.run_command(bits, check_rc) return out.splitlines() else: - rc, out, err = self.module.run_command(bits, check_rc) return rc def is_svn_repo(self): '''Checks if path is a SVN Repo.''' rc = self._exec(["info", self.dest], check_rc=False) - if rc == 0: - return True - else: - return False + return rc == 0 def checkout(self): '''Creates new svn working directory if it does not already exist.'''