o
    ﯪg¶                     @   s  d Z g dZddlZddlZddlZddlmZmZ ddlm	Z	m
Z
 ddlmZmZmZ ddlmZ ddlmZmZmZ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!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+ ddl,m-Z-m.Z.m/Z/ e'rddl0m1Z1 ddl2m3Z3 ddl4m5Z5 e.d Z6e7e8Z9dedede)ede def df defddZ:e+dddefddZ;e+de def defddZ;e+dedefddZ;de)e def edf de)eef fddZ;G dd deZ<G dd  d ee< Z=G d!d" d"eZ>G d#d$ d$eeZ?dS )%zHModule implementing a remote object allowing easy access to git remotes.)RemoteProgressPushInfo	FetchInfoRemote    N)Githandle_process_output)defenc
force_text)GitConfigParserSectionConstraintcp)GitCommandError)Head	ReferenceRemoteReferenceSymbolicReferenceTagReference)CallableRemoteProgressIterableListIterableObj	LazyMixinr   	join_path)AnyCallableDictIteratorListNoReturnOptionalSequenceTYPE_CHECKINGTypeUnioncastoverload)AnyGitObjectLiteralPathLike)Commit)UpdateProgress)Repo) !+-*=t?kwargsgitprogressr)   .returnc                 C   s*   |dur|j dd }|dkrd| d< | S )a  Add the ``--progress`` flag to the given `kwargs` dict if supported by the git
    command.

    :note:
        If the actual progress in the given progress instance is not given, we do not
        request any progress.

    :return:
        Possibly altered `kwargs`
    N   )      Tr5   )version_info)r3   r4   r5   v r<   F/var/www/html/chatdoc2/venv/lib/python3.10/site-packages/git/remote.pyadd_progress>   s
   r>   c                 C      d S Nr<   r5   r<   r<   r=   to_progress_instanceY      rB   c                 C   r?   r@   r<   rA   r<   r<   r=   rB   ]   rC   c                 C   r?   r@   r<   rA   r<   r<   r=   rB   a   rC   c                 C   s"   t | rt| S | du rt S | S )zaGiven the `progress` return a suitable object derived from
    :class:`~git.util.RemoteProgress`.N)callabler   r   rA   r<   r<   r=   rB   e   s
   c                   @   s   e Zd ZdZdZdZdd edD \ZZZ	Z
ZZZZZZZe	edeeeedZ			
d#dedeed	f dedddee dedd	fddZeded fddZedeeef fddZedddedd fddZeddde d e de!fd!d"Z"d	S )$r   ah  
    Carries information about the result of a push operation of a single head::

        info = remote.push()[0]
        info.flags          # bitflags providing more information about the result
        info.local_ref      # Reference pointing to the local reference that was pushed
                            # It is None if the ref was deleted.
        info.remote_ref_string # path to the remote reference located on the remote side
        info.remote_ref # Remote Reference on the local side corresponding to
                        # the remote_ref_string. It can be a TagReference as well.
        info.old_commit # commit at which the remote_ref was standing before we pushed
                        # it to local_ref.commit. Will be None if an error was indicated
        info.summary    # summary line providing human readable english text about the push
    )	local_refremote_ref_stringflags_old_commit_sha_remotesummarypushinfoc                 C      g | ]}d |> qS r8   r<   .0xr<   r<   r=   
<listcomp>       zPushInfo.<listcomp>   r   )Xr.   r/   r-   r+   r0   r,   N rG   rE   rF   remoter   
old_commitrJ   r6   c                 C   s(   || _ || _|| _|| _|| _|| _dS )zInitialize a new instance.

        local_ref: HEAD | Head | RemoteReference | TagReference | Reference | SymbolicReference | None
        N)rG   rE   rF   rI   rH   rJ   )selfrG   rE   rF   rV   rW   rJ   r<   r<   r=   __init__   s   
zPushInfo.__init__)r(   Nc                 C   s   | j r| jj| j pd S r@   )rH   rI   repocommitrX   r<   r<   r=   rW      s   zPushInfo.old_commitc                 C   sd   | j drt| jj| j S | j dr+t| jj| j }t| jjdt| j|jf S t	d| j  )z
        :return:
            Remote :class:`~git.refs.reference.Reference` or
            :class:`~git.refs.tag.TagReference` in the local repository corresponding to
            the :attr:`remote_ref_string` kept in this instance.
        z	refs/tagsz
