Skip to content

Commit

Permalink
git_config: fix state=absent if value is present (#8452)
Browse files Browse the repository at this point in the history
* Fix state=absent if value is present.

* Update changelog fragment.
  • Loading branch information
felixfontein authored Jun 6, 2024
1 parent 0129346 commit 2a3819a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 2 additions & 0 deletions changelogs/fragments/8452-git_config-absent.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- "git_config - fix behavior of ``state=absent`` if ``value`` is present (https://github.com/ansible-collections/community.general/issues/8436, https://github.com/ansible-collections/community.general/pull/8452)."
2 changes: 1 addition & 1 deletion plugins/modules/git_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def main():
module.exit_json(changed=False, msg='', config_value=old_values[0] if old_values else '')
elif unset and not out:
module.exit_json(changed=False, msg='no setting to unset')
elif new_value in old_values and (len(old_values) == 1 or add_mode == "add"):
elif new_value in old_values and (len(old_values) == 1 or add_mode == "add") and not unset:
module.exit_json(changed=False, msg="")

# Until this point, the git config was just read and in case no change is needed, the module has already exited.
Expand Down
24 changes: 24 additions & 0 deletions tests/integration/targets/git_config/tasks/unset_value.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,30 @@
scope: "{{ option_scope }}"
register: get_result

- name: assert unset changed and deleted value
assert:
that:
- unset_result is changed
- unset_result.diff.before == option_value + "\n"
- unset_result.diff.after == "\n"
- get_result.config_value == ''

- import_tasks: setup_value.yml

- name: unsetting value with value specified
git_config:
name: "{{ option_name }}"
scope: "{{ option_scope }}"
value: "{{ option_value }}"
state: absent
register: unset_result

- name: getting value
git_config:
name: "{{ option_name }}"
scope: "{{ option_scope }}"
register: get_result

- name: assert unset changed and deleted value
assert:
that:
Expand Down

0 comments on commit 2a3819a

Please sign in to comment.