diff options
| author | Egor Tensin <egor@tensin.name> | 2026-08-06 13:07:27 +0200 |
|---|---|---|
| committer | Egor Tensin <egor@tensin.name> | 2026-08-06 13:08:45 +0200 |
| commit | d7c131e370306aff43ebbfe682df7ba64302d9f1 (patch) | |
| tree | 8581994225110a24d7faceb43ae4d06b0ed1cfeb /plugins/module_utils/git.py | |
| parent | Merge pull request #2 from egor-tensin/dependabot/github_actions/actions/setu... (diff) | |
| download | infra-ansible-d7c131e370306aff43ebbfe682df7ba64302d9f1.tar.gz infra-ansible-d7c131e370306aff43ebbfe682df7ba64302d9f1.zip | |
reformat Python code with default Black settings
Diffstat (limited to 'plugins/module_utils/git.py')
| -rw-r--r-- | plugins/module_utils/git.py | 56 |
1 files changed, 28 insertions, 28 deletions
diff --git a/plugins/module_utils/git.py b/plugins/module_utils/git.py index d9c5f35..b05281d 100644 --- a/plugins/module_utils/git.py +++ b/plugins/module_utils/git.py @@ -7,30 +7,30 @@ from ansible.module_utils.common.text.converters import to_text def is_work_tree(action, repo_dir, task_vars): cmd_result = action._execute_module( - module_name='ansible.builtin.command', + module_name="ansible.builtin.command", module_args=dict( - argv=['git', 'rev-parse', '--is-inside-work-tree'], + argv=["git", "rev-parse", "--is-inside-work-tree"], chdir=repo_dir, ), task_vars=task_vars, ) - return not cmd_result.get('failed') + return not cmd_result.get("failed") def get_status(action, repo_dir, task_vars): cmd_result = action._execute_module( - module_name='ansible.builtin.command', + module_name="ansible.builtin.command", module_args=dict( - argv=['git', 'status', '--porcelain'], + argv=["git", "status", "--porcelain"], chdir=repo_dir, ), task_vars=task_vars, ) - if cmd_result.get('failed'): + if cmd_result.get("failed"): raise AnsibleActionFail( f"Couldn't get git status for {repo_dir}", result=cmd_result ) - return to_text(cmd_result['stdout']) + return to_text(cmd_result["stdout"]) def get_dirty_file_list(action, repo_dir, task_vars): @@ -40,46 +40,46 @@ def get_dirty_file_list(action, repo_dir, task_vars): return status -def get_remote_url(action, repo_dir, task_vars, remote='origin'): +def get_remote_url(action, repo_dir, task_vars, remote="origin"): cmd_result = action._execute_module( - module_name='ansible.builtin.command', + module_name="ansible.builtin.command", module_args=dict( - argv=['git', 'config', '--local', f'remote.{remote}.url'], + argv=["git", "config", "--local", f"remote.{remote}.url"], chdir=repo_dir, ), task_vars=task_vars, ) - if cmd_result.get('failed'): + if cmd_result.get("failed"): raise AnsibleActionFail( f"Couldn't read the URL of remote '{remote}' in {repo_dir}", result=cmd_result, ) - return cmd_result['stdout'] + return cmd_result["stdout"] def update_remote(action, repo_dir, remote, task_vars, accept_hostkey=False): - ssh = os.environ.get('GIT_SSH', 'ssh') - ssh_opts = '' + ssh = os.environ.get("GIT_SSH", "ssh") + ssh_opts = "" if accept_hostkey: - ssh_opts += ' -o StrictHostKeyChecking=no' + ssh_opts += " -o StrictHostKeyChecking=no" ssh_command = shlex.quote(ssh) + ssh_opts cmd_result = action._execute_module( - module_name='ansible.builtin.command', + module_name="ansible.builtin.command", module_args=dict( argv=[ - 'env', - f'GIT_SSH_COMMAND={ssh_command}', - 'git', - 'remote', - 'update', + "env", + f"GIT_SSH_COMMAND={ssh_command}", + "git", + "remote", + "update", remote, ], chdir=repo_dir, ), task_vars=task_vars, ) - if cmd_result.get('failed'): + if cmd_result.get("failed"): raise AnsibleActionFail( f"Couldn't update remote '{remote}' for {repo_dir}", result=cmd_result ) @@ -87,24 +87,24 @@ def update_remote(action, repo_dir, remote, task_vars, accept_hostkey=False): def is_ancestor(action, repo_dir, remote, version, task_vars): looks_like_hash = all( - ((c >= '0' and c <= '9') or (c >= 'a' and c <= 'f') for c in version) + ((c >= "0" and c <= "9") or (c >= "a" and c <= "f") for c in version) ) - remote_versions = [f'{remote}/{version}'] + remote_versions = [f"{remote}/{version}"] if looks_like_hash: remote_versions += [version] for _version in remote_versions: cmd_result = action._execute_module( - module_name='ansible.builtin.command', + module_name="ansible.builtin.command", module_args=dict( - argv=['git', 'merge-base', '--is-ancestor', 'HEAD', _version], + argv=["git", "merge-base", "--is-ancestor", "HEAD", _version], chdir=repo_dir, ), task_vars=task_vars, ) - if cmd_result.get('failed'): - if cmd_result.get('stderr'): + if cmd_result.get("failed"): + if cmd_result.get("stderr"): continue else: return True |