refs/headszrefs/remotes/%s/%szCould not handle remote ref: %r)
rF   
startswithr   rI   rZ   r   r   strname
ValueError)rX   
remote_refr<   r<   r=   ra      s   	zPushInfo.remote_reflinec              
   C   sR  | dd\}}}d}z	|| j| O }W n ty) } z	td||f |d}~ww | d\}}	|| j@ r9d}
n|dkr@d}
nt|j|}
d}|drd	|v rX|| j	O }nHd
|v rb|| j
O }n>d|v rl|| jO }n4d|v rv|| jO }n*d|v r|| jO }n d|v r|| jO }nd}|dkrd}| dd  |\}}|}t||
|	|||S )zCreate a new :class:`PushInfo` instance as parsed from line which is expected
        to be like refs/heads/master:refs/heads/master 05d2687..1d0568e as bytes.	   r   3Control character %r unknown as parsed from line %rN:z(delete)[z
[rejected]z[remote rejected]z[remote failure]z
[no match]z	[new tag]z[new branch]...r+   ..)split	_flag_mapKeyErrorr`   DELETEDr   	from_pathrZ   r]   REJECTEDREMOTE_REJECTEDREMOTE_FAILUREERRORNEW_TAGNEW_HEADr   )clsrV   rb   control_characterfrom_torJ   rG   efrom_ref_stringto_ref_stringfrom_refrW   split_tokenold_sha_new_shar<   r<   r=   
_from_line   sF   


zPushInfo._from_linerZ   r*   argsr3   c                 O      t r@   NotImplementedErrorru   rZ   r   r3   r<   r<   r=   
iter_items     zPushInfo.iter_items)NrU   )#__name__
__module____qualname____doc__	__slots___id_attribute_rangers   rt   NO_MATCHro   rp   rq   rm   FORCED_UPDATEFAST_FORWARD
UP_TO_DATErr   rk   intr"   r   r^   r   rY   propertyrW   r   r   ra   classmethodr   r   r   r   r<   r<   r<   r=   r   v   sd    	

4 r   c                       s6   e Zd ZdZd
ddZd fddZddd	Z  ZS )PushInfoListz=:class:`~git.util.IterableList` of :class:`PushInfo` objects.r6   c                 C   s   t tt| dS N
push_infos)r#   r   r   __new__ru   r<   r<   r=   r        zPushInfoList.__new__Nc                    s   t  d d | _d S r   )superrY   errorr\   	__class__r<   r=   rY     s   
zPushInfoList.__init__c                 C   s   | j r| j dS )z-Raise an exception if any ref failed to push.N)r   r\   r<   r<   r=   raise_if_error  s   zPushInfoList.raise_if_error)r6   r   r6   N)r   r   r   r   r   rY   r   __classcell__r<   r<   r   r=   r     s
    
r   c                   @   s  e Zd ZU dZdZdZdd edD \ZZZ	Z
ZZZZedZeede	ee
d	Zeeef ed
< eded fddZ			d)dedededeedf dee ddfddZ defddZ!e"defddZ#e"d*ddZ$edd d!ed"edd fd#d$Z%edd d%e&d&e&de'fd'd(Z(dS )+r   a*  
    Carries information about the results of a fetch operation of a single head::

     info = remote.fetch()[0]
     info.ref           # Symbolic Reference or RemoteReference to the changed
                        # remote head or FETCH_HEAD
     info.flags         # additional flags to be & with enumeration members,
                        # i.e. info.flags & info.REJECTED
                        # is 0 if ref is SymbolicReference
     info.note          # additional notes given by git-fetch intended for the user
     info.old_commit    # if info.flags & info.FORCED_UPDATE|info.FAST_FORWARD,
                        # field is set to the previous location of ref, otherwise None
     info.remote_ref_path # The path from which we fetched on the remote. It's the remote's version of our info.ref
    )refrW   rG   noteremote_ref_path	fetchinfoc                 C   rL   rM   r<   rN   r<   r<   r=   rQ   =  rR   zFetchInfo.<listcomp>   zK^ *(?:.{0,3})(.) (\[[\w \.$@]+\]|[\w\.$@]+) +(.+) -> ([^ ]+)(    \(.*\)?$)?r   )r,   r-   r/   r0   r+   r.   rk   r6   Tc                 C   s   t t | jd= W d   n1 sw   Y  t t | jd= W d   n1 s-w   Y  t jdd dkrD| j| jd< dS | j| jd< dS )zUpdate information about which :manpage:`git-fetch(1)` flags are supported
        by the git executable being used.

        Called by the :func:`git.refresh` function in the top level ``__init__``.
        r1   Nr.   r7   )r7   
   T)
contextlibsuppressrl   rk   r   r:   
TAG_UPDATEr   r<   r<   r=   refreshJ  s   

zFetchInfo.refreshrU   Nr   rG   r   rW   r   c                 C   s"   || _ || _|| _|| _|| _dS )zInitialize a new instance.N)r   rG   r   rW   r   )rX   r   rG   r   rW   r   r<   r<   r=   rY   _  s
   	
zFetchInfo.__init__c                 C      | j S r@   r_   r\   r<   r<   r=   __str__n     zFetchInfo.__str__c                 C      | j jS )z:return: Name of our remote ref)r   r_   r\   r<   r<   r=   r_   q     zFetchInfo.namer(   c                 C   r   )z!:return: Commit of our remote ref)r   r[   r\   r<   r<   r=   r[   v  r   zFetchInfo.commitrZ   r*   rb   
fetch_linec              
   C   s\  | j |}|du rtd| | \}}}}}	tt|}z|d\}
}}|dd\}}W n tyC } ztd| |d}~ww d}z	|| j| O }W n tyd } z	td||f |d}~ww d}d	}d
|v rr|| j	O }d|v r}|| j
O }d}d|v r|| jO }d}d|v r|| jO }d|v sd|v rd}|dkr|dd }|||d }d}|dkrt}n|dks|rt}n|dv rt}nd|v rt}ntd| |tu r||d}n=d}| }|tjd r|}|tur|tjd st}n|tu rd|v rttj|}nt|j|}|||d	d}|	r$|	 p%d}	| |||	||S )a  Parse information from the given line as returned by ``git-fetch -v`` and
        return a new :class:`FetchInfo` object representing this information.

        We can handle a line as follows::

            %c %-*s %-*s -> %s%s

        Where ``c`` is either a space, ``!``, ``+``, ``-``, ``*``, or ``=``:

        - '!' means error
        - '+' means success forcing update
        - '-' means a tag was updated
        - '*' means birth of new branch or tag
        - '=' means the head was up to date (and not moved)
        - ' ' means a fast-forward

        `fetch_line` is the corresponding line from FETCH_HEAD, like::

            acb0fa8b94ef421ad60c8507b634759a472cd56c    not-for-merge   branch '0.1.7RC' of /tmp/tmpya0vairemote_repo
        NzFailed to parse line: %rrc   r+   r8   z#Failed to parse FETCH_HEAD line: %rr   re   Frejectedznew tagTz
tag updatez
new branchrh   ri   
FETCH_HEADtag)zremote-trackingbranch/z Cannot handle reference type: %rztags/)
check_pathrU   )_re_fetch_resultmatchr`   groupsr#   flagKeyLiteralrj   rk   rl   ro   rs   r   rt   	rev_parser   r   r   r   	TypeErrorstripr]   r   _common_path_defaultr   )ru   rZ   rb   r   r   rv   	operationlocal_remote_refremote_local_ref_strr   _new_hex_sha_fetch_operation
fetch_noteref_type_namerx   rG   rW   is_tag_operationr|   ref_typeremote_local_refref_pathr<   r<   r=   r   {  s   





zFetchInfo._from_liner   r3   c                 O   r   r@   r   r   r<   r<   r=   r     r   zFetchInfo.iter_items)rU   NN)r6   r(   ))r   r   r   r   r   r   r   rs   rt   HEAD_UPTODATEr   ro   r   r   rr   recompiler   rk   r   r   r   __annotations__r   r&   r   r   r^   r"   r%   r   r'   rY   r   r   r_   r[   r   r   r   r   r<   r<   r<   r=   r      sd   
 
	

  r   c                       s  e Zd ZU dZdZdZdgZdgZddgZe	e
d< 	 dd	de	d
dfddZde	d
ef fddZd
e	fddZde	d
df fddZd
e	fddZd
e	fddZded
efddZded
efddZd
efddZd
efd d!Zedd	d"ed#ed
ed  fd$d%Z	&d`d'e	d(ee	 d)ed#ed
d f
d*d+Zdade	d)ed#ed
d fd,d-Zde	d#ed
d fd.d/Ze d
ee	 fd0d1Z!e d
e"e# fd2d3Z$e d
e"e% fd4d5Z&edadd	de	de	d)ed#ed
d fd6d7Z'edd	de	de	d#ed
d f
d8d9Z(edd	de	d
e	fd:d;Z)edd	de	d
e	fd<d=Z*d>e	d
d fd?d@Z+d#ed
d fdAdBZ,	dbdCdDdEe-e.dFef e/df dGe-de0f d
e"dH fdIdJZ1	dbdCdDdEe-e.dFef e/df dGe-de0f d
e2fdKdLZ3dcdMdNZ4			O		&	&dddPe-e	e5e	 df dEe-e/ddQf dRedGe-de0f d)edSed#ed
e"e6 fdTdUZ7				&	&dedPe-e	e5e	 df dEe-e/dQdf dGe-de0f d)edSed#ed
e"e6 fdVdWZ8				&	&dedPe-e	e5e	 df dEe-e/dQe.dFe/f df dGe-de0f d)edSed#ed
e2fdXdYZ9e d
e:e; fdZd[Z<dcd\d]Z=e d
e:fd^d_Z>  Z?S )fr   a^  Provides easy read and write access to a git remote.

    Everything not part of this interface is considered an option for the current
    remote, allowing constructs like ``remote.pushurl`` to query the pushurl.

    :note:
        When querying configuration, the configuration accessor will be cached to speed
        up subsequent accesses.
    )rZ   r_   _config_readerr_   z--upload-packz--receive-packz--execurlrZ   r*   r6   Nc                 C   s   || _ || _dS )zInitialize a remote instance.

        :param repo:
            The repository we are a remote of.

        :param name:
            The name of the remote, e.g. ``origin``.
        N)rZ   r_   )rX   rZ   r_   r<   r<   r=   rY   +  s   	
zRemote.__init__attrc                    sD   |dkr
t  |S z| j|W S  tjy!   t  | Y S w )zwAllows to call this instance like ``remote.special(*args, **kwargs)`` to
        call ``git remote special self.name``.r   )r   __getattr__r   getr   NoOptionErrorrX   r   r   r<   r=   r   7  s   zRemote.__getattr__c                 C   s
   d| j  S )Nzremote "%s"r   r\   r<   r<   r=   _config_section_nameE     
zRemote._config_section_namec                    s4   |dkrt | jd|  | _d S t | d S )Nr   
repository)r   rZ   config_readerr   r   r   _set_cache_r   r   r<   r=   r   H  s   

zRemote._set_cache_c                 C   r   r@   r   r\   r<   r<   r=   r   S  r   zRemote.__str__c                 C   s   d| j j| jf S )Nz<git.%s "%s">)r   r   r_   r\   r<   r<   r=   __repr__V  r   zRemote.__repr__otherc                 C   s   t |t| o| j|jkS r@   )
isinstancetyper_   rX   r   r<   r<   r=   __eq__Y  s   zRemote.__eq__c                 C   s
   | |k S r@   r<   r   r<   r<   r=   __ne__\  r   zRemote.__ne__c                 C   s
   t | jS r@   )hashr_   r\   r<   r<   r=   __hash___  r   zRemote.__hash__c                 C   s>   z	| j d W dS  tjy   Y dS  tjy   Y dS w )z
        :return:
            ``True`` if this is a valid, existing remote.
            Valid remotes have an entry in the repository's configuration.
        r   TF)r   r   r   r   NoSectionErrorr\   r<   r<   r=   existsb  s   zRemote.existsr   r3   c                 o   sn    | d D ],}|dsq|d}|d}|dks"|dkr(td| t|||d | V  qdS )zJ:return: Iterator yielding :class:`Remote` objects of the given repositoryr   zremote "r   z%Remote-Section has invalid format: %rr8   N)r   sectionsr]   findrfindr`   r   )ru   rZ   r   r3   sectionlboundrboundr<   r<   r=   r   q  s   


zRemote.iter_itemsFnew_urlold_urlallow_unsafe_protocolsc                 K   sd   |st | d}||d< |r!| jjj|d| j||fi | | S | jjj|d| j|fi | | S )a  Configure URLs on current remote (cf. command ``git remote set-url``).

        This command manages URLs on the remote.

        :param new_url:
            String being the URL to add as an extra remote URL.

        :param old_url:
            When set, replaces this URL with `new_url` for the remote.

        :param allow_unsafe_protocols:
            Allow unsafe protocols to be used, like ``ext``.

        :return:
            self
        zset-urlinsert_kwargs_after--)r   check_unsafe_protocolsrZ   r4   rV   r_   )rX   r   r   r   r3   scmdr<   r<   r=   set_url~  s   
 zRemote.set_urlc                 K   s   | j |d|dS )a  Adds a new url on current remote (special case of ``git remote set-url``).

        This command adds new URLs to a given remote, making it possible to have
        multiple URLs for a single remote.

        :param url:
            String being the URL to add as an extra remote URL.

        :param allow_unsafe_protocols:
            Allow unsafe protocols to be used, like ``ext``.

        :return:
            self
        T)addr   r   )rX   r   r   r3   r<   r<   r=   add_url  s   zRemote.add_urlc                 K   s   | j |ddS )aJ  Deletes a new url on current remote (special case of ``git remote set-url``).

        This command deletes new URLs to a given remote, making it possible to have
        multiple URLs for a single remote.

        :param url:
            String being the URL to delete from the remote.

        :return:
            self
        T)deleter   )rX   r   r3   r<   r<   r=   
delete_url  s   zRemote.delete_urlc                 #   sN   z| j jdd| j}t|tsJ |dD ]}|V  qW dS  ty } zzdt|v rz&| j jd| j}t|ts?J |dD ]}d|v rR|dd V  qDW n? ty   z1t fd	d
dD r| j j	dd| j }t|tsyJ |dD ]}|V  q~n W Y d  nd  ww |W Y d}~dS W Y d}~dS d}~ww )zL:return: Iterator yielding all configured URL targets on a remote as stringszget-urlz--all
zUnknown subcommand: get-urlshowz  Push  URL:z: r   c                 3   s    | ]	}|t  v V  qd S r@   )r^   )rO   msg_exr<   r=   	<genexpr>  s    zRemote.urls.<locals>.<genexpr>)zcorrect access rightszcannot run sshz	--get-allzremote.%s.urlN)
rZ   r4   rV   r_   r   r^   rj   r   anyconfig)rX   remote_detailsrb   exr<   r   r=   urls  sB   
zRemote.urlsc                 C   s.   t tjd| j }|tj| j| jd |S )a7  
        :return:
            :class:`~git.util.IterableList` of :class:`~git.refs.remote.RemoteReference`
            objects.

            It is prefixed, allowing you to omit the remote path portion, e.g.::

                remote.refs.master  # yields RemoteReference('/refs/remotes/origin/master')
        %s/)rV   )r   r   r   r_   extend
list_itemsrZ   )rX   out_refsr<   r<   r=   refs  s   zRemote.refsc                 C   s   t tjd| j }| jjdd|  dd D ]3}d}||s"q|	|d}|t
jd r;|t
| j| qd	tj|f }|t| j| q|S )
a  
        :return:
            :class:`~git.util.IterableList` of :class:`~git.refs.remote.RemoteReference`
            objects that do not have a corresponding head in the remote reference
            anymore as they have been deleted on the remote side, but are still
            available locally.

            The :class:`~git.util.IterableList` is prefixed, hence the 'origin' must be
            omitted. See :attr:`refs` property for an example.

            To make things more complicated, it can be possible for the list to include
            other kinds of references, for example, tag references, if these are stale
            as well. This is a fix for the issue described here:
            https://github.com/gitpython-developers/GitPython/issues/260
        r  prunez	--dry-runr7   Nz * [would prune] rU   r   z%s/%s)r   r   r   r_   rZ   r4   rV   
splitlinesr]   replacer   r   appendrn   )rX   r
  rb   tokenref_namefqhnr<   r<   r=   
stale_refs  s   "
zRemote.stale_refsc                 K   sH   d}||d< t |}|st | |jj|d||fi | | ||S )a  Create a new remote to the given repository.

        :param repo:
            Repository instance that is to receive the new remote.

        :param name:
            Desired name of the remote.

        :param url:
            URL which corresponds to the remote's name.

        :param allow_unsafe_protocols:
            Allow unsafe protocols to be used, like ``ext``.

        :param kwargs:
            Additional arguments to be passed to the ``git remote add`` command.

        :return:
            New :class:`Remote` instance

        :raise git.exc.GitCommandError:
            In case an origin with that name already exists.
        r   r   r   )r   
polish_urlr   r4   rV   )ru   rZ   r_   r   r   r3   r   r<   r<   r=   create  s   


zRemote.createc                 K   s   | j |||fi |S r@   )r  )ru   rZ   r_   r   r3   r<   r<   r=   r   /  s   z
Remote.addc                 C   s$   |j d| t|| r|  |S )znRemove the remote with the given name.

        :return:
            The passed remote name to remove
        rm)r4   rV   r   _clear_cacheru   rZ   r_   r<   r<   r=   remove3  s   
zRemote.removec                 C   s   |  ||S )zAlias of remove.
        Remove the remote with the given name.

        :return:
            The passed remote name to remove
        )r  r  r<   r<   r=   r  ?  s   z	Remote.rmnew_namec                 C   s4   | j |kr| S | jjd| j | || _ |   | S )zPRename self to the given `new_name`.

        :return:
            self
        rename)r_   rZ   r4   rV   r  )rX   r  r<   r<   r=   r  I  s   
zRemote.renamec                 K   s*   d}||d< | j jj|| jfi | | S )a@  Fetch all changes for this remote, including new branches which will be
        forced in (in case your local remote branch is not part the new remote branch's
        ancestry anymore).

        :param kwargs:
            Additional arguments passed to ``git remote update``.

        :return:
            self
        updater   )rZ   r4   rV   r_   )rX   r3   r   r<   r<   r=   r  X  s   zRemote.updateproczGit.AutoInterruptr5   .kill_after_timeoutr   c                 C   s  t |}td}g }ttj }| }t|d |d d|d |jr(d	|jp)d}|j
|d |r8td| |jD ]#}	t|	}	|D ]}
t|	dkr]|	d	 d
kr]|	d |
kr]||	 qCqCq;t| jd}t|jd}dd | D }W d    n1 sw   Y  t|}t|}||krd}|d7 }|d7 }|||f; }t| tdt|d  tdt|d  ||k r|d | }n|d | }t||D ]2\}}z|t| j|| W q ty } ztd| td|  W Y d }~qd }~ww |S )Nr_   F	finalizerdecode_streamsr  r   rU   stderr'Error lines received while fetching: %sr8   r   r+   r   rbc                 S   s   g | ]}| tqS r<   )decoder   )rO   rb   r<   r<   r=   rQ     s    z6Remote._get_fetch_info_from_stderr.<locals>.<listcomp>zFFetch head lines do not match lines provided via progress information
zKlength of progress lines %i should be equal to lines in FETCH_HEAD file %i
z5Will ignore extra progress lines or fetch head lines.s   info lines: zUTF-8s   head info: z#Caught error while parsing line: %szGit informed while fetching: %s)rB   r   setr   rk   keysnew_message_handlerr   error_linesjoinwait_loggerwarningother_linesr	   lenr  r   rZ   openabspath	readlinesdebugr^   encodezipr   r`   r   )rX   r  r5   r  outputfetch_info_linescmdsprogress_handlerstderr_textrb   cmd
fetch_headfpfetch_head_infol_fill_fhir   err_liner   excr<   r<   r=   _get_fetch_info_from_stderrh  sf   	
$

z"Remote._get_fetch_info_from_stderrc              
      s   t |}| }t  dtdd f fdd}t|||d d|d |jr*d|jp+d}z	|j|d	 W  S  ty] } z s@ |rRt	
d
| | _W Y d }~ S W Y d }~ S d }~ww )Nrb   r6   c                    s.   z  t|  W d S  ty   Y d S w r@   )r  r   r   r`   )rb   r7  rX   r<   r=   stdout_handler  s
   z-Remote._get_push_info.<locals>.stdout_handlerFr  r   rU   r"  r$  )rB   r)  r   r^   r   r*  r+  r,  	Exceptionr-  r.  r   )rX   r  r5   r  r:  rF  r;  rx   r<   rE  r=   _get_push_info  s6   

zRemote._get_push_infoc                 C   s^   | j }d}z$|jd|d|u r#d}|d7 }|d7 }t|| j| jf W |  dS |  w )z?Turns out we can't deal with remotes if the refspec is missing.placeholderfetch)defaultz Remote '%s' has no refspec set.
zYou can set it as follows:zA 'git config --add "remote.%s.fetch +refs/heads/*:refs/heads/*"'.N)r   	get_valueAssertionErrorr_   release)rX   r  unsetr   r<   r<   r=   _assert_refspec  s   zRemote._assert_refspecTrefspecr)   verboseallow_unsafe_optionsc                 K   s   |du r|    t|| jj|}t|tr|}n|g}|s)|D ]	}	|	r(t|	 q|s7tjt|	 | j
d | jjjd| g|R ddd|d|}
| j|
||d}t| jjdr`| jj  |S )	a  Fetch the latest changes for this remote.

        :param refspec:
            A "refspec" is used by fetch and push to describe the mapping
            between remote ref and local ref. They are combined with a colon in
            the format ``<src>:<dst>``, preceded by an optional plus sign, ``+``.
            For example: ``git fetch $URL refs/heads/master:refs/heads/origin`` means
            "grab the master branch head from the $URL and store it as my origin
            branch head". And ``git push $URL refs/heads/master:refs/heads/to-upstream``
            means "publish my master branch head as to-upstream branch at $URL".
            See also :manpage:`git-push(1)`.

            Taken from the git manual, :manpage:`gitglossary(7)`.

            Fetch supports multiple refspecs (as the underlying :manpage:`git-fetch(1)`
            does) - supplying a list rather than a string for 'refspec' will make use of
            this facility.

        :param progress:
            See the :meth:`push` method.

        :param verbose:
            Boolean for verbose output.

        :param kill_after_timeout:
            To specify a timeout in seconds for the git command, after which the process
            should be killed. It is set to ``None`` by default.

        :param allow_unsafe_protocols:
            Allow unsafe protocols to be used, like ``ext``.

        :param allow_unsafe_options:
            Allow unsafe options to be used, like ``--upload-pack``.

        :param kwargs:
            Additional arguments to be passed to :manpage:`git-fetch(1)`.

        :return:
            IterableList(FetchInfo, ...) list of :class:`FetchInfo` instances providing
            detailed information about the fetch results

        :note:
            As fetch does not provide progress information to non-ttys, we cannot make
            it available here unfortunately as in the :meth:`push` method.
        Noptionsunsafe_optionsr   TF)
as_processwith_stdoutuniversal_newlinesr;   r  update_cache)rP  r>   rZ   r4   r   listr   r   check_unsafe_optionsr(  unsafe_git_fetch_optionsrJ  rD  hasattrodbr[  )rX   rQ  r5   rR  r  r   rS  r3   r   r   r  resr<   r<   r=   rJ    s4   7

zRemote.fetchc           
      K   s   |du r|    t|| jj|}t|pg }|s#|D ]}t| q|s1tjt|	 | j
