o
    ﯪg)                     @   s   d Z ddgZddlmZmZ ddlmZ ddlmZ ddl	m
Z
 dd	lmZ dd
lmZmZmZmZ ddlmZmZ erNddlmZ ddlmZ ddlmZ dedefddZG dd deZG dd de
ZdS )zcSome ref-based objects.

Note the distinction between the :class:`HEAD` and :class:`Head` classes.
HEADHead    )GitConfigParserSectionConstraint)GitCommandError)	join_path   )	Reference)SymbolicReference)AnySequenceTYPE_CHECKINGUnion)
Commit_ishPathLike)CommitRemoteReference)Repostringreturnc                 C   s$   |  dr| dr| dd S | S )N"r   )
startswithendswith)r    r   I/var/www/html/chatdoc2/venv/lib/python3.10/site-packages/git/refs/head.pystrip_quotes    s   r   c                       s   e Zd ZU dZd ZdZdZded< efddded	d
f fddZ	d	e
fddZ	 			
ddeee
ef dededeeee d
f ded	d fddZ  ZS )r   zqSpecial case of a :class:`~git.refs.symbolic.SymbolicReference` representing the
    repository's HEAD reference.	ORIG_HEADr   r   commitrepor   pathr   Nc                    s.   || j krtd| j |f t || d S )Nz&HEAD instance must point to %r, got %r)
_HEAD_NAME
ValueErrorsuper__init__)selfr    r!   	__class__r   r   r%   2   s   
zHEAD.__init__c                 C   s   t | j| jS )z
        :return:
            :class:`~git.refs.symbolic.SymbolicReference` pointing at the ORIG_HEAD,
            which is maintained to contain the previous value of HEAD.
        )r
   r    _ORIG_HEAD_NAMEr&   r   r   r   	orig_head7   s   zHEAD.orig_headTFindexworking_treepathskwargsc              
   K   s~   d}|r
d}|r
d}|rd}|st dz| jjj||d|fi | W | S  ty> } z|jdkr3 W Y d}~| S d}~ww )a.  Reset our HEAD to the given commit optionally synchronizing the index and
        working tree. The reference we refer to will be set to commit as well.

        :param commit:
            :class:`~git.objects.commit.Commit`, :class:`~git.refs.reference.Reference`,
            or string identifying a revision we should reset HEAD to.

        :param index:
            If ``True``, the index will be set to match the given commit.
            Otherwise it will not be touched.

        :param working_tree:
            If ``True``, the working tree will be forcefully adjusted to match the given
            commit, possibly overwriting uncommitted changes without warning.
            If `working_tree` is ``True``, `index` must be ``True`` as well.

        :param paths:
            Single path or list of paths relative to the git root directory
            that are to be reset. This allows to partially reset individual files.

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

        :return:
            self
        z--softz--mixedNz--hardz?Cannot reset the working tree if the index is not reset as wellz--r   )r#   r    gitresetr   status)r&   r   r,   r-   r.   r/   modeer   r   r   r1   ?   s&   #

z
HEAD.reset)r   TFN)__name__
__module____qualname____doc__r"   r)   	__slots____annotations__r   r%   r
   r+   r   r   strboolr   r   r1   __classcell__r   r   r'   r   r   &   s2   
 
c                   @   s   e Zd ZdZdZdZdZeddddd	d
dede	ddf
ddZ
ded dd fddZded fddZd$dededd fddZd$dede	ded fddZdedee fddZdee fd d!Zdee fd"d#ZdS )%r   a  A Head is a named reference to a :class:`~git.objects.commit.Commit`. Every Head
    instance contains a name and a :class:`~git.objects.commit.Commit` object.

    Examples::

        >>> repo = Repo("/path/to/repo")
        >>> head = repo.heads[0]

        >>> head.name
        'master'

        >>> head.commit
        <git.Commit "1c09f116cbc2cb4100fb6935bb162daa4723f455">

        >>> head.commit.hexsha
        '1c09f116cbc2cb4100fb6935bb162daa4723f455'
    z
