관리-도구
편집 파일: git.cpython-39.opt-1.pyc
a �����)g������������������������@���s���d�dl�mZmZmZ�eZdZdZdZd�dl Z d�dl Z d�dlZd�dlZd�dl Z d�dlZd�dlZd�dlZd�dlmZ�d�dlmZmZ�d�dlmZ�d�d lmZ�d�d lmZ�d�dlmZmZ�dd ��ZdUdd�Z dd��Z!dd��Z"dd��Z#dd��Z$dVdd�Z%dd��Z&dWdd�Z'd d!��Z(d"d#��Z)d$d%��Z*d&d'��Z+d(d)��Z,d*d+��Z-d,d-��Z.d.d/��Z/d0d1��Z0d2d3��Z1d4d5��Z2d6d7��Z3dXd8d9�Z4d:d;��Z5d<d=��Z6dYd>d?�Z7d@dA��Z8dZdBdC�Z9dDdE��Z:dFdG��Z;dHdI��Z<dJdK��Z=dLdM��Z>dNdO��Z?dPdQ��Z@dRdS��ZAeBdTk�r�eA���dS�)[�����)�absolute_import�division�print_functiona�"�� --- module: git author: - "Ansible Core Team" - "Michael DeHaan" version_added: "0.0.1" short_description: Deploy software (or files) from git checkouts description: - Manage I(git) checkouts of repositories to deploy files or software. extends_documentation_fragment: action_common_attributes options: repo: description: - git, SSH, or HTTP(S) protocol address of the git repository. type: str required: true aliases: [ name ] dest: description: - The path of where the repository should be checked out. This is equivalent to C(git clone [repo_url] [directory]). The repository named in I(repo) is not appended to this path and the destination directory must be empty. This parameter is required, unless I(clone) is set to C(false). type: path required: true version: description: - What version of the repository to check out. This can be the literal string C(HEAD), a branch name, a tag name. It can also be a I(SHA-1) hash, in which case I(refspec) needs to be specified if the given revision is not already available. type: str default: "HEAD" accept_hostkey: description: - Will ensure or not that "-o StrictHostKeyChecking=no" is present as an ssh option. - Be aware that this disables a protection against MITM attacks. - Those using OpenSSH >= 7.5 might want to set I(ssh_opts) to 'StrictHostKeyChecking=accept-new' instead, it does not remove the MITM issue but it does restrict it to the first attempt. type: bool default: 'no' version_added: "1.5" accept_newhostkey: description: - As of OpenSSH 7.5, "-o StrictHostKeyChecking=accept-new" can be used which is safer and will only accepts host keys which are not present or are the same. if C(true), ensure that "-o StrictHostKeyChecking=accept-new" is present as an ssh option. type: bool default: 'no' version_added: "2.12" ssh_opts: description: - Options git will pass to ssh when used as protocol, it works via C(git)'s GIT_SSH/GIT_SSH_COMMAND environment variables. - For older versions it appends GIT_SSH_OPTS (specific to this module) to the variables above or via a wrapper script. - Other options can add to this list, like I(key_file) and I(accept_hostkey). - An example value could be "-o StrictHostKeyChecking=no" (although this particular option is better set by I(accept_hostkey)). - The module ensures that 'BatchMode=yes' is always present to avoid prompts. type: str version_added: "1.5" key_file: description: - Specify an optional private key file path, on the target host, to use for the checkout. - This ensures 'IdentitiesOnly=yes' is present in ssh_opts. type: path version_added: "1.5" reference: description: - Reference repository (see "git clone --reference ..."). version_added: "1.4" remote: description: - Name of the remote. type: str default: "origin" refspec: description: - Add an additional refspec to be fetched. If version is set to a I(SHA-1) not reachable from any branch or tag, this option may be necessary to specify the ref containing the I(SHA-1). Uses the same syntax as the C(git fetch) command. An example value could be "refs/meta/config". type: str version_added: "1.9" force: description: - If C(true), any modified files in the working repository will be discarded. Prior to 0.7, this was always C(true) and could not be disabled. Prior to 1.9, the default was C(true). type: bool default: 'no' version_added: "0.7" depth: description: - Create a shallow clone with a history truncated to the specified number or revisions. The minimum possible value is C(1), otherwise ignored. Needs I(git>=1.9.1) to work correctly. type: int version_added: "1.2" clone: description: - If C(false), do not clone the repository even if it does not exist locally. type: bool default: 'yes' version_added: "1.9" update: description: - If C(false), do not retrieve new revisions from the origin repository. - Operations like archive will work on the existing (old) repository and might not respond to changes to the options version or remote. type: bool default: 'yes' version_added: "1.2" executable: description: - Path to git executable to use. If not supplied, the normal mechanism for resolving binary paths will be used. type: path version_added: "1.4" bare: description: - If C(true), repository will be created as a bare repo, otherwise it will be a standard repo with a workspace. type: bool default: 'no' version_added: "1.4" umask: description: - The umask to set before doing any checkouts, or any other repository maintenance. type: raw version_added: "2.2" recursive: description: - If C(false), repository will be cloned without the --recursive option, skipping sub-modules. type: bool default: 'yes' version_added: "1.6" single_branch: description: - Clone only the history leading to the tip of the specified revision. type: bool default: 'no' version_added: '2.11' track_submodules: description: - If C(true), submodules will track the latest commit on their master branch (or other branch specified in .gitmodules). If C(false), submodules will be kept at the revision specified by the main project. This is equivalent to specifying the --remote flag to git submodule update. type: bool default: 'no' version_added: "1.8" verify_commit: description: - If C(true), when cloning or checking out a I(version) verify the signature of a GPG signed commit. This requires git version>=2.1.0 to be installed. The commit MUST be signed and the public key MUST be present in the GPG keyring. type: bool default: 'no' version_added: "2.0" archive: description: - Specify archive file path with extension. If specified, creates an archive file of the specified format containing the tree structure for the source tree. Allowed archive formats ["zip", "tar.gz", "tar", "tgz"]. - This will clone and perform git archive from local directory as not all git servers support git archive. type: path version_added: "2.4" archive_prefix: description: - Specify a prefix to add to each file path in archive. Requires I(archive) to be specified. version_added: "2.10" type: str separate_git_dir: description: - The path to place the cloned repository. If specified, Git repository can be separated from working tree. type: path version_added: "2.7" gpg_whitelist: description: - A list of trusted GPG fingerprints to compare to the fingerprint of the GPG-signed commit. - Only used when I(verify_commit=yes). - Use of this feature requires Git 2.6+ due to its reliance on git's C(--raw) flag to C(verify-commit) and C(verify-tag). type: list elements: str default: [] version_added: "2.9" requirements: - git>=1.7.1 (the command line tool) attributes: check_mode: support: full diff_mode: support: full platform: platforms: posix notes: - "If the task seems to be hanging, first verify remote host is in C(known_hosts). SSH will prompt user to authorize the first contact with a remote host. To avoid this prompt, one solution is to use the option accept_hostkey. Another solution is to add the remote host public key in C(/etc/ssh/ssh_known_hosts) before calling the git module, with the following command: ssh-keyscan -H remote_host.com >> /etc/ssh/ssh_known_hosts." az�� - name: Git checkout ansible.builtin.git: repo: 'https://foosball.example.org/path/to/repo.git' dest: /srv/checkout version: release-0.22 - name: Read-write git checkout from github ansible.builtin.git: repo: git@github.com:mylogin/hello.git dest: /home/mylogin/hello - name: Just ensuring the repo checkout exists ansible.builtin.git: repo: 'https://foosball.example.org/path/to/repo.git' dest: /srv/checkout update: no - name: Just get information about the repository whether or not it has already been cloned locally ansible.builtin.git: repo: 'https://foosball.example.org/path/to/repo.git' dest: /srv/checkout clone: no update: no - name: Checkout a github repo and use refspec to fetch all pull requests ansible.builtin.git: repo: https://github.com/ansible/ansible-examples.git dest: /src/ansible-examples refspec: '+refs/pull/*:refs/heads/*' - name: Create git archive from repo ansible.builtin.git: repo: https://github.com/ansible/ansible-examples.git dest: /src/ansible-examples archive: /tmp/ansible-examples.zip - name: Clone a repo with separate git directory ansible.builtin.git: repo: https://github.com/ansible/ansible-examples.git dest: /src/ansible-examples separate_git_dir: /src/ansible-examples.git - name: Example clone of a single branch ansible.builtin.git: repo: https://github.com/ansible/ansible-examples.git dest: /src/ansible-examples single_branch: yes version: master - name: Avoid hanging when http(s) password is missing ansible.builtin.git: repo: https://github.com/ansible/could-be-a-private-repo dest: /src/from-private-repo environment: GIT_TERMINAL_PROMPT: 0 # reports "terminal prompts disabled" on missing password # or GIT_ASKPASS: /bin/true # for git before version 2.3.0, reports "Authentication failed" on missing password aR�� after: description: Last commit revision of the repository retrieved during the update. returned: success type: str sample: 4c020102a9cd6fe908c9a4a326a38f972f63a903 before: description: Commit revision before the repository was updated, "null" for new repository. returned: success type: str sample: 67c04ebe40a003bda0efb34eacfb93b0cafdf628 remote_url_changed: description: Contains True or False whether or not the remote URL was changed. returned: success type: bool sample: True warnings: description: List of warnings if requested features were not available due to a too old git version. returned: error type: str sample: git version is too old to fully support the depth argument. Falling back to full checkouts. git_dir_now: description: Contains the new path of .git directory if it is changed. returned: success type: str sample: /path/to/new/git/dir git_dir_before: description: Contains the original path of .git directory if it is changed. returned: success type: str sample: /path/to/old/git/dir N)�LooseVersion)� to_native�to_text)� AnsibleModule)�get_best_parsable_locale)�get_bin_path)�b�string_typesc�������������� ���C���s����t�j�|�r|�jd|�d��|r�t�j�|d�}zXt�||��t|d��}|�d|���W�d�����n1�sj0����Y��||d<�||d<�W�nT�t t fy��}�z8t�j�|�r�t�||��|�jdt|��d��W�Y�d�}~n d�}~0�0�d�S�) Nz(Separate-git-dir path %s already exists.��msg�.git�wz gitdir: %sZgit_dir_beforeZgit_dir_nowzUnable to move git dir. %s)�os�path�exists� fail_json�join�shutil�move�open�write�IOError�OSErrorr���)�module�resultZrepo_dirZold_repo_dirZworktree_dirZdot_git_file_pathZdot_git_file�err��r����7/usr/lib/python3.9/site-packages/ansible/modules/git.py� relocate_repo[��s����,r!���Fc����������� ������C���s����d}t�j�|��r�d}zt|�d�}|���}|����W�n*�ty\���|rX|rX|jd|��d��Y�n0�|r�zB|�d|�dd�}|� d�}|d �}|� d d�} | d �� d�}W�n*�ty����|r�|r�|jd |�d��Y�n0�|S�)zExtract the head referenceN�rzUnable to read %sr ���zrefs/remotes/%s������� ����/����� zUnable to split head from '%s')r���r���r���r����readline�close� Exceptionr����replace�split�rstrip) �headfile�remoter���� fail_on_error�resZrawdata�fZrefpartsZnewrefZ nrefpartsr���r���r ���� head_splitterm��s*���� r5���c�������������� ���C���s0���|�d�u�rd�S�t�j�t�j�t�j�t�j�|�����S�)N)r���r����normpath�realpath� expanduser� expandvars�r���r���r���r ����unfrackgitpath���s����r;���c����������� ������C���s����g�}d|�}|�j�||d�\}}}|�d�}d�} |D�]} d| v�r2| } q2| r�| �dd�} | �dd�} | �dd �} t�| �}|D�]$}|�d �rz|�d d�}|�|��qz|S�)Nz%s submodule update --help��cwdr)���zgit submodule [--quiet] update �[r#����]�|r%���z--)�run_commandr.���r-����shlex� startswith�append) r����git_pathr=����params�cmd�rc�stdout�stderr�linesZupdate_line�line�parts�partr���r���r ����get_submodule_update_params���s$���� rO���c�������������� ���C���s����z<t��|�jt�jt�jB�t�jB��r6tj|�jd�d�\}}nt�W�n"�t tfy^���t���\}}Y�n0�t dt�j�dt�j�dd����}t�� |d��}|�|��W�d����n1�s�0����Y��t��|�}t��||jtjB���|��d ||f���|�j|d ��|S�)z� This writes an shell wrapper for ssh options to be used with git this is only relevant for older versions of gitthat cannot handle the options themselves. Returns path to the script r'���)�prefixz #!/bin/sh %s $GIT_SSH_OPTS "$@" �GIT_SSH�GIT_SSH_COMMAND�sshzw+bNz#Wrote temp git ssh wrapper (%s): %sr:���)r����accessZtmpdir�W_OK�R_OK�X_OK�tempfileZmkstempr���r���r����environ�get�fdopenr����stat�chmod�st_mode�S_IEXEC�debugZadd_cleanup_file)r����fdZwrapper_path�templateZfh�str���r���r ����write_ssh_wrapper���s �����( rd���c����������� ������C���s���|du�rt�j�dd�}nt�j�dd�d�|�}d}|jd�rP||vrP|d|�7�}d}||vrh|d|�7�}|�r�d |��}||vr�|d |�7�}d}||vr�|d|�7�}|td�k�r�|t�jd<�t|�}|t�jd <�n2t�j�d t�j�dd��} |r�| d|�7�} | t�jd<�dS�)z� use environment variables to configure git's ssh execution, which varies by version but this functino should handle all. NZGIT_SSH_OPTSr#���r%���zStrictHostKeyChecking=no�accept_hostkeyz -o %sz BatchMode=yesz-i %sz %szIdentitiesOnly=yesz2.3.0rQ���rR���rS���)r���rY���rZ���rF���r���rd���) �key_file�ssh_opts�git_versionr���Z accept_keyZforce_batchZkey_optZikey�wrapperZfull_cmdr���r���r ����set_git_ssh_env���s0���� rj����HEADc����������� ������C���s2���d||f�}|�j�||d�\}}}t|��d�}|S�)z% samples the version of the git repo z%s rev-parse %sr<���r)����rA���r���r/���) r���rE����dest�refrG���rH���rI���rJ���Zshar���r���r ����get_version��s����ro���c�������������� ���C���st���zt�d�}W�n6�tyB�}�z|�jdt|�d��W�Y�d�}~n d�}~0�0�d}|dddg}|��|�\}}}|dkrpd }|S�) NrS���zNRemote host is missing ssh command, so you cannot use acceptnewhostkey option.�r����detailsTz-oz StrictHostKeyChecking=accept-newz-Vr���F)r ���� ValueErrorr���r���rA���)r���Zssh_pathr���Zsupports_acceptnewhostkeyrG���rH���rI���rJ���r���r���r ����ssh_supports_acceptnewhostkey��s�����rs���c�����������������C���s����|�dd|�d|g}|j�||d�\}}}|dkr>|jd|||d��i�}d�} |���D�]b} | �d�rj| d d ��} qNt| ����dkr�| d�u�r�|����| ���|| <�d�} qN|jd| ����d ��qN| d�ur�|jd| �d ��|S�)N� submodule�foreachz rev-parser<���r���z(Unable to determine hashes of submodules�r���rI���rJ���rH���z Entering '� ���r&����(���z'Unable to parse submodule hash line: %sr ���z%Unable to find hash for submodule: %s)rA���r���� splitlinesrC����len�strip)rE���r���rm����versionrG���rH����outr���Z submodulesZ subm_namerL���r���r���r ����get_submodule_versions��s.����� r~���c�����������������C���sD��t�j�|�}zt��|��W�n�ty,���Y�n0�|�dg}|rF|�d��n|�d|g��t|�||||�prt|�||||�}|r�|dks�| r�|�dt |�g��n0|r�|�dt |�g��|�d|g��n |� d��|r�|�dt |�g��|�r8| d u�r�|jd |��d��| td�k��r|� d | ���n|�d��|�r8|�d|g��d}|�r~| d u��r\|jd |��d��| td�k��rpd}n|�d|���|�||g��|j |d|d��|�r�t|| |t�j�|d�|��|�r�|dk�r�|j |�dd||gd|d��| �r*|�dg}|�r|�dt |�g��|�|| g��|j |d|d��|�r@t|�||||��d S�)z3 makes a new git repo if it does not already exist �clonez--barez--originrk����--depthz--branchzsIgnoring depth argument. Shallow clones are only available for HEAD, branches, tags or in combination with refspec.z--referenceNz Cannot find git executable at %sr ���z1.7.10z=git version '%s' is too old to use 'single-branch'. Ignoring.z--single-branchFz1.7.5Tz--separate-git-dir=%s�Zcheck_rcr=���r����originr1����add�fetch)r���r����dirname�makedirsr,���rD����extend�is_remote_branch� is_remote_tag�str�warnr���r���rA���r!���r����verify_commit_sign)rE���r����reporm���r1����depthr|����bare� reference�refspec�git_version_used� verify_commit�separate_git_dirr���� gpg_whitelist� single_branchZdest_dirnamerG���Zis_branch_or_tagZneeds_separate_git_dir_fallbackr���r���r ���r���9��s`���� r���c����������� ������C���sJ���|rdS�d|�}|�j�||d�\}}}|���}ttdd��|��}t|�dkS�)NFz%s status --porcelainr<���c�����������������S���s���t��d|���S�)Nz^\?\?.*$)�re�search)�cr���r���r ����<lambda>��������z has_local_mods.<locals>.<lambda>r���)rA���ry����list�filterrz���) r���rE���rm���r����rG���rH���rI���rJ���rK���r���r���r ����has_local_mods���s����r����c�����������������C���s���d|�f�}|j�|d|d�S�)z� Resets the index and working tree to HEAD. Discards any changes to tracked files in working tree since that commit. z%s reset --hard HEADTr����)rA���)rE���r���rm���rG���r���r���r ����reset���s���� r����c �����������������C���s����|du�rdd|�iS�||kr�t�||��} t||�||||||d| � �d|||f�} |�j| |d�\}}} |dkrv|rvd|iS�|dkr�dd||f�iS�| r�dd ||| f�iS�dd ||f�iS�i�S�)z* Return the difference between 2 versions NZpreparedz>> Newly checked out %sr#���z %s diff %s %sr<���r���z*>> No visual differences between %s and %sz5>> Failed to get proper diff between %s and %s: >> %sz.>> Failed to get proper diff between %s and %s)rh���r����rA���)r���rE���rm���r����r1���r����r�����before�afterr����rG���rH���r}���r���r���r���r ����get_diff���s���� r����c�����������������C���sZ��d}d�}d}||j�d�kr d}n$|dtj�|j�d���kr@d}n|}|dkr~|r^d|�|f�} q�t|�||||�} d|�|| f�} nHt|�||||�r�d|�||f�} n(t|�||||�r�d}d|�||f�} n|S�|j| d|d �\}}} t|�d k�r�|j d|�|| |d��t |�}|�rJ|�d �D�]2}|�|d���r6|}��qJn|�|��r|}�q|���d�}|S�)NFr����T�file://rk���z%s ls-remote %s -h HEAD� %s ls-remote %s -h refs/heads/%sz %s ls-remote %s -t refs/tags/%s*r����r$���z*Could not determine remote revision for %srv���r)���z^{}r���) rF���r���r���r8����get_head_branchr����r����rA���rz���r���r���r.����endswith)rE���r���rm���r|���r1���r����Zcloningr=����tagrG���Zhead_branchrH���r}���r���Zrevr���r���r ����get_remote_head���s@����r����c����������� ������C���s@���d|�||f�}|j�|d|d�\}}}t|dd�|v�r8dS�dS�d�S�)Nz%s ls-remote %s -t refs/tags/%sTr�����surrogate_or_strict��errorsF�rA���r���� rE���r���rm���r1���r|���rG���rH���r}���r���r���r���r ���r�������s ����r����c����������� ������C���sh���g�}d|�f�}|j�||d�\}}}|dkr>|jd|�||d��|�d�D�]}|���rH|�|�����qH|S�)Nz%s branch --no-color -ar<���r���z-Could not determine branch data - received %s�r���rI���rJ���r)���)rA���r���r.���r{���rD���) rE���r���rm����branchesrG���rH���r}���r���rL���r���r���r ����get_branches���s���� r����c�����������������C���s����g�}|�ddddg}|j�||d�\}}}|dkrB|jd|�||d��t|��d �D�]0}|���rP|����d �\} } | dkrP|�| ��qP|S�)Nzfor-each-refz refs/tags/�--formatz%(objecttype):%(refname:short)r<���r���z*Could not determine tag data - received %sr����r)����:r����)rA���r���r���r.���r{���rD���)rE���r���rm����tagsrG���rH���r}���r���rL���ZtagtypeZtagnamer���r���r ����get_annotated_tags���s����r����c����������� ������C���s@���d|�||f�}|j�|d|d�\}}}t|dd�|v�r8dS�dS�d�S�)Nr����Tr����r����r����Fr����r����r���r���r ���r�������s ����r����c�����������������C���s8���t�|�||�}d|�}||v�r dS�d|�|v�r0dS�dS�d�S�)Nz%sTz* %sF)r����)rE���r���rm����branchr����Zlbranchr���r���r ����is_local_branch��s����r����c�����������������C���sB���t�|�||�}|D�],}|�d�rd|v�s6d|v�s6d|v�r�dS�qdS�)Nz* z no branchz detached fromzdetached atTF)r����rC���)rE���r���rm���r����r����r���r���r ����is_not_a_branch��s ����"r����c�����������������C���s����|r |�}nt�j�|�d�}t�j�|�r�t|d��}|���}W�d�����n1�sL0����Y��|����dd�\}}|rvtd��t�j� |�r�|}nt�j�|�|�}t�j� |�s�td|���|S�)Nr���r"���zgitdir: r$���z..git file has invalid git dir reference formatz%s is not a directory)r���r���r����isfiler����readr/���r.���rr����isabs�isdir)rm���r����� repo_pathZgitfile�dataZ ref_prefixZgitdirr���r���r ���� get_repo_path��s����&r����c����������� ��� ���C���s����zt�||�}W�n:�ttfyH�}�z|jdt|�d��W�Y�d}~n d}~0�0�tj�|d�}t|�||�rxtj�|dd|d�}t |||dd�}|S�) aN�� Determine what branch HEAD is associated with. This is partly taken from lib/ansible/utils/__init__.py. It finds the correct path to .git/HEAD and reads from that file the branch that HEAD is associated with. In the case of a detached HEAD, this will look up the branch in .git/refs/remotes/<remote>/HEAD. �cCurrent repo does not have a valid reference to a separate Git dir or it refers to the invalid pathrp���Nrk���ZrefsZremotesT)r���r2���) r����r���rr���r���r���r���r���r���r����r5���) rE���r���rm���r1���r����r����r���r0���r����r���r���r ���r����0��s�����r����c�����������������C���s:���|�dd|g}|j�||d�\}}}|dkr,dS�t|��d�S�)z%Return URL of remote source for repo.z ls-remotez --get-urlr<���r���Nr)���rl���)rE���r���rm���r1����commandrH���r}���r���r���r���r ����get_remote_urlL��s ����r����c�����������������C���s~���t�|�|||�}||ks&t|�t|�kr*dS�|�dd||g}|j||d�\}}} |dkrvd||f�} |jd| || f�d��|d uS�) �" updates repo from remote sources Fr1���zset-urlr<���r���zset a new url %s for %s�Failed to %s: %s %sr ���N)r����r;���rA���r���)rE���r���r����rm���r1���� remote_urlr����rH���r}���r����labelr���r���r ����set_remote_urlW��s����r����c�����������������C���s���t�|�||||��g�}d}|�dg} g�}|r�t|�|||�}|rF|�|��nz|dkrZ|�|��nft|�||||�r�||kr�|�d||f���|�d|||f���n&t|�||||�r�|�d|�d�|���|r�| �dt|�g��|r�|�s2|r�d d g}n4| td�k�r| �d��n|�|| |g�f��d g}|�r2|�|��| �rB| �d ��| �|g��|�|| |�f��|D�]@\}}|j||d�\}}}|dk�rd|j d|||f�|d���qddS�)r����z download remote objects and refsr����rk����+refs/heads/%s:refs/heads/%sz!+refs/heads/%s:refs/remotes/%s/%sz+refs/tags/z:refs/tags/r����z+refs/heads/*:refs/heads/*z+refs/tags/*:refs/tags/*z1.9z--tags�--forcer<���r���r����)r���rG���N) r����r����rD���r����r����r����r����r���rA���r���)rE���r���r����rm���r|���r1���r����r����r����r�����forceZcommandsZ fetch_strZ fetch_cmdZrefspecsZcurrentheadr����r����rH���r}���r���r���r���r ���r����i��sH���� r����c�����������������C���sf��d}t�j�t�j�|d��s|S�tt�j�|d�d�}|D�]F}|s6|����d�r6|�dd�d����}t�j�t�j�||d��s6d}q6|�sbt|�||�} |�d d |�dg} |j | d|d�\}}} |d kr�|j d|�| �d��|r�d}t|�||d||f��}| |kr�d}nf|�d dg} |j | d|d�\}}} |d k�r:|j d|�| �d��|���D�]}|d �dk�rBd}��qb�qB|S�)NF�.gitmodulesr"���r����=r$���r���Trt���ru���r����r����r���zFailed to fetch submodules: %sr ���Zmasterz%s/%s�statusz'Failed to retrieve submodule status: %sr%���)r���r���r���r���r���r{���rC���r.���r~���rA���r���ry���)rE���r���r1����track_submodulesrm����changedZgitmodules_filerL���r���ZbeginrG���rH���r}���r���r|���r����r���r���r ����submodules_fetch���s:���� r����c����������� ������C���s����t�||�|�}tj�tj�|d��s&dS�|�ddg}|j|d|d�\}}} d|v�rd|rd|�ddd d dg}n|�ddd d g}|r�|�d��|j||d �\}}} |dkr�|jd|�| �d��||| fS�)z init and update any submodules r����)r���r#���r#���rt����syncTr����r1����updatez--initz--recursivez--remoter����r<���r���z$Failed to init/update submodules: %sr ���)rO���r���r���r���r���rA���rD���r���) rE���r���rm���r����r����rF���rG���rH���r}���r���r���r���r ����submodule_update���s���� r����c�����������������C���sd���d||f�}|d|||f�7�}d|�|||f�}|j�||d�\}} } |dkr`|jd|�| | |d��dS�) z�set refs for the remote branch version This assumes the branch does not yet exist locally and is therefore also not checked out. Can't use git remote set-branches, as it is not available in git 1.7.1 (centos6) r����z" +refs/heads/%s:refs/remotes/%s/%sz%s fetch --depth=%s %s %sr<���r���z&Failed to fetch branch from remote: %srv���N)rA���r���)rE���r���rm���r1���r|���r����Z branchrefrG���rH���r}���r���r���r���r ����set_remote_branch���s����r����c�����������������C���s���d}|dkrdt�|�|||�} |jd|�| f�|d�\} }}| dkrT|jd| �||| d��d|�|| f�}n�t|�||||��r|r�t|�|||�s�t|�|||||��t|�|||�s�d |�|||f�}nH|jd|�|f�|d�\} }}| dkr�|jd|�||| d��d |�||f�}nd|�|f�}|j||d�\} } }| dk�rj|dk�rR|jd|�| || |d��n|jd| �| || |d��|�r�t|�||||��| | |fS�) Nr#���rk���z%s checkout --force %sr<���r���zFailed to checkout branch %srv���z%s reset --hard %s/%s --z%s checkout --track -b %s %s/%sz%s reset --hard %s/%szFailed to checkout %s)r���rI���rJ���rH���rG���)r����rA���r���r����r����r����r����)rE���r���rm���r1���r|���r����r����r����rG���r����rH���r}���r���Zout1Zerr1r���r���r ����switch_version���s>���� � � �r����c�����������������C���s����|t�|�||�v�rd}nd}d|�||f�}|r4|d7�}|j||d�\}}} |dkrf|jd|�|| |d��|r�t| �} | |vr�|jd | �|| |d��||| fS�) Nz verify-tagz verify-commitz%s %s %sz --rawr<���r���z1Failed to verify GPG signature of commit/tag "%s"rv���zFThe gpg_whitelist does not include the public key "%s" for this commit)r����rA���r����get_gpg_fingerprint)rE���r���rm���r|���r����Zgit_subrG���rH���r}���r���Zfingerprintr���r���r ���r����#��s����r����c�����������������C���sF���|�����D�]8}|���}|d�dkr"qt|�dkr2dnd}||���S�dS�)z�Return a fingerprint of the primary key. Ref: https://git.gnupg.org/cgi-bin/gitweb.cgi?p=gnupg.git;a=blob;f=doc/DETAILS;hb=HEAD#l482 r$���ZVALIDSIG����r(���N)ry���r.���rz���)�outputrL���r����Zdata_idr���r���r ���r����5��s����r����c�����������������C���sL���d|��}|��|�\}}}|dkr$dS�t�dt|��}|s<dS�t|���d��S�)z#return the installed version of gitz%s --versionr���Nzgit version (.*)$)rA���r����r����r���r����groups)rE���r���rG���rH���r}���r���Zrematchr���r���r ���rh���E��s����rh���c�����������������C���sp���|�dd|d||g}|dur2|��dd��|��d|��|j||d�\}} } |dkrf|jd d ||| f�d��|| | fS�)z. Create git archive in given source directory �archiver����z--outputNr&���z--prefixr<���r���z#Failed to perform archive operationzLGit archive command failed to create archive %s using %s directory.Error: %srp���)�insertrA���r���)rE���r���rm���r�����archive_fmt�archive_prefixr|���rG���rH���r}���r���r���r���r ����git_archiveS��s������r����c�������������� ���C���sl��ddddd�}t�j�|�\} } |�| d�}|du�rD|jd|�dd ��|�d �d��dd �}t�j�|��rHt� ��} t�j� | |�}|d�|�}t|�||||||��t� ||�r�|jdd��zt�| ��W�n�ty����Y�n0�nlz&t�||��t�| ��|jdd��W�nD�t�yD�}�z*|jd||f�dt|��d ��W�Y�d}~n d}~0�0�n t|�||||||��|jdd��dS�)z8 Helper function for creating archive using git_archive �zipztar.gz�tarZtgz)z.zipz.gzz.tarz.tgzNz8Unable to get file extension from archive file name : %szoPlease specify archive as filename with extension. File extension can be one of ['tar', 'tar.gz', 'zip', 'tgz']rp���r'���r&���r���r#����.F�r����TzFailed to move %s to %sz Error occurred while moving : %s)r���r����splitextrZ���r���r.���r-���r���rX���Zmkdtempr���r�����filecmp�cmpr����r����rmtreer���r���r���)rE���r���rm���r����r����r|���r����r���Zall_archive_fmt�_Zarchive_extr����Z repo_nameZtempdirZnew_archive_destZnew_archive�er���r���r ����create_archiveb��sJ������� ���r����c������������$������C���sZ��t�ttdd�tddgd�tdd�tdd�td�d�td�d�td d d�td�dd�td d d�td d d�td d d�tg�ddd�td d d�td d d�td�ddd�td�dd�td�dd�td d d�td d d�tdd d�td d d�td�dd�tdd�t��tdd�d�ddgddgidd�}�|�jd�}|�jd�}|�jd�}|�jd�}|�jd�}|�jd �}|�jd!�}|�jd"�}|�jd#�} |�jd$�} |�jd%�}|�jd&�}|�jd'�} |�jd(�}|�jd)��p�|��d*d�}|�jd+�}|�jd,�}|�jd-�}|�jd�}|�jd�}|�jd.�}tdt��d/�}|�jd0��r0|d�u�r,d1|v�r0d2|v�r0|d37�}nd1}|�jd4��r~t|���sR|��d5��n,|d�u�rzd1|v�r~d2|v�r~|d67�}nd2}|d�u�r�t|t��s�|�j d7d8��zt |d9�}W�n.�t�y����|�j d:tt ���d;��d<��Y�n0�t�|��tj�|��d=��rd>tj�|��}t|��}t||||d?�|�_|�r8tj�|�}d�}|�sV| �rV|�j d@d8��n�|�rtj�|�}zPt|| �}|�r�tj�|��r�||k�r�d|dA<�|�j�s�t|�||||��|}W�n<�ttf�y��}�z|�j dBt|�d<��W�Y�d�}~n d�}~0�0�tj�|dC�}t||��}t ||||���|d�u�rB|t!dD�k��rB|��dE��d�}|�jdF�}|�jdG�}|j"d�dH��d}|�rztj�|��r�|�s$| �s$|�j�s�| �s�t#||�|||| �}|j"d|dI��|�j$�r�t%|�|||||| |dJ�|dK�� } | �r�| |dL<�|�j&f�i�|���t'||�|||||| | |||||||���n�|�s�t(|�||�|dJ<�|j"|dJ�dM��|�r�|�j�rt|j"ddN��|�j&f�i�|���t)||�||||||��|�j&f�i�|����nlt*|�||| �}t(|�||�|dJ<�|�r |�s�|�j f�dOdP|�dQ�i|���|�j�s t+||�|��|j"ddP|�dR��|�j�rBt,||�||�}!|!�o>|!|k�o>t-|!�t-|�k}"nt.||�|||�}"|j"|"dS��|�j�r�t#||�|||| �}|j"|dJ�|k�p�|"|dI��|�j$�r�t%|�|||||| |dJ�|dK�� } | �r�| |dL<�|�j&f�i�|���nt/||�|||||| |||dT��t(|�||�|dK<�| �s&t0||�||||||��d}#|�r�| �s�t1||�|||�}#|#�r�|j"|#dU��|�j�r~|j"d|dI��|�j&f�i�|���t2||�|||dT��t(|�||�|dK<�|dJ�|dK�k�s�|�s�|#�s�|"�r|j"ddN��|�j$�rt%|�|||||| |dJ�|dK�� } | �r| |dL<�|�rF|�j�r0|j"ddN��|�j&f�i�|���t)||�||||||��|�j&f�i�|���d�S�)VNr���)�typeT�name)�required�aliasesrk���)�defaultr�����no�bool)r����r�����intZyesr����r����)r����r�����elementsF)r����r����r����)r����r�����raw)rm���r����r|���r1���r����r����r����r����r���r����r����r����re����accept_newhostkeyrf���rg���� executabler����� recursiver����r�����umaskr����r����r����)r����r����)re���r����r����r����)Z argument_specZmutually_exclusiveZrequired_byZsupports_check_moderm���r����r|���r1���r����r����r����r����r���r����r����r����r����r����r�����gitrf���rg���r����r����)r�����warningsre���z-o StrictHostKeyChecking=noz#-o StrictHostKeyChecking=accept-newz -o StrictHostKeyChecking=nor����zWYour ssh client does not support accept_newhostkey option, therefore it cannot be used.z$ -o StrictHostKeyChecking=accept-newz/umask must be defined as a quoted octal integerr �������zumask must be an octal integerr$���rp���r'���r����)�LANG�LC_ALL�LC_MESSAGES�LC_CTYPEz;the destination directory must be specified unless clone=nor����r����Zconfigz1.9.1z[git version is too old to fully support the depth argument. Falling back to full checkouts.r����r����)r����)r����r����r����r�����diff)r����r����r���z.Local modifications exist in the destination: z (force=no).)r����r���)�remote_url_changed)r����)Zsubmodules_changed)3r����dictrF���r ���r����rs���r����� isinstancer���r���r����r,���r����sys�exc_infor���r����r���r8���rC���r ���Zrun_command_environ_updater7����abspathr����r���Z check_moder!���r���rr���r���rh���rj���r���r����r����Z_diffr����Z exit_jsonr���ro���r����r����r����r����r;���r����r����r����r����r����)$r���rm���r����r|���r1���r����r����r����r����Zallow_cloner����r����r����r����r����rE���rf���rg���r����r����r����r����r����localeZ gitconfigr����r���r����r����r����Z local_modsZremote_headr����r����r����Zsubmodules_updatedr���r���r ����main���sb��� ��! � � �" $ r���__main__)NF)rk���)rk���)F)F)F)CZ __future__r���r���r���r����Z __metaclass__Z DOCUMENTATIONZEXAMPLESZRETURNr����r���r����rB���r\���r��r���rX���Z#ansible.module_utils.compat.versionr���Zansible.module_utils._textr���r���Zansible.module_utils.basicr���Z"ansible.module_utils.common.localer ���Z#ansible.module_utils.common.processr ���Zansible.module_utils.sixr���r���r!���r5���r;���rO���rd���rj���ro���rs���r~���r���r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����rh���r����r����r���__name__r���r���r���r ����<module>���sr����e;! %5 G - >- )2�v