U
    楡c%                     @   s   d dl mZmZ ddlmZmZ d dlmZmZm	Z	m
Z
mZmZ d dlmZmZmZ erdd dlmZ dgZedef edef d	d
dZG dd deeeZdS )    )	LazyMixinIterableObj   )SymbolicReferenceT_References)AnyCallableIteratorTypeUnionTYPE_CHECKING)
Commit_ishPathLike_T)Repo	Reference.)funcreturnc                    s"   t ttd fdd} j|_|S )zOA decorator raising a TypeError if we are not a valid remote, based on the path)selfargsr   c                    s$   |   std| j  | f| S )Nz1ref path does not point to a remote reference: %s)Z	is_remote
ValueErrorpath)r   r   r    6/tmp/pip-unpacked-wheel-_pbxsds5/git/refs/reference.pywrapper   s    z(require_remote_ref_path.<locals>.wrapper)r   r   r   __name__)r   r   r   r   r   require_remote_ref_path   s    r   c                	       s   e Zd ZdZdZdZdZdZddee	dd fd	d
Z
edddZdeedef eedf d d fddZeedddZedee deedf eeee dddZeeedddZeeedddZ  ZS )r   zRepresents a named reference to any object. Subclasses may apply restrictions though,
    i.e. Heads can only point to commits.r   FTrefsr   N)repor   
check_pathr   c                    sJ   |r0t || jd s0td| jjd| |  tt| || dS )ab  Initialize this instance
        :param repo: Our parent repository

        :param path:
            Path relative to the .git/ directory pointing to the ref in question, i.e.
            refs/heads/master
        :param check_path: if False, you can provide any path. Otherwise the path must start with the
            default path prefix of this type./zCannot instantiate z from path N)	str
startswith_common_path_defaultr   	__class__r   superr   __init__)r   r   r   r    r%   r   r   r'   2   s    	zReference.__init__)r   c                 C   s   | j S )N)name)r   r   r   r   __str__@   s    zReference.__str__r   )objectlogmsgr   c                    sZ   d}|dk	r,| j j}|js,|j| kr,| jj}tt| || |dk	rV| j j	|| | S )zZSpecial version which checks if the head-log needs an update as well
        :return: selfN)
r   headZis_detachedrefcommitZbinshar&   r   
set_objectZ
log_append)r   r+   r,   Z	oldbinshar-   r(   r   r   r0   F   s    zReference.set_objectc                 C   s0   | j d}t|dk r| j S d|dd S )zK:return: (shortest) Name of this reference - it may contain path componentsr!         N)r   splitlenjoinr   tokensr   r   r   r)   k   s    zReference.name)clsr   common_pathr   kwargsr   c                 O   s   |  ||S )zdEquivalent to SymbolicReference.iter_items, but will return non-detached
        references as well.)Z_iter_items)r8   r   r9   r   r:   r   r   r   
iter_itemsu   s    
zReference.iter_itemsc                 C   s   | j d}|d S )z
        :return:
            Name of the remote we are a reference of, such as 'origin' for a reference
            named 'origin/master'r!   r2   )r   r3   r6   r   r   r   remote_name   s    zReference.remote_namec                 C   s   | j d}d|dd S )z:return: Name of the remote head itself, i.e. master.
        :note: The returned name is usually not qualified enough to uniquely identify
            a branchr!   r1   N)r   r3   r5   r6   r   r   r   remote_head   s    zReference.remote_head)T)N)N)r   
__module____qualname____doc__	__slots__Z_points_to_commits_onlyZ_resolve_ref_on_creater$   r   boolr'   r"   r*   r   r   r0   propertyr)   classmethodr
   r   r   r	   r;   r   r<   r=   __classcell__r   r   r(   r   r   (   s>   	 
%	 
	N)Zgit.utilr   r   Zsymbolicr   r   typingr   r   r	   r
   r   r   Z	git.typesr   r   r   Zgit.repor   __all__r   r   r   r   r   r   <module>   s     