From 41db45ac336594ff3ce376988bb95c625e9b3a57 Mon Sep 17 00:00:00 2001 From: Rob Emery Date: Wed, 5 Sep 2018 00:59:16 +0100 Subject: [PATCH] Subversion: Only fire changed when content has changed (#41036) * Previously when checking out a subdirectory, if changes are made in the repository that aren't present in the subdirectory (i.e. in a different branch or similiar) then the changes handler still kicks in even though the content of this working copy hasn't necessarily changed. Now we parse the output of svn update and fire if anything changes at all. * Previously when checking out a subdirectory, if changes are made in the repository that aren't present in the subdirectory (i.e. in a different branch or similiar) then the changes handler still kicks in even though the content of this working copy hasn't necessarily changed. Now we parse the output of svn update and svn switch, firing if anything changes at all. * Should not be executable * ==None doesn't do what I want, is None does --- .../modules/source_control/subversion.py | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/lib/ansible/modules/source_control/subversion.py b/lib/ansible/modules/source_control/subversion.py index 2cc7ff7bd6..5921e636d6 100644 --- a/lib/ansible/modules/source_control/subversion.py +++ b/lib/ansible/modules/source_control/subversion.py @@ -137,6 +137,7 @@ class Subversion(object): bits.extend(["--password", self.password]) bits.extend(args) rc, out, err = self.module.run_command(bits, check_rc) + if check_rc: return out.splitlines() else: @@ -167,15 +168,29 @@ class Subversion(object): def switch(self): '''Change working directory's repo.''' # switch to ensure we are pointing at correct repo. - self._exec(["switch", self.repo, self.dest]) + # it also updates! + output = self._exec(["switch", self.repo, self.dest]) + for line in output: + if re.search(r'^[ABDUCGE]\s', line): + return True + return False def update(self): '''Update existing svn working directory.''' - self._exec(["update", "-r", self.revision, self.dest]) + output = self._exec(["update", "-r", self.revision, self.dest]) + + for line in output: + if re.search(r'^[ABDUCGE]\s', line): + return True + return False def revert(self): '''Revert svn working directory.''' - self._exec(["revert", "-R", self.dest]) + output = self._exec(["revert", "-R", self.dest]) + for line in output: + if re.search(r'^Reverted ', line) is None: + return True + return False def get_revision(self): '''Revision and URL of subversion working directory.''' @@ -263,8 +278,10 @@ def main(): module.exit_json(changed=False) if not export and checkout: svn.checkout() + files_changed = True else: svn.export(force=force) + files_changed = True 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 @@ -276,19 +293,21 @@ def main(): module.fail_json(msg="ERROR: modified files exist in the repository.") check, before, after = svn.needs_update() module.exit_json(changed=check, before=before, after=after) + files_changed = False before = svn.get_revision() local_mods = svn.has_local_mods() if switch: - svn.switch() + files_changed = svn.switch() or files_changed if local_mods: if force: - svn.revert() + files_changed = svn.revert() or files_changed else: module.fail_json(msg="ERROR: modified files exist in the repository.") - svn.update() + files_changed = svn.update() or files_changed elif in_place: before = None svn.checkout(force=True) + files_changed = True local_mods = svn.has_local_mods() if local_mods and force: svn.revert() @@ -299,7 +318,7 @@ def main(): module.exit_json(changed=True) else: after = svn.get_revision() - changed = before != after or local_mods + changed = files_changed or local_mods module.exit_json(changed=changed, before=before, after=after)