o
    ﯪg                     @   s  d dgZ ddlZddlmZ ddlZddlZddlmZ ddl	Z	ddl
Z
ddlZddlZddlmZ ddlmZ ddlmZmZmZ ddlmZmZmZmZ dd	lmZmZ dd
l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+ ddl,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5 e
j6dkrddl,m7Z7 nddl8m7Z7 ddl9m:Z:m;Z;m<Z< e3rddl=m>Z> ddl?m@Z@ ddlAmBZB ddlCmDZD eEeFZGG dd de!ZHeHjIZIeHjJZJeHjKZKeHjLZLeHjMZMG dd  d eeZNdS )	SubmoduleUpdateProgress    N)BytesIO)Git)defenc)GitConfigParserSectionConstraintcp)BadNameInvalidGitRepositoryErrorNoSuchPathErrorRepositoryDirtyError)IndexObjectObject)TraversableIterableObj)IterableListRemoteProgressjoin_path_nativermtreeto_native_path_linuxunbare_repo   )SubmoduleConfigParserfind_first_remote_branchmkheadsm_name
sm_section)	AnyCallableDictIteratorMappingSequenceTYPE_CHECKINGUnioncast)      )Literal)
Commit_ishPathLikeTBD)	IndexFile)Commit)Head)Repoc                   @   sJ   e Zd ZU dZdd eejejd D \ZZZ	ejd Ze
ed< dZdS )r   zClass providing detailed progress information to the caller who should
    derive from it and implement the
    :meth:`update(...) <git.util.RemoteProgress.update>` message.c                 C   s   g | ]}d |> qS )r    ).0xr0   r0   V/var/www/html/chatdoc2/venv/lib/python3.10/site-packages/git/objects/submodule/base.py
<listcomp>Q   s    zUpdateProgress.<listcomp>r&   _num_op_codesr0   N)__name__
__module____qualname____doc__ranger   r5   CLONEFETCH	UPDWKTREEint__annotations__	__slots__r0   r0   r0   r3   r   L   s
   
 "c                       s  e Zd ZU dZdZdZdZdZej	ej
B Z	 dZed ed< 	 dZd	Z	
	
	
	
	
	
ddddedeed
f deed
f deed
f ded deed
f deed
f dd
f fddZdedd
f fddZedd ded  fddZede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#defd)d*Z$eddded d+ede%fd,d-Z&dd.d/Z'edd0de(fd1d2Z)d+ede*fd3d4Z+ed5ddededefd6d7Z,e	8	8ddddededed9ed:ed;eddfd<d=Z-ed5ddedefd>d?Z.ed@edAedd
fdBdCZ/e	
	
	8	
	
	
	8	8ddddededeed
f deed
f dDedEeed
f dFee0eef d
f dGee1e2 d
f d9ed:edd fdHdIZ3	8	J	8	
	8	8	8	
	
	8	8ddKedLedMedNedO dPedQedRedFee0eef d
