Raises error for non-existent repo path (#1512)
* 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>pull/1517/head
parent
47b940fc63
commit
e9dafb3467
|
@ -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).
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue