1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Raises error for non-existent repo path (#1512) (#1518)

* Raises error for non-existent repo path, requires Ansible 2.10.4 or higher.

* Changes from suggestions in the PR

* Suggestion from PR

* Update changelogs/fragments/630-git_config-handling-invalid-dir.yaml

Co-authored-by: Felix Fontein <felix@fontein.de>

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit e9dafb3467)

Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
This commit is contained in:
patchback[bot] 2020-12-21 13:11:45 +01:00 committed by GitHub
parent d29db3ecf9
commit 9e7b067904
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- git_config - now raises an error for non-existent repository paths (https://github.com/ansible-collections/community.general/issues/630).

View file

@ -148,6 +148,8 @@ config_values:
alias.diffc: "diff --cached"
alias.remotev: "remote -v"
'''
import os
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.six.moves import shlex_quote
@ -245,7 +247,13 @@ def main():
else:
new_value_quoted = shlex_quote(new_value)
cmd = ' '.join(args + [new_value_quoted])
(rc, out, err) = module.run_command(cmd, cwd=dir)
try: # try using extra parameter from ansible-base 2.10.4 onwards
(rc, out, err) = module.run_command(cmd, cwd=dir, ignore_invalid_cwd=False)
except TypeError:
# @TODO remove try/except when community.general drop support for 2.10.x
if not os.path.isdir(dir):
module.fail_json(msg="Cannot find directory '{0}'".format(dir))
(rc, out, err) = module.run_command(cmd, cwd=dir)
if err:
module.fail_json(rc=rc, msg=err, cmd=cmd)