f dGee1e2 d
f d9ed:edd fdSdTZ4e5ddUedVedWedd fdXdYZ6e5	J	8	J	8ddWedQedVedPedd f
dZd[Z7dd\ee8ed
f d]edd fd^d_Z9e5	Jdd`eda dbede*dc fdddeZ:e5dfedd fdgdhZ;e5ddidjZ<defdkdlZ=defdmdnZ>e?ddpdqZ@e?defdrdsZAe?defdtduZBe?defdvdwZCe?ddxdyZDe?defdzd{ZEde*e% fd|d}ZFded  fd~dZGe	ddddee8ef ded;edeHd  f
ddZI  ZJS )r   a|  Implements access to a git submodule. They are special in that their sha
    represents a commit in the submodule's repository which is to be checked out
    at the path of this instance.

    The submodule type does not have a string type associated with it, as it exists
    solely as a marker in the tree and index.

    All methods work in bare and non-bare repositories.
    name.gitmodulesbranchmaster	submoduletype)_parent_commit_url_branch_path_name__weakref__pathrH   rI   Nrepor/   binshamoderM   parent_commit)r-   Nurlbranch_pathreturnc	           	         sP   t  |||| d| _|| _|dur|| _|dur|| _|dur&|| _dS dS )aJ  Initialize this instance with its attributes.

        We only document the parameters that differ from
        :class:`~git.objects.base.IndexObject`.

        :param repo:
            Our parent repository.

        :param binsha:
            Binary sha referring to a commit in the remote repository.
            See the `url` parameter.

        :param parent_commit:
            The :class:`~git.objects.commit.Commit` whose tree is supposed to contain
            the ``.gitmodules`` blob, or ``None`` to always point to the most recent
            commit. See :meth:`set_parent_commit` for details.

        :param url:
            The URL to the remote repository which is the submodule.

        :param branch_path:
            Full repository-relative path to ref to checkout when cloning the remote
            repository.
        r   N)super__init__sizerG   rH   rI   rJ   )	selfrN   rO   rP   rM   rA   rQ   rR   rS   	__class__r0   r3   rV   z   s   #
zSubmodule.__init__attrc              
      s   |dv rL|   }z|d| _W n& tjy6 } z| jjd ur,tdt	| jjd |W Y d }~nd }~ww |d| _
|| jtj| j| _d S |dkrTtdt | d S )NrL   rM   z;This submodule instance does not exist anymore in '%s' filerB   rR   rJ   zCCannot retrieve the name of a submodule if it was not set initially)config_readergetrM   r	   NoSectionErrorrN   working_tree_dir
ValueErrorospjoinrH   	get_valuek_head_optiongitr.   to_full_pathk_head_defaultrI   AttributeErrorrU   _set_cache_)rX   r[   readererY   r0   r3   ri      s*   zSubmodule._set_cache_itemc                 C   s,   z|  | W S  ty   td Y S w )z4:return: All the submodules of our module repository )
list_itemsmoduler   r   )clsrl   r0   r0   r3   _get_intermediate_items   s
   z!Submodule._get_intermediate_itemsre   c                 C   s   |j d d dkS )Nr&   )r         )version_info)rp   re   r0   r0   r3   _need_gitfile_submodules   s   z"Submodule._need_gitfile_submodulesotherc                 C   s   | j |j kS )zCompare with another submodule.rJ   rX   rv   r0   r0   r3   __eq__   s   zSubmodule.__eq__c                 C   s
   | |k S )z.Compare with another submodule for inequality.r0   rx   r0   r0   r3   __ne__      
zSubmodule.__ne__c                 C   s
   t | jS )z5Hash this instance using its logical id, not the sha.)hashrJ   rX   r0   r0   r3   __hash__   r{   zSubmodule.__hash__c                 C      | j S )Nrw   r}   r0   r0   r3   __str__   s   zSubmodule.__str__c                 C   s    dt | j| j| j| j| jf S )Nz0git.%s(name=%s, path=%s, url=%s, branch_path=%s))rF   r6   rJ   rM   rR   rS   r}   r0   r0   r3   __repr__   s   zSubmodule.__repr__	read_onlyc              
   C   s   d}|durz|j j|k}W n	 ty   Y nw |js)|r)|jr)t|j| j}n&|dus1J dz| |}W n t	yN } z
t
d| j|f |d}~ww |sZ|jsV|sZtdt||dS )ag  
        :return:
            Config parser constrained to our submodule in read or write mode

        :raise IOError:
            If the ``.gitmodules`` file cannot be found, either locally or in the
            repository at the given parent commit. Otherwise the exception would be
            delayed until the first access of the config parser.
        TNz-need valid parent_commit in bare repositoriesz6Could not find %s file in the tree of parent commit %sz;Cannot write blobs of 'historical' submodule configurationsr   )headcommitr`   barer_   ra   rb   k_modules_file_sio_modulesKeyErrorIOErrorr   )rp   rN   rQ   r   parent_matches_head	fp_modulerk   r0   r0   r3   _config_parser   s.   zSubmodule._config_parserc              	   C   s0   | j D ]}zt| | W q ty   Y qw dS )z"Clear the possibly changed values.N)_cache_attrsdelattrrh   )rX   rA   r0   r0   r3   _clear_cache  s   
zSubmodule._clear_cacher-   c                 C   s"   t |j| j j }| j|_|S )z
        :return:
            Configuration file as :class:`~io.BytesIO` - we only access it through the
            respective blob's data
        )r   treer   data_streamreadrA   )rp   rQ   sior0   r0   r3   r     s   zSubmodule._sio_modulesc                 C   sL   z| j }W n ty   d}Y nw | | j||}||  t|t| jS )zI:return: Config parser constrained to our submodule in read or write modeN)rQ   r`   r   rN   set_submoduler   r   rA   )rX   r   pcparserr0   r0   r3   _config_parser_constrained$  s   

z$Submodule._config_parser_constrainedparent_repoc                 C   s6   |  |jrt|jd|S |jrt|j|S t )Nmodules)ru   re   ra   rb   git_dirr_   NotADirectoryError)rp   r   rM   rA   r0   r0   r3   _module_abspath/  s
   zSubmodule._module_abspathFallow_unsafe_optionsallow_unsafe_protocolskwargsc                 K   s   |  |||}|}	| |jr+||d< t|}
t|
s"t|
 tt	|j
|}	tjj||	f||d|}| |jrE| |	| |S )a  
        :return:
            :class:`~git.repo.base.Repo` instance of newly cloned repository.

        :param repo:
            Our parent repository.

        :param url:
            URL to clone from.

        :param path:
            Repository-relative path to the submodule checkout location.

        :param name:
            Canonical name of the submodule.

        :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 given to :manpage:`git-clone(1)`.
        separate_git_dir)r   r   )r   ru   re   ra   dirnameisdirosmakedirsrb   strr_   r/   
clone_from!_write_git_file_and_module_config)rp   rN   rR   rM   rA   r   r   r   module_abspathmodule_checkout_pathmodule_abspath_dircloner0   r0   r3   _clone_repo7  s(   $


zSubmodule._clone_repoc                 C   s   t |}|dr|dd }t|r>|jr>t |j}||s)td||f |t|dd d }|s>td| |S )z:return: A path guaranteed to be relative to the given parent repository

        :raise ValueError:
            If path is not contained in the parent repository's working tree.
        /NzNSubmodule checkout path '%s' needs to be within the parents repository at '%s'r   z?Absolute submodule path '%s' didn't yield a valid relative path)	r   endswithra   isabsr_   
startswithr`   lenrstrip)rp   r   rM   working_tree_linuxr0   r0   r3   _to_relative_pathp  s   


zSubmodule._to_relative_pathr_   r   c              
   C   s   t |d}t j||d}tjdkrt |rt| t|d}|	d| 
t W d   n1 s6w   Y  tt |dddd	}|d
dtt j||d W d   dS 1 s`w   Y  dS )a  Write a ``.git`` file containing a (preferably) relative path to the actual
        git module repository.

        It is an error if the `module_abspath` cannot be made into a relative path,
        relative to the `working_tree_dir`.

        :note:
            This will overwrite existing files!

        :note:
            As we rewrite both the git file as well as the module configuration, we
            might fail on the configuration and will not roll back changes done to the
            git file. This should be a non-issue, but may easily be fixed if it becomes
            one.

        :param working_tree_dir:
            Directory to write the ``.git`` file into.

        :param module_abspath:
            Absolute path to the bare repository.
        .git)startwin32wbz
gitdir: %sNconfigF)r   merge_includescoreworktree)ra   rb   relpathsysplatformisfiler   removeopenwriteencoder   r   	set_valuer   )rp   r_   r   git_file	rela_pathfpwriterr0   r0   r3   r     s   
"z+Submodule._write_git_file_and_module_configno_checkoutdepthenvclone_multi_optionsc                 C   s  |j rtd| ||}|durt|}| || j| j||dd}| rPz|jjj	t
| }||_|W S  tyO   |j}|j||d }|j|_| Y S w t|tjt
|p\| j}| }|du }|r|dur|dd | jD vrtd||jf d}|du r|std	| | }d
d |jD }|std|j |d }n1d|i}|s|j|d< |rt|tr||d< ntd|	r|	|d< | j||||f||
|d|}t|}|j ! }|"t#|d| W d   n1 sw   Y  |j j}|j!|dd&}|"d| |"d| ||_$|s(|"| j%|j& |j&|_'W d   n	1 s3w   Y  |rA|jjj|_|j(|gdd |S )ax  Add a new submodule to the given repository. This will alter the index as
        well as the ``.gitmodules`` file, but will not create a new commit. If the
        submodule already exists, no matter if the configuration differs from the one
        provided, the existing submodule will be returned.

        :param repo:
            Repository instance which should receive the submodule.

        :param name:
            The name/identifier for the submodule.

        :param path:
            Repository-relative or absolute path at which the submodule should be
            located.
            It will be created as required during the repository initialization.

        :param url:
            ``git clone ...``-compatible URL. See :manpage:`git-clone(1)` for more
            information. If ``None``, the repository is assumed to exist, and the URL of
            the first remote is taken instead. This is useful if you want to make an
            existing repository a submodule of another one.

        :param branch:
            Name of branch at which the submodule should (later) be checked out. The
            given branch must exist in the remote repository, and will be checked out
            locally as a tracking branch.
            It will only be written into the configuration if it not ``None``, which is
            when the checked out branch will be the one the remote HEAD pointed to.
            The result you get in these situation is somewhat fuzzy, and it is
            recommended to specify at least ``master`` here.
            Examples are ``master`` or ``feature/new``.

        :param no_checkout:
            If ``True``, and if the repository has to be cloned manually, no checkout
            will be performed.

        :param depth:
            Create a shallow clone with a history truncated to the specified number of
            commits.

        :param env:
            Optional dictionary containing the desired environment variables.

            Note: Provided variables will be used to update the execution environment
            for ``git``. If some variable is not specified in `env` and is defined in
            attr:`os.environ`, the value from attr:`os.environ` will be used. If you
            want to unset some variable, consider providing an empty string as its
            value.

        :param clone_multi_options:
            A list of clone options. Please see
            :meth:`Repo.clone <git.repo.base.Repo.clone>` for details.

        :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``.

        :return:
            The newly created :class:`Submodule` instance.

        :note:
            Works atomically, such that no change will be done if, for example, the
            repository update fails.
        z*Cannot add submodules to bare repositoriesNzinvalid-temporaryrR   r   c                 S      g | ]}|j qS r0   r   r1   rr0   r0   r3   r4   +      z!Submodule.add.<locals>.<listcomp>zJSpecified URL '%s' does not match any remote url of the repository at '%s'z8A URL was not given and a repository did not exist at %sc                 S   r   r0   r   r   r0   r0   r3   r4   :  r   z.Didn't find any remote url in repository at %snbr   zdepth should be an integermulti_options)r   r   r   rR   F)indexr   rM   Tr   ))r   r   r   r   NULL_BIN_SHAk_default_modeexistsr   r   r   r   rJ   r   r   entries	entry_keyrO   re   r.   rf   rg   module_existsro   remotesr`   abspathrA   
isinstancer>   r   r   
polish_urlrN   config_writerr   r   rH   rd   rM   rI   add)rp   rN   rA   rM   rR   rC   r   r   r   r   r   r   smr   entrybr
has_modulebranch_is_defaultmrepourlsr   r   r0   r0   r3   r     s   Q





zSubmodule.addT	recursiveinitto_latest_revisionprogress)r   Ndry_runforce
keep_goingc           #      C   s  | j jr| S |du rt }d}|rd}|rd}zzN|  }|j}t|}t|D ]<\}}t}|dkr7|tO }|	||||d|| j
f   |sN|j|d ||d krX|tO }|	||||d| j
   q)W n ty:   d}|sx|  Y W S | j}|st|rzt| W n ty } ztd	| |d}~ww |	ttB dd|d
| j|| j
f   |s| j| j | j| j| j
d||	|
|d	}|	ttB dd|d|   |s8z.td|}t|j| j}t|| j}|t|| j |j j!|d| d |j j"#| W n t$tfy   t%&d| j Y nw | j ' }|(t)| j
d| j W d   n	1 s3w   Y  Y nw | j*}| j+}|durJ|j j,}|dur|rd|j- }|sy|j j". }|duro|j/}|j*}|j+}nt%0d||j j" nt%0d| |dur,|j j/j*|kr,d}|j j/j*| jkr|1|j j/|}t|dks|d dur|d j+|kr|rd} | d7 } t%2|  nd} | |rdpd|j |f; } t%3|  d}|r|s|j4ddddrt5|d|	tt6B dd|d| j| j
|f   |s|r|r|j7j8||d n	|j j9|ddd  |	tt6B dd|d!| j
   W n t:yK }! z|s: t%0t;|! W Y d}!~!nd}!~!ww |rk|durk| <|  D ]}"|"j	|||||||d" q[| S )#a  Update the repository of this submodule to point to the checkout we point at
        with the binsha of this instance.

        :param recursive:
            If ``True``, we will operate recursively and update child modules as well.

        :param init:
            If ``True``, the module repository will be cloned into place if necessary.

        :param to_latest_revision:
            If ``True``, the submodule's sha will be ignored during checkout. Instead,
            the remote will be fetched, and the local tracking branch updated. This only
            works if we have a local tracking branch, which is the case if the remote
            repository had a master branch, or if the ``branch`` option was specified
            for this submodule and the branch existed remotely.

        :param progress:
            :class:`UpdateProgress` instance, or ``None`` if no progress should be
            shown.

        :param dry_run:
            If ``True``, the operation will only be simulated, but not performed.
            All performed operations are read-only.

        :param force:
            If ``True``, we may reset heads even if the repository in question is dirty.
            Additionally we will be allowed to set a tracking branch which is ahead of
            its remote branch back into the past or the location of the remote branch.
            This will essentially 'forget' commits.

            If ``False``, local tracking branches that are in the future of their
            respective remote branches will simply not be moved.

        :param keep_going:
            If ``True``, we will ignore but log all errors, and keep going recursively.
            Unless `dry_run` is set as well, `keep_going` could cause
            subsequent/inherited errors you wouldn't see otherwise.
            In conjunction with `dry_run`, it can be useful to anticipate all errors
            when updating submodules.

        :param env:
            Optional dictionary containing the desired environment variables.

            Note: Provided variables will be used to update the execution environment
            for ``git``. If some variable is not specified in `env` and is defined in
            attr:`os.environ`, value from attr:`os.environ` will be used.

            If you want to unset some variable, consider providing the empty string as
            its value.

        :param clone_multi_options:
            List of :manpage:`git-clone(1)` options.
            Please see :meth:`Repo.clone <git.repo.base.Repo.clone>` for details.
            They only take effect with the `init` option.

        :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``.

        :note:
            Does nothing in bare repositories.

        :note:
            This method is definitely not atomic if `recursive` is ``True``.

        :return:
            self
        Nrm   z	DRY-RUN: r   z"Fetching remote %s of submodule %r)r   r   z$Done fetching remote of submodule %rz:Module directory at %r does already exist and is non-emptyz(Cloning url '%s' to '%s' in submodule %rT)r   r   r   r   r   zDone cloning to %sr/   zsubmodule: attaching head to %s)logmsgz%Failed to checkout tracking branch %srR   z8Cannot update to latest revision in repository at %r as z6%s a tracking branch was not set for local branch '%s'z%%s there was no local tracking branchzNWill force checkout or reset on local branch that is possibly in the future ofzK the commit it will be checked out to, effectively 'forgetting' new commitszRSkipping %s on branch '%s' of submodule repo '%s' as it contains un-pushed commitscheckoutresetFr   working_treeuntracked_fileszCannot reset a dirty repositoryz;Updating working tree at %s for submodule %r to revision %s)r   )r   r   z+Done updating working tree for submodule %r)r   r   r   r   )=rN   r   r   ro   r   r   	enumerater<   BEGINupdaterA   fetchENDr   r   ra   r   r   rmdirOSErrorr;   rR   r   rM   r%   r   branch_namer   rS   
set_objectr   r   r   set_reference	referenceset_tracking_branch
IndexError_loggerwarningr   r   r   rO   hexshais_detachedworking_dirtracking_branchr   error
merge_basedebuginfois_dirtyr   r=   re   r   r   	Exceptionr   
iter_items)#rX   r   r   r   r   r   r   r   r   r   r   r   prefixr   rmtslen_rmtsiremoteopcheckout_module_abspathrk   remote_branchlocal_branchr   rO   r	  r
  msg_baserrefrcommit	may_resetbase_commitmsgerrrE   r0   r0   r3   r   z  sV  T
	

	R


,



zSubmodule.updatemodule_pathconfigurationro   c              
   C   s,  || dk r
t d| | j|}|| jkr| S tt| jj|}t|r,t d| | jj	}|
|d}|rA||jv rAt d|ret|rdtt|rSt dt|r^t| nt| n	 | j}d}	|rt|rt|| d}	tt|d	r| | j| j| j}
| ||
 | j}za|rz)|
| jd}|j| }|j|= t|d
d |f |dd
  }||j|< W n ty } ztd| j |d
}~ww | j|d}|d| || _W d
   n1 sw   Y  W n ty   |	rt||  w || jkr|  | | S )a  Move the submodule to a another module path. This involves physically moving
        the repository at our current path, changing the configuration, as well as
        adjusting our index entry accordingly.

        :param module_path:
            The path to which to move our module in the parent repository's working
            tree, given as repository-relative or absolute path. Intermediate
            directories will be created accordingly. If the path already exists, it must
            be empty. Trailing (back)slashes are removed automatically.

        :param configuration:
            If ``True``, the configuration will be adjusted to let the submodule point
            to the given path.

        :param module:
            If ``True``, the repository managed by this submodule will be moved as well.
            If ``False``, we don't move the submodule's checkout, which may leave the
            parent repository in an inconsistent state.

        :return:
            self

        :raise ValueError:
            If the module path existed and was not empty, or was a file.

        :note:
            Currently the method is not atomic, and it could leave the repository in an
            inconsistent state if a sub-step fails for some reason.
        r   zRYou must specify to move at least the module or the configuration of the submodulez&Cannot move repository onto a file: %sr   z-Index entry for target path did already existz*Destination module directory was not emptyFTr   Nr&      z%Submodule's entry at %r did not exist)r   rM   )!r`   r   rN   rM   r   r   r_   ra   r   r   r   r   r   r   r   listdirislinkr   r   r   renamesrb   r   rA   r   re   