refs/headsremotemergeF)forcer    r   headszUnion[Head, str]r@   r/   r   Nc                O   s$   d}|rd}|j j|g|R   dS )zDelete the given heads.

        :param force:
            If ``True``, the heads will be deleted even if they are not yet merged into
            the main development stream. Default ``False``.
        z-dz-DN)r0   branch)clsr    r@   rA   r/   flagr   r   r   delete   s   zHead.deleteremote_reference)r   Nc                 C   s   ddl m} |durt||std| |  A}|du r7|| j || j t|	 dkr6|
  n|| j|j || jt|j W d   | S W d   | S 1 s]w   Y  | S )a  Configure this branch to track the given remote reference. This will
        alter this branch's configuration accordingly.

        :param remote_reference:
            The remote reference to track or None to untrack any references.

        :return:
            self
        r   r   NzIncorrect parameter type: %rr   )r>   r   
isinstancer#   config_writerremove_optionk_config_remotek_config_remote_reflenoptionsremove_section	set_valueremote_namer   to_full_pathremote_head)r&   rF   r   writerr   r   r   set_tracking_branch   s,   




zHead.set_tracking_branchc                 C   st   ddl m} |  }|| jr8|| jr8t| jtt	|
| j}|t|
| j|j}|| j|S dS )z
        :return:
            The remote reference we are tracking, or ``None`` if we are not a tracking
            branch.
        r   r   N)r>   r   config_reader
has_optionrJ   rK   r   r    rQ   r   	get_valuer   name)r&   r   readerrefremote_refpathr   r   r   tracking_branch   s   zHead.tracking_branchnew_pathc                 C   s2   d}|rd}| j j|| | d| j|f | _| S )a  Rename self to a new path.

        :param new_path:
            Either a simple name or a path, e.g. ``new_name`` or ``features/new_name``.
            The prefix ``refs/heads`` is implied.

        :param force:
            If ``True``, the rename will succeed even if a head with the target name
            already exists.

        :return:
            self

        :note:
            Respects the ref log, as git commands are used.
        z-mz-Mz%s/%s)r    r0   rB   _common_path_defaultr!   )r&   r]   r@   rD   r   r   r   rename   s   zHead.rename)r   r   c                 K   sN   ||d< |d du r| d | jjj| fi | | jjjr#| jjS | jjS )a  Check out this head by setting the HEAD to this reference, by updating the
        index to reflect the tree we point to and by updating the working tree to
        reflect the latest index.

        The command will fail if changed working tree files would be overwritten.

        :param force:
            If ``True``, changes to the index and the working tree will be discarded.
            If ``False``, :exc:`~git.exc.GitCommandError` will be raised in that
            situation.

        :param kwargs:
            Additional keyword arguments to be passed to git checkout, e.g.
            ``b="new_branch"`` to create a new branch at the given spot.

        :return:
            The active branch after the checkout operation, usually self unless a new
            branch has been created.
            If there is no active branch, as the HEAD is now detached, the HEAD
            reference will be returned instead.

        :note:
            By default it is only allowed to checkout heads - everything else will leave
            the HEAD detached which is allowed and possible, but remains a special state
            that some tools might not be able to handle.
        fF)popr    r0   checkoutheadis_detachedactive_branch)r&   r@   r/   r   r   r   rb      s   

zHead.checkout	read_onlyc                 C   s*   |r| j  }n| j  }t|d| j S )Nzbranch "%s")r    rU   rH   r   rX   )r&   rf   parserr   r   r   _config_parser  s   
zHead._config_parserc                 C      | j ddS )z
        :return:
            A configuration parser instance constrained to only read this instance's
            values.
        Trf   rh   r*   r   r   r   rU         zHead.config_readerc                 C   ri   )z
        :return:
            A configuration writer instance with read-and write access to options of
            this head.
        Frj   rk   r*   r   r   r   rH   (  rl   zHead.config_writer)F)r5   r6   r7   r8   r^   rJ   rK   classmethodr<   r   rE   r   rT   r\   r   r_   rb   r   r   rh   rU   rH   r   r   r   r   r      s    &&	N)r8   __all__
git.configr   r   git.excr   git.utilr   	referencer	   symbolicr
   typingr   r   r   r   	git.typesr   r   git.objectsr   git.refsr   git.repor   r;   r   r   r   r   r   r   r   <module>   s    Z