diff --git a/changelogs/fragments/2125-git-config-scope-file.yml b/changelogs/fragments/2125-git-config-scope-file.yml new file mode 100644 index 0000000000..75862e0333 --- /dev/null +++ b/changelogs/fragments/2125-git-config-scope-file.yml @@ -0,0 +1,2 @@ +bugfixes: + - git_config - fixed scope ``file`` behaviour and added integraton test for it (https://github.com/ansible-collections/community.general/issues/2117). diff --git a/plugins/modules/source_control/git_config.py b/plugins/modules/source_control/git_config.py index 16126b3bfa..ab71370115 100644 --- a/plugins/modules/source_control/git_config.py +++ b/plugins/modules/source_control/git_config.py @@ -216,14 +216,13 @@ def main(): args = [git_path, "config", "--includes"] if params['list_all']: args.append('-l') - if scope: - args.append("--" + scope) - if name: - args.append(name) - if scope == 'file': args.append('-f') args.append(params['file']) + elif scope: + args.append("--" + scope) + if name: + args.append(name) if scope == 'local': dir = params['repo'] diff --git a/tests/integration/targets/git_config/aliases b/tests/integration/targets/git_config/aliases index 757c99661d..114ac22bb1 100644 --- a/tests/integration/targets/git_config/aliases +++ b/tests/integration/targets/git_config/aliases @@ -1,2 +1,3 @@ shippable/posix/group3 skip/aix +destructive diff --git a/tests/integration/targets/git_config/tasks/get_set_state_present_file.yml b/tests/integration/targets/git_config/tasks/get_set_state_present_file.yml new file mode 100644 index 0000000000..20946ac393 --- /dev/null +++ b/tests/integration/targets/git_config/tasks/get_set_state_present_file.yml @@ -0,0 +1,29 @@ +--- +- import_tasks: setup_no_value.yml + +- name: setting value with state=present + git_config: + name: "{{ option_name }}" + value: "{{ option_value }}" + scope: "file" + file: "{{ output_dir }}/gitconfig_file" + state: present + register: result + +- name: getting value with state=present + git_config: + name: "{{ option_name }}" + scope: "file" + file: "{{ output_dir }}/gitconfig_file" + state: present + register: get_result + +- name: assert set changed and value is correct with state=present + assert: + that: + - set_result is changed + - set_result.diff.before == "\n" + - set_result.diff.after == option_value + "\n" + - get_result is not changed + - get_result.config_value == option_value +... diff --git a/tests/integration/targets/git_config/tasks/main.yml b/tests/integration/targets/git_config/tasks/main.yml index 74127eb5c6..c88d52e27a 100644 --- a/tests/integration/targets/git_config/tasks/main.yml +++ b/tests/integration/targets/git_config/tasks/main.yml @@ -16,6 +16,8 @@ - import_tasks: get_set_no_state.yml # testing get/set option with state=present - import_tasks: get_set_state_present.yml + # testing get/set option with state=present and scope=file + - import_tasks: get_set_state_present_file.yml # testing state=absent without value to delete - import_tasks: unset_no_value.yml # testing state=absent with value to delete diff --git a/tests/integration/targets/git_config/tasks/setup_no_value.yml b/tests/integration/targets/git_config/tasks/setup_no_value.yml index 01a2c9735e..d5552450cf 100644 --- a/tests/integration/targets/git_config/tasks/setup_no_value.yml +++ b/tests/integration/targets/git_config/tasks/setup_no_value.yml @@ -5,4 +5,9 @@ file: path: ~/.gitconfig state: absent -... \ No newline at end of file + +- name: set up without value (file) + file: + path: "{{ output_dir }}/gitconfig_file" + state: absent +... diff --git a/tests/integration/targets/git_config/tasks/setup_value.yml b/tests/integration/targets/git_config/tasks/setup_value.yml index f5e0565441..3eff9c423a 100644 --- a/tests/integration/targets/git_config/tasks/setup_value.yml +++ b/tests/integration/targets/git_config/tasks/setup_value.yml @@ -5,4 +5,9 @@ copy: src: gitconfig dest: ~/.gitconfig -... \ No newline at end of file + +- name: set up with value (file) + copy: + src: gitconfig + dest: "{{ output_dir }}/gitconfig_file" +...