
    .Ph8                         d Z ddlZddlZddlmZ  G d d          Z G d de          Z G d	 d
e          Z G d de          Z G d de          Z	 G d de          Z
dS )zAccess to hooks.    N   )	HookErrorc                       e Zd ZdZd ZdS )HookzGeneric hook object.c                 *    t          | j                  )zExecute the hook with the given args.

        Args:
          args: argument list to hook
        Raises:
          HookError: hook execution failure
        Returns:
          a hook may return a useful value
        )NotImplementedErrorexecute)selfargss     M/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/dulwich/hooks.pyr	   zHook.execute!   s     "$,///    N)__name__
__module____qualname____doc__r	    r   r   r   r      s)        
0 
0 
0 
0 
0r   r   c                   *    e Zd ZdZ	 	 	 d	 ddZd ZdS )	ShellHookzHook by executable file.

    Implements standard githooks(5) [0]:

    [0] http://www.kernel.org/pub/software/scm/git/docs/githooks.html
    Nreturnc                 Z    || _         || _        || _        || _        || _        || _        dS )a  Setup shell hook definition.

        Args:
          name: name of hook for error messages
          path: absolute path to executable file
          numparam: number of requirements parameters
          pre_exec_callback: closure for setup before execution
            Defaults to None. Takes in the variable argument list from the
            execute functions and returns a modified argument list for the
            shell hook.
          post_exec_callback: closure for cleanup after execution
            Defaults to None. Takes in a boolean for hook success and the
            modified argument list and returns the final hook return value
            if applicable
          cwd: working directory to switch to when executing the hook
        N)namefilepathnumparampre_exec_callbackpost_exec_callbackcwd)r
   r   pathr   r   r   r   s          r   __init__zShellHook.__init__6   s4    2 	 !2"4r   c           
      J   t          |          | j        k    r2t          d| j         d| j         dt          |           d|           | j        
 | j        | }	 t          j        t          j        	                    | j
        | j                  gt          |          | j                  }|dk    r/| j         | j        dg|R   t          d| j         d|           | j         | j        d	g|R  S dS # t          $ r | j         | j        dg|R   Y dS Y dS w xY w)
z!Execute the hook with given args.zHook z. executed with wrong number of args. Expected z. Saw z. args: Nr   r   z exited with non-zero status r   )lenr   r   r   r   
subprocesscallosr   relpathr   r   listr   OSError)r
   r   rets      r   r	   zShellHook.executeX   s   t99%%	QUQ^fijnfofoy}   !-)4)40D	2/99GDJJGTX  C axx*6+D+A55555 U	 U UPS U UVVV&2.t.q848888 32 	2 	2 	2&2''1D1111111 322	2s   BC< <D"!D")NNNr   Nr   r   r   r   r   r	   r   r   r   r   r   .   sW            
       D2 2 2 2 2r   r   c                       e Zd ZdZddZdS )PreCommitShellHookzpre-commit shell hook.r   Nc                     t           j                            |dd          }t                              | d|d|           d S )Nhooksz
pre-commitr   r    r$   r   joinr   r   )r
   r   
controldirr   s       r   r   zPreCommitShellHook.__init__t   s>    7<<
G\BB4xDDDDDr   r)   r   r   r   r   r   r   r   r   r,   r,   q   s4          E E E E E Er   r,   c                       e Zd ZdZddZdS )PostCommitShellHookzpost-commit shell hook.r   Nc                     t           j                            |dd          }t                              | d|d|           d S )Nr.   zpost-commitr   r    r/   r
   r1   r   s      r   r   zPostCommitShellHook.__init__}   s>    7<<
G]CC4!LLLLLr   r)   r2   r   r   r   r4   r4   z   s4        !!M M M M M Mr   r4   c                       e Zd ZdZddZdS )CommitMsgShellHookzcommit-msg shell hook.r   Nc           	          t           j                            |dd          }d }d }t                              | d|d|||           d S )Nr.   z
commit-msgc                      dd l }|                                \  }}t          j        |d          5 }|                    | d                    d d d            n# 1 swxY w Y   |fS )Nr   wb)tempfilemkstempr$   fdopenwrite)r   r<   fdr   fs        r   prepare_msgz0CommitMsgShellHook.__init__.<locals>.prepare_msg   s    OOO!))++JR2t$$ !Q   ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! 7Ns   AA Ac                     | r^t          |d         d          5 }|                                }d d d            n# 1 swxY w Y   t          j        |d                    |S t          j        |d                    d S )Nr   rb)openreadr$   unlink)successr   rA   new_msgs       r   	clean_msgz.CommitMsgShellHook.__init__.<locals>.clean_msg   s     $q'4(( 'AffhhG' ' ' ' ' ' ' ' ' ' ' ' ' ' '	$q'"""Id1gs   :>>r   r/   )r
   r1   r   rB   rJ   s        r   r   zCommitMsgShellHook.__init__   sj    7<<
G\BB	 	 		 	 	 	,![)Z	
 	
 	
 	
 	
r   r)   r2   r   r   r   r8   r8      s.          
 
 
 
 
 
r   r8   c                        e Zd ZdZddZd ZdS )PostReceiveShellHookzpost-receive shell hook.r   Nc                     || _         t          j                            |dd          }t                              | d|d           d S )Nr.   zpost-receiver   )r   r   )r1   r$   r   r0   r   r   r6   s      r   r   zPostReceiveShellHook.__init__   sC    $7<<
G^DD4hKKKKKr   c                 f   t           j                            | j                  sd S 	 t           j                                        }| j        |d<   t          j        | j        t          j	        t          j	        t          j	        |          }d
                    d |D                       }|                    |          \  }}|j        dk    s|r2d}||j        ||fz  }t          |                    dd                    |S # t          $ r"}	t          t!          |	                    |	d }	~	ww xY w)	NGIT_DIR)stdinstdoutstderrenv   
c                 8    g | ]}d                      |          S )    )r0   ).0refs     r   
<listcomp>z0PostReceiveShellHook.execute.<locals>.<listcomp>   s"    !H!H!HS$))C..!H!H!Hr   r   s0   post-receive exit code: %d
stdout:
%s
stderr:
%szutf-8backslashreplace)r$   r   existsr   environcopyr1   r"   PopenPIPEr0   communicate
returncoder   decoder'   repr)
r
   client_refsrS   pin_dataout_dataerr_dataerr_fmterr_msgerrs
             r   r	   zPostReceiveShellHook.execute   s'   w~~dm,, 	4	0*//##C!_C	N  o!!  A jj!H!HK!H!H!HIIG!"w!7!7Hh!!h!W!Q\8X$FFw8J K KLLLO 	0 	0 	0DII&&C/	0s   CD 
D0D++D0r)   r*   r   r   r   rL   rL      sA        ""L L L L
0 0 0 0 0r   rL   )r   r$   r"   errorsr   r   r   r,   r4   r8   rL   r   r   r   <module>rm      sQ  ,   				          0 0 0 0 0 0 0 0 @2 @2 @2 @2 @2 @2 @2 @2FE E E E E E E EM M M M M) M M M
 
 
 
 
 
 
 
:$0 $0 $0 $0 $09 $0 $0 $0 $0 $0r   