HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/states/__pycache__/hg.cpython-310.pyc
o

�N�g�@s�dZddlZddlZddlZddlZddlmZddlm	Z	m
Z
e�e�Z
ejj��r-dndZdd�Z											
ddd�Zd
d�Zdd�Zdd�ZdS)a�
Interaction with Mercurial repositories
=======================================

Before using hg over ssh, make sure the remote host fingerprint already exists
in ~/.ssh/known_hosts, and the remote host has this host's public key.

.. code-block:: yaml

    https://bitbucket.org/example_user/example_repo:
        hg.latest:
          - rev: tip
          - target: /tmp/example_repo
�N)�CommandExecutionError)�_fail�
_neutral_testzhg.exeZhgcCs tdt�rdSddt�d�fS)z&
    Only load if hg is available
    zcmd.has_execTFzCommand z
 not found)�__salt__�	HG_BINARY�rr�B/opt/saltstack/salt/lib/python3.10/site-packages/salt/states/hg.py�__virtual__sr	FTc	
Cs�|ddid�}	|st|	d�Stj�|�otj�|�d��}
|
r-t|	||||||||�	}	|	Stj�|�r@t|	||�}|dur?|Snt�d|�tdrUt	|	d	|�d
|���St
|	||||||�|	S)a�
    Make sure the repository is cloned to the given directory and is up to date

    name
        Address of the remote repository as passed to "hg clone"

    rev
        The remote branch, tag, or revision hash to clone/pull

    target
        Target destination directory path on minion to clone into

    clean
        Force a clean update with -C (Default: False)

    user
        Name of the user performing repository management operations

        .. versionadded:: 0.17.0

    identity
        Private SSH key on the minion server for authentication (ssh://)

        .. versionadded:: 2015.5.0

    force
        Force hg to clone into pre-existing directories (deletes contents)

    opts
        Include additional arguments and options to the hg command line

    update_head
        Should we update the head if new changes are found? Defaults to True

        .. versionadded:: 2017.7.0

    T�)�name�result�comment�changesz"target option is requiredz/.hgNz.target %s is not found, "hg clone" is required�test�Repository z is about to be cloned to )r�os�path�isdir�_update_repo�_handle_existing�log�debug�__opts__r�_clone_repo)r�rev�target�clean�user�identity�force�opts�update_head�retZ
is_repositoryZfailrrr�latest&s*0
����r#c	
Cs�t�d|�td||dd�}	|	st|d|�d��Stdr't|d�||	��Sz
td	|||||d
�}
WntyP}zd|d<||d
<|WYd}~Sd}~ww|durgd|
v}|rad|d
<|Sd|d
<|S|r�ztd||||d�WnEty�}zd|d<||d
<|WYd}~Sd}~wwztd|d||d�Wnty�}zd|d<||d
<|WYd}~Sd}~wwtd||dd�}
|	|
kr�|	�d|
��}t�d||�d|�d�|d
<||dd<|Sd|
vr�t|d|
���S|S)zQ
    Update the repo to a given revision. Using clean passes -C to the hg up
    z;target %s is found, "hg pull && hg up is probably required"�hg.revision�.)rrzSeems that z is not a valid hg reporzBRepository {} update is probably required (current revision is {})zhg.pull)rrr Z
repositoryFrr
Nzno changes foundzKUpdate is probably required but update_head=False so we will skip updating.z=No changes found and update_head=False so will skip updating.�	hg.update)rrZtip)�cwdrrz => zRepository %s updated: %srz	 updated.r�revisionzerror:zAn error was thrown by hg:
)	rrrrrr�formatr�info)r"rrrrrrr r!Zcurrent_revZpull_out�errr�new_revZ
revision_textrrrrpsr��

�����������rcCsPt�|�}|st�d|�t�|�dS|r#t�d|�t�|�dSt|d�S)Nz?target %s found, but directory is empty, automatically deletingzPtarget %s found and is not empty. Since force option is in use, deleting anyway.z"Directory exists, and is not empty)r�listdirrr�shutil�rmtreer)r"rr�	not_emptyrrrr�s
��
rc
Csz
td|||||d�}Wnty)}zd|d<||d<|WYd}~Sd}~wwtj�|�s5t||�S|r_ztd|||d�Wnty^}zd|d<||d<|WYd}~Sd}~wwtd||d	�}	d
|�d|��}
t�|
�|
|d<||dd
<|	|dd<|S)Nzhg.clone)rrr Frr
r&)rr$)r'rrz cloned to r�newr()rrrrrrrr*)r"rrrrrr rr+r,�messagerrrr�s8

���
��
r)NNFNNFFT)�__doc__�loggingrr.Zsalt.utils.platform�saltZsalt.exceptionsrZsalt.states.gitrr�	getLogger�__name__r�utils�platformZ
is_windowsrr	r#rrrrrrr�<module>s,

�JC