B
    `                 @   sR   d Z ddlmZmZmZ eZddlZddlm	Z
 ddlmZmZ G dd dZdS )	z&Wrapper around git command-line tools.    )absolute_importdivisionprint_functionN   )types)SubprocessErrorraw_commandc               @   sz   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dS )!Gitz&Wrapper around git command-line tools.Nc             C   s   d| _ || _d S )Ngit)r
   root)selfr    r   I/home/dcms/DCMS/lib/python3.7/site-packages/ansible_test/_internal/git.py__init__   s    zGit.__init__c             C   s.   dg| }|dkrddg}| j || dddS )zm
        :type args: list[str]
        :type git_options: list[str] | None
        :rtype: list[str]
        diffNz-czcore.quotePath=
replace)
str_errors)run_git_split)r   argsZgit_optionscmdr   r   r   get_diff   s    
zGit.get_diffc             C   s   ddddg| }|  |dS )zA
        :type args: list[str]
        :rtype: list[str]
        r   z--name-onlyz--no-renamesz-z )r   )r   r   r   r   r   r   get_diff_names    s    zGit.get_diff_namesc             C   s6   dddg}|  |d}dd |D }dd |D }|S )z-Return a list of submodule paths recursively.	submodulestatusz--recursiver   c             S   s   g | ]}t d |dqS )z^.[0-9a-f]+ (?P<path>[^ ]+)path)researchgroup).0liner   r   r   
<listcomp>,   s    z+Git.get_submodule_paths.<locals>.<listcomp>c             S   s   g | ]}| d s|qS )z../)
startswith)r    r   r   r   r   r"   5   s    )r   )r   r   outputZsubmodule_pathsr   r   r   get_submodule_paths(   s
    
	zGit.get_submodule_pathsc             C   s   ddg| }|  |dS )zA
        :type args: list[str]
        :rtype: list[str]
        zls-filesz-zr   )r   )r   r   r   r   r   r   get_file_names9   s    zGit.get_file_namesc             C   s   ddddg}|  |S )z#
        :rtype: list[str]
        zfor-each-refzrefs/heads/z--formatz%(refname:strip=2))r   )r   r   r   r   r   get_branchesA   s    zGit.get_branchesc             C   s   dddg}|  | S )z
        :rtype: str
        zsymbolic-refz--shortHEAD)run_gitstrip)r   r   r   r   r   
get_branchH   s    
zGit.get_branchc             C   s<   dg}|r||7 }n
|dg7 }|r2|dd| g7 }|  |S )zo
        :type commits: list[str] | None
        :type max_count: int | None
        :rtype: list[str]
        zrev-listr(   z--max-countz%s)r   )r   Zcommits	max_countr   r   r   r   get_rev_listO   s    

zGit.get_rev_listc             C   s   dd|g}|  | S )z7
        :type branch: str
        :rtype: str
        z
merge-basez--fork-point)r)   r*   )r   branchr   r   r   r   get_branch_fork_pointa   s    
zGit.get_branch_fork_pointc             C   s4   d|g}y| j |dd dS  tk
r.   dS X dS )z5
        :type ref: str
        :rtype: bool
        showr   )r   TFN)r)   r   )r   refr   r   r   r   is_valid_refi   s    zGit.is_valid_refstrictc             C   s&   | j ||d|}|sg S ||S )z
        :type cmd: list[str]
        :type separator: str | None
        :type str_errors: str
        :rtype: list[str]
        )r   )r)   r*   split)r   r   	separatorr   r$   r   r   r   r   u   s    zGit.run_git_splitc             C   s   t | jg| | jd|dd S )zX
        :type cmd: list[str]
        :type str_errors: str
        :rtype: str
        T)cwdcapturer   r   )r   r
   r   )r   r   r   r   r   r   r)      s    zGit.run_git)N)N)NN)Nr3   )r3   )__name__
__module____qualname____doc__r   r   r   r%   r&   r'   r+   r-   r/   r2   r   r)   r   r   r   r   r	      s   



r	   )r;   
__future__r   r   r   type__metaclass__r    r   tutilr   r   r	   r   r   r   r   <module>   s   