IndexEntryr   r   r   r   r  rename)rX   r$  r%  ro   r   module_checkout_abspathr   tekeycur_pathrenamed_moduler   previous_sm_pathekeyr   nentryrk   r   r0   r0   r3   move  sl   




$	
zSubmodule.movec                 C   sf  |s|st dd}|  D ]}|d7 }||||| ~q|r1|s1|dkr1|  jd| j  |r|  r|  }|j}|rj| j	}	d}
t
|	rNtj}
nt
|	rVt}
n	t
|	r_td|si|
seJ |
|	 nW|jddddrytd	|j |jD ]0}d}|j}|D ]}|t|j|dk7 }qt|r|t|krtd
|j t|r~~~q||s|   |j}~t  tt| |st
|r|   t| |s|   |r1|s1| jj}z|j|| j d= W n	 t!y   Y nw |"  | j# }|$t%| j W d   n	1 sw   Y  | # }|$  W d   | S 1 s,w   Y  | S )a  Remove this submodule from the repository. This will remove our entry
        from the ``.gitmodules`` file and the entry in the ``.git/config`` file.

        :param module:
            If ``True``, the checked out module we point to will be deleted as well. If
            that module is currently on a commit outside any branch in the remote, or if
            it is ahead of its tracking branch, or if there are modified or untracked
            files in its working tree, then the removal will fail. In case the removal
            of the repository fails for these reasons, the submodule status will not
            have been altered.

            If this submodule has child modules of its own, these will be deleted prior
            to touching the direct submodule.

        :param force:
            Enforces the deletion of the module even though it contains modifications.
            This basically enforces a brute-force file system based deletion.

        :param configuration:
            If ``True``, the submodule is deleted from the configuration, otherwise it
            isn't. Although this should be enabled most of the time, this flag enables
            you to safely delete the repository of your submodule.

        :param dry_run:
            If ``True``, we will not actually do anything, but throw the errors we would
            usually throw.

        :return:
            self

        :note:
            Doesn't work in bare repositories.

        :note:
            Doesn't work atomically, as failure to remove any part of the submodule will
            leave an inconsistent state.

        :raise git.exc.InvalidGitRepositoryError:
            Thrown if the repository cannot be deleted.

        :raise OSError:
            If directories or files could not be removed.
        zCNeed to specify to delete at least the module, or the configurationr   r   z-Removed at least one of child-modules of '%s'NzKCannot forcibly delete repository as it was neither a link, nor a directoryTr   zLCannot delete module at %s with any modifications, unless force is specifiedz3Cannot delete module at %s as there are new commits)&r`   childrenr   ro   r   r   rA   r   r   r   ra   r(  r   r   r   r   AssertionErrorr  r   r_   r   refsr   re   cherryr   gccollectr   rN   r   r   rM   r   r   r   remove_sectionr   )rX   ro   r   r%  r   nccsmmodr   mpmethodr  num_branches_with_new_commitsrrefsr  wtdparent_index
gcp_writer	sc_writerr0   r0   r3   r   ?  s   3




	


zSubmodule.remover   checkc                 C   s   |du r	d| _ | S | j|}|j}| j|vr td|| jf | j }|| _ |rF| j| j| j dd}|t| j	sF|| _ td| j
|f z|t| j
 j| _W n ty^   | j| _Y nw |   | S )a  Set this instance to use the given commit whose tree is supposed to
        contain the ``.gitmodules`` blob.

        :param commit:
            Commit-ish reference pointing at the root tree, or ``None`` to always point
            to the most recent commit.

        :param check:
            If ``True``, relatively expensive checks will be performed to verify
            validity of the submodule.

        :raise ValueError:
            If the commit's tree didn't contain the ``.gitmodules`` blob.

        :raise ValueError:
            If the parent commit didn't store this submodule under the current path.

        :return:
            self
        Nz-Tree of commit %s did not contain the %s fileTr   z6Submodule at path %r did not exist in parent commit %s)rG   rN   r   r   r   r`   r   has_sectionr   rA   rM   r   rO   r   r   r   )rX   r   rF  pcommitpctreeprev_pcr   r0   r0   r3   set_parent_commit  s*   
