
    d;                         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     Q/home/feoh/.local/pipx/venvs/poetry/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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
    Nc                 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__5   s4    2 	 !2"4r   c                 @   t          |          | j        k    r-t          d| j        | j        t          |          |fz            | j        
 | j        | }	 t          j        t          j        	                    | j
        | j                  gt          |          z   | j                  }|dk    r.| j         | j        dg|R   t          d| j        |fz            | 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 argszeHook %s executed with wrong number of args.                             Expected %d. Saw %d. args: %sNr   r   z&Hook %s exited with non-zero status %dr   )lenr   r   r   r   
subprocesscallosr   relpathr   r   listr   OSError)r
   r   rets      r   r	   zShellHook.executeW   sy    t99%%;9dmSYY=>   !-)4)40D	2/99:T$ZZGH  C axx*6+D+A55555<	3?OO   &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C7 7DD)NNNr   r   r   r   r   r	   r   r   r   r   r   -   sM                 D2 2 2 2 2r   r   c                       e Zd ZdZd ZdS )PreCommitShellHookzpre-commit shell hookc                     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__x   s>    7<<
G\BB4xDDDDDr   Nr   r   r   r   r   r   r   r   r*   r*   u   s.        E E E E Er   r*   c                       e Zd ZdZd ZdS )PostCommitShellHookzpost-commit shell hookc                     t           j                            |dd          }t                              | d|d|           d S )Nr,   zpost-commitr   r   r-   r
   r/   r   s      r   r   zPostCommitShellHook.__init__   s>    7<<
G]CC4!LLLLLr   Nr0   r   r   r   r2   r2   ~   s.          M M M M Mr   r2   c                       e Zd ZdZd ZdS )CommitMsgShellHookzcommit-msg shell hook
    c           	          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   r?   new_msgs       r   	clean_msgz.CommitMsgShellHook.__init__.<locals>.clean_msg   s     $q'4(( 'AffhhG' ' ' ' ' ' ' ' ' ' ' ' ' ' '	$q'"""Id1gs   :>>r   r-   )r
   r/   r   r@   rH   s        r   r   zCommitMsgShellHook.__init__   sj    7<<
G\BB	 	 		 	 	 	,![)Z	
 	
 	
 	
 	
r   Nr0   r   r   r   r6   r6      s-         
 
 
 
 
r   r6   c                       e Zd ZdZd Zd ZdS )PostReceiveShellHookzpost-receive shell hookc                     || _         t          j                            |dd          }t                              | d|d           d S )Nr,   zpost-receiver   )r   r   )r/   r#   r   r.   r   r   r4   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 )    )r.   ).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copyr/   r!   PopenPIPEr.   communicate
returncoder   decoder&   repr)
r
   client_refsrQ   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Nr(   r   r   r   rJ   rJ      s;        !!L L L
0 0 0 0 0r   rJ   )r   r#   r!   errorsr   r   r   r*   r2   r6   rJ   r   r   r   <module>rk      sQ  *   				          0 0 0 0 0 0 0 0 E2 E2 E2 E2 E2 E2 E2 E2P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   