o
    ;in                     @   sz   d dl Z d dlmZ d dlmZ d dlmZ dee dee fddZ	d	ej
deeef fd
dZdeej
 fddZdS )    N)Optional)logger)api_pb2argsreturnc              
      s   z5t j| t jjt jjdI d H }| I d H \}}|jdkr/td|  d|j  W d S |d	 W S  t
yT } ztjd|  d|d W Y d }~d S d }~ww )N)stdoutstderrr   zCommand z exited with code zutf-8z failed)exc_info)asynciocreate_subprocess_exec
subprocessPIPEcommunicate
returncoder   debugdecodestrip	Exception)r   processstdout_bytes_e r   J/home/ubuntu/.local/lib/python3.10/site-packages/modal/_utils/git_utils.pyrun_command_fallible	   s   
r   commit_infoc                 C   sl   | j dkrdS t| jdkrdS t| jdkrdS t| jdkr"dS t| jdkr+d	S t| jdkr4d
S dS )Ngit)FzInvalid VCS(   )FzInvalid commit hash   )FzBranch name too long   )FzRepo URL too long)FzAuthor name too long)FzAuthor email too long)T )vcslencommit_hashbranchrepo_urlauthor_nameauthor_email)r   r   r   r   is_valid_commit_info   s   
r(   c            
   	      s,  t jdd} g dg dg dg dg}dd |D }tj| I d	H \}}}}|s,d	S || _|s3d	S |d
}t|dk rKtdt| d d	S z|d | _	t
|d | _|d | _|d | _W n ttfyw   td|  Y d	S w t|| _|r|| _t| \}}	|std|	  d	S | S )zDCollect git information about the current repository asynchronously.r   )r!   )r   logz-1z--format=%H%n%ct%n%an%n%aeHEAD)r   z	rev-parsez--abbrev-refr*   )r   statusz--porcelain)r   remotezget-urloriginc                 s   s    | ]}t |V  qd S )N)r   ).0cmdr   r   r   	<genexpr><   s    z&get_git_commit_info.<locals>.<genexpr>N
   zLog info returned only z linesr            zFailed to parse git log info: zInvalid commit info: )r   
CommitInfor
   gatherr$   splitr"   r   r   r#   intcommit_timestampr&   r'   
ValueError
IndexErrorbooldirtyr%   r(   warning)
git_infocommandstaskslog_infor$   r+   
origin_url
info_linesvaliderror_messager   r   r   get_git_commit_info.   sF   




rH   )r
   typingr   modal.configr   modal_protor   liststrr   r6   tupler=   r(   rH   r   r   r   r   <module>   s   