zSubmodule.set_parent_commitr   )r,   Nr   r   c                 C   s(   | j dd}|dur||j_||j_|S )a  
        :return:
            A config writer instance allowing you to read and write the data belonging
            to this submodule into the ``.gitmodules`` file.

        :param index:
            If not ``None``, an :class:`~git.index.base.IndexFile` instance which should
            be written. Defaults to the index of the :class:`Submodule`'s parent
            repository.

        :param write:
            If ``True``, the index will be written each time a configuration value changes.

        :note:
            The parameters allow for a more efficient writing of the index, as you can
            pass in a modified index on your own, prevent automatic writing, and write
            yourself once the whole operation is complete.

        :raise ValueError:
            If trying to get a writer on a parent_commit which does not match the
            current head commit.

        :raise IOError:
            If the ``.gitmodules`` file/blob could not be read.
        Fr   N)r   r   _index_auto_write)rX   r   r   r   r0   r0   r3   r   !  s
   zSubmodule.config_writernew_namec                 C   s2  | j |kr| S | j }|t| j r |t| j t| W d   n1 s*w   Y  | jddj}|t| j t| W d   n1 sLw   Y  || _|  }|	 r| 
| j| j|}|j}t|t|jr| 
| j| jtt }t|| |}t|| |jr| |j| | S )a  Rename this submodule.

        :note:
            This method takes care of renaming the submodule in various places, such as:

            * ``$parent_git_dir / config``
            * ``$working_tree_dir / .gitmodules``
            * (git >= v1.8.0: move submodule repository to new name)

        As ``.gitmodules`` will be changed, you would need to make a commit afterwards.
        The changed ``.gitmodules`` file will already be added to the index.

        :return:
            This :class:`Submodule` instance
        NTr   )rA   rN   r   rG  r   rename_sectionr   rJ   ro   has_separate_working_treer   rM   r   r   r   uuiduuid4r   r)  r_   r   )rX   rN  pwcwr=  destination_module_abspath
source_dirtmp_dirr0   r0   r3   r+  D  s.   
zSubmodule.renamec              
   C   s\   | j }zt|}|| jkr|W S W n ttfy' } ztd| |d}~ww td| )a2  
        :return:
            :class:`~git.repo.base.Repo` instance initialized from the repository at our
            submodule path

        :raise git.exc.InvalidGitRepositoryError:
            If a repository was not available.
            This could also mean that it was not yet initialized.
        zNo valid repository at %sNz(Repository at %r was not yet checked out)r   re   r/   rN   r   r   )rX   r,  rN   rk   r0   r0   r3   ro   |  s   

zSubmodule.modulec                 C   s$   z|    W dS  ty   Y dS w )z
        :return:
            ``True`` if our module exists and is a valid git repository.
            See the :meth:`module` method.
        TF)ro   r  r}   r0   r0   r3   r     s   zSubmodule.module_existsc                 C   s   t  }| jD ]}zt| |rt| |||< W q tjtfy"   Y qw |   z7z| j W W | jD ]}||v r?t	| |||  q1dS  t