d | jjjd| |fddddd|}| j|||d}	t| jjdrX| jj  |	S )	a  Pull changes from the given branch, being the same as a fetch followed by a
        merge of branch with your local branch.

        :param refspec:
            See :meth:`fetch` method.

        :param progress:
            See :meth:`push` method.

        :param kill_after_timeout:
            See :meth:`fetch` method.

        :param allow_unsafe_protocols:
            Allow unsafe protocols to be used, like ``ext``.

        :param allow_unsafe_options:
            Allow unsafe options to be used, like ``--upload-pack``.

        :param kwargs:
            Additional arguments to be passed to :manpage:`git-pull(1)`.

        :return:
            Please see :meth:`fetch` method.
        NrT  r   FT)rX  rW  rY  r;   rZ  r[  )rP  r>   rZ   r4   r   _unpack_argsr   r]  r\  r(  unsafe_git_pull_optionspullrD  r_  r`  r[  )
rX   rQ  r5   r  r   rS  r3   r   r  ra  r<   r<   r=   rd  9  s(   !zRemote.pullc           	      K   s   t || jj|}t|pg }|s|D ]}t| q|s)tjt| | j	d | jjj
d| |fddd|d|}| j|||dS )a  Push changes from source branch in refspec to target branch in refspec.

        :param refspec:
            See :meth:`fetch` method.

        :param progress:
            Can take one of many value types:

            * ``None``, to discard progress information.
            * A function (callable) that is called with the progress information.
              Signature: ``progress(op_code, cur_count, max_count=None, message='')``.
              See :meth:`RemoteProgress.update <git.util.RemoteProgress.update>` for a
              description of all arguments given to the function.
            * An instance of a class derived from :class:`~git.util.RemoteProgress` that
              overrides the
              :meth:`RemoteProgress.update <git.util.RemoteProgress.update>` method.

        :note:
            No further progress information is returned after push returns.

        :param kill_after_timeout:
            To specify a timeout in seconds for the git command, after which the process
            should be killed. It is set to ``None`` by default.

        :param allow_unsafe_protocols:
            Allow unsafe protocols to be used, like ``ext``.

        :param allow_unsafe_options:
            Allow unsafe options to be used, like ``--receive-pack``.

        :param kwargs:
            Additional arguments to be passed to :manpage:`git-push(1)`.

        :return:
            A :class:`PushInfoList` object, where each list member represents an
            individual head which had been updated on the remote side.

            If the push contains rejected heads, these will have the
            :const:`PushInfo.ERROR` bit set in their flags.

            If the operation fails completely, the length of the returned
            :class:`PushInfoList` will be 0.

            Call :meth:`~PushInfoList.raise_if_error` on the returned object to raise on
            any failure.
        rT  r   T)	porcelainrW  rY  r  rZ  )r>   rZ   r4   r   rb  r   r]  r\  r(  unsafe_git_push_optionspushrH  )	rX   rQ  r5   r  r   rS  r3   r   r  r<   r<   r=   rg  o  s(   7
zRemote.pushc                 C   r   )z
        :return:
            :class:`~git.config.GitConfigParser` compatible object able to read options
            for only our remote. Hence you may simply type ``config.get("pushurl")`` to
            obtain the information.
        )r   r\   r<   r<   r=   r     s   zRemote.config_readerc                 C   s    z| ` W d S  ty   Y d S w r@   )r   AttributeErrorr\   r<   r<   r=   r    s
   
zRemote._clear_cachec                 C   s    | j  }|   t||  S )a  
        :return:
            :class:`~git.config.GitConfigParser`-compatible object able to write options
            for this remote.

        :note:
            You can only own one writer at a time - delete it to release the
            configuration file and make it usable by others.

            To assure consistent results, you should only query options through the
            writer. Once you are done writing, you are free to use the config reader
            once again.
        )rZ   config_writerr  r   r   )rX   writerr<   r<   r=   ri    s   
zRemote.config_writer)NF)Fr@   r   )NNTNFF)NNNFF)@r   r   r   r   r   r   r^  rc  rf  r^   r   rY   r   r   r   r   r   r   objectboolr   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r   r  r   r  r  r   r  r  r  r  r"   r   r   floatrD  r   rH  rP  r   r   rJ  rd  rg  r   r
   r   r  ri  r   r<   r<   r   r=   r     s   
 
 
 "&! 	

K


,
	
S

8

M
	r   )@r   __all__r   loggingr   git.cmdr   r   
git.compatr   r	   
git.configr
   r   r   git.excr   git.refsr   r   r   r   r   git.utilr   r   r   r   r   r   typingr   r   r   r   r   r   r   r   r    r!   r"   r#   r$   	git.typesr%   r&   r'   git.objects.commitr(   git.objects.submodule.baser)   git.repo.baser*   r   	getLoggerr   r-  r>   rB   r   r   r   r   r<   r<   r<   r=   <module>   sZ    <



  i