
    Vh                    H    d Z ddlmZ ddlZddlZddlmZmZ  G d d      Z	y)&Wrapper around git command-line tools.    )annotationsN   )SubprocessErrorraw_commandc                  z    e Zd ZdZdddZdddZddZddZddZddZ	dd	Z
ddd
ZddZddZdddZdddZy)Gitr   Nc                     d| _         || _        y )Ngit)r   root)selfr   s     J/home/dcms/DCMS/lib/python3.12/site-packages/ansible_test/_internal/git.py__init__zGit.__init__   s    	    c                H    dg|z   }|ddg}| j                  ||z   dd      S )z/Run `git diff` and return the result as a list.diffz-czcore.quotePath=
replace
str_errorsrun_git_split)r   argsgit_optionscmds       r   get_diffzGit.get_diff   s;    ho!23K!!+"3Ti!PPr   c                4    g d|z   }| j                  |d      S )z8Return a list of file names from the `git diff` command.)r   z--name-onlyz--no-renames-z r   r   r   r   s      r   get_diff_nameszGit.get_diff_names   s    ;dB!!#t,,r   c                    g d}| j                  |d      }|D cg c]'  }t        j                  d|      j                  d      ) }}|D cg c]  }|j	                  d      r| }}|S c c}w c c}w )z-Return a list of submodule paths recursively.)	submodulestatusz--recursiver   z^.[0-9a-f]+ (?P<path>[^ ]+)pathz../)r   researchgroup
startswith)r   r   outputlinesubmodule_pathsr%   s         r   get_submodule_pathszGit.get_submodule_paths    sx    4##C.ekl]a299%CTJPPQWXll -<ZD4??SXCY4ZZ m [s   ,A,A1$A1c                4    ddg|z   }| j                  |d      S )z<Return a list of file names from the `git ls-files` command.zls-filesr   r   r   r    s      r   get_file_nameszGit.get_file_names1   s$    4 4'!!#t,,r   c                ,    g d}| j                  |      S )zReturn the list of branches.)zfor-each-refzrefs/heads/z--formatz%(refname:strip=2)r   r   r   s     r   get_brancheszGit.get_branches6   s    O!!#&&r   c                H    g d}| j                  |      j                         S )zReturn the current branch name.)zsymbolic-refz--shortHEADrun_gitstripr1   s     r   
get_branchzGit.get_branch;   s    1||C &&((r   c                ^    dg}|r||z  }n|dgz  }|r
|dd|z  gz  }| j                  |      S )z;Return the list of results from the `git rev-list` command.zrev-listr4   z--max-countz%sr   )r   commits	max_countr   s       r   get_rev_listzGit.get_rev_list@   sH    l7NCF8OCM4)#344C!!#&&r   c                J    d|dg}| j                  |      j                         S )zEReturn a reference to the point at which the given branch was forked.z
merge-baser4   r5   )r   branchr   s      r   get_branch_fork_pointzGit.get_branch_fork_pointN   s&    VV,||C &&((r   c                R    d|g}	 | j                  |d       y# t        $ r Y yw xY w)zDReturn True if the given reference is valid, otherwise return False.showr   r   TF)r6   r   )r   refr   s      r   is_valid_refzGit.is_valid_refS   s5    sm	LLL3 		s    	&&c                p    | j                  ||      j                  |      }|sg S |j                  |      S )z=Run the given `git` command and return the results as a list.r   )r6   r7   split)r   r   	separatorr   r*   s        r   r   zGit.run_git_split\   s6    cj9??	JI||I&&r   c                V    t        | j                  g|z   | j                  d|      d   S )z?Run the given `git` command and return the results as a string.T)cwdcapturer   r   )r   r   r   )r   r   r   s      r   r6   zGit.run_gite   s)    DHH:+DU_`abccr   )N)r   t.Optional[str]returnNone)r   	list[str]r   t.Optional[list[str]]rK   rM   )r   rM   rK   rM   )rK   rM   )rK   str)NN)r:   rN   r;   zt.Optional[int]rK   rM   )r>   rO   rK   rO   )rB   rO   rK   bool)Nstrict)r   rM   rF   rJ   r   rO   rK   rM   )rQ   )r   rM   r   rO   rK   rO   )__name__
__module____qualname____doc__r   r   r!   r-   r/   r2   r8   r<   r?   rC   r   r6    r   r   r	   r	      sC    0Q-
"-
'
)
')
'dr   r	   )
rU   
__future__r   r&   typingtutilr   r   r	   rV   r   r   <module>r[      s$    , " 	 Zd Zdr   