y^   Y W | jD ]}||v r[t	| |||  qMdS w | jD ]}||v rpt	| |||  qbw )z
        :return:
            ``True`` if the submodule exists, ``False`` otherwise.
            Please note that a submodule may exist (in the ``.gitmodules`` file) even
            though its module doesn't exist on disk.
        TF)localsr   hasattrgetattrr	   r^   r`   r   rM   setattrr  )rX   locr[   r0   r0   r3   r     s@   	




zSubmodule.existsr.   c                 C   s   t |  | jS )z
        :return:
            The branch instance that we are to checkout

        :raise git.exc.InvalidGitRepositoryError:
            If our module is not yet checked out.
        )r   ro   rI   r}   r0   r0   r3   rC     s   	zSubmodule.branchc                 C   r   )z
        :return:
            Full repository-relative path as string to the branch we would checkout from
            the remote and track
        )rI   r}   r0   r0   r3   rS     s   zSubmodule.branch_pathc                 C   s   t | j| jjS )zi
        :return:
            The name of the branch, which is the shortest possible branch name
        )re   r.   rN   rI   rA   r}   r0   r0   r3   r    s   zSubmodule.branch_namec                 C   r   )zG:return: The url to the repository our submodule's repository refers to)rH   r}   r0   r0   r3   rR     s   zSubmodule.urlc                 C   s   | j du r
| j S | j S )z
        :return:
            :class:`~git.objects.commit.Commit` instance with the tree containing the
            ``.gitmodules`` file

        :note:
            Will always point to the current head's commit if it was not set explicitly.
        N)rG   rN   r   r}   r0   r0   r3   rQ     s   


zSubmodule.parent_commitc                 C   r   )a  
        :return:
            The name of this submodule. It is used to identify it within the
            ``.gitmodules`` file.

        :note:
            By default, this is the name is the path at which to find the submodule, but
            in GitPython it should be a unique identifier similar to the identifiers
            used for remotes, which allows to change the path of the submodule easily.
        rw   r}   r0   r0   r3   rA     s   zSubmodule.namec                 C   s   | j ddS )a  
        :return:
            ConfigReader instance which allows you to query the configuration values of
            this submodule, as provided by the ``.gitmodules`` file.

        :note:
            The config reader will actually read the data directly from the repository
            and thus does not need nor care about your working tree.

        :note:
            Should be cached by the caller and only kept as long as needed.

        :raise IOError:
            If the ``.gitmodules`` file/blob could not be read.
        Tr   )r   r}   r0   r0   r3   r\     s   zSubmodule.config_readerc                 C   s
   |  | S )z
        :return:
            IterableList(Submodule, ...) An iterable list of :class:`Submodule`
            instances which are children of this submodule or 0 if the submodule is not
            checked out.
        )rq   r}   r0   r0   r3   r4    s   
zSubmodule.childrenHEADargsc                 o   sF   z| |}| j||dd}W n ttfy   Y dS w | D ]}t|}||d}	||d}
| j}||| j	rFt
||| j	}|j}z	|j}||	 }W n) ty{   z|j||	d }t||j|j|j}W n
 tyx   Y Y q!w Y nw t|tjjjjurq!||_||  kr||_tj||_|
|_|V  q!dS )z
        :return:
            Iterator yielding :class:`Submodule` instances available in the given
            repository
        Tr   NrM   rR   r   )r   r   r   r
   sectionsr   r]   rg   
has_optionrd   r   r   r   r   r   r   r   rO   rP   rM   rF   re   objectsrE   baserJ   rG   r.   rf   rI   rH   )rp   rN   rQ   r^  r   r   r   smsr   pur   r   rtr   r   r0   r0   r3   r  #  sH   
zSubmodule.iter_items)NNNNNN)rT   N)FF)NNFNNNFF)FTFNFFFNNFF)TT)TFTF)T)NT)rT   r/   )rT   r.   )rT   r-   )r]  )Kr6   r7   r8   r9   _id_attribute_r   rd   rg   statS_IFDIRS_IFLNKr   rF   r(   r?   r@   r   bytesr$   r>   r*   r   rV   ri   classmethodr   rq   r   boolru   r   ry   objectrz   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r!   r"   r+   r   r   r   r3  r   r)   rK  r   r+  ro   r   r   propertyrC   rS   r  rR   rQ   rA   r\   r4  r    r  __classcell__r0   r0   rY   r3   r   a   s  
 





	
-	
)

	8&


	
 J	

  Ow "-5"7%
	
)O__all__r8  ior   loggingr   os.pathrM   ra   rh  r   rQ  re   git.cmdr   
git.compatr   
git.configr   r   r	   git.excr
   r   r   r   git.objects.baser   r   git.objects.utilr   git.utilr   r   r   r   r   r   utilr   r   r   r   r   typingr   r   r   r    r!   r"   r#   r$   r%   rt   r(   typing_extensions	git.typesr)   r*   r+   	git.indexr,   git.objects.commitr-   git.refsr.   git.repor/   	getLoggerr6   r  r   r   r   r;   r<   r=   r   r0   r0   r0   r3   <module>   sH    	,


