
    U                         S r SSKrSSKrSSKJr   " S S\5      r " S S\5      r " S S	\5      r " S
 S\5      r	 " S S\5      r
 " S S\5      rg)zAccess to hooks.    N)	HookErrorc                       \ rS rSrSrS rSrg)Hook   zGeneric hook object.c                 ,    [        U R                  5      e)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      lib/third_party/dulwich/hooks.pyr	   Hook.execute"   s     "$,,//     N)__name__
__module____qualname____firstlineno____doc__r	   __static_attributes__r   r   r   r   r      s
    
0r   r   c                   .    \ rS rSrSr   SS jrS rSrg)	ShellHook/   zHook by executable file

Implements standard githooks(5) [0]:

[0] http://www.kernel.org/pub/software/scm/git/docs/githooks.html
Nc                 L    Xl         X l        X0l        X@l        XPl        X`l        g)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__ShellHook.__init__7   s$    2 	 !2"4r   c                 ^   [        U5      U R                  :w  a/  [        SU R                  U R                  [        U5      U4-  5      eU R                  b  U R                  " U6 n [
        R                  " U R                  /[        U5      -   U R                  S9nUS:w  a:  U R                  b  U R                  " S/UQ76   [        SU R                  U4-  5      eU R                  b  U R                  " S/UQ76 $ g! [         a%    U R                  b  U R                  " S/UQ76    g gf = f)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 %d   )lenr   r   r   r   
subprocesscallr   listr   r   OSError)r
   r   rets      r   r	   ShellHook.executeY   s)    t9%;99dmmSY=>  !!-))40D	2//4==/DJ">DHHMCax**6++A55<		3?OO  &&2..q8488 3 	2&&2''1D1 3	2s   &BC= =*D,+D,)r   r   r   r   r   r   )NNNr   r   r   r   r   r!   r	   r   r   r   r   r   r   /   s      D2r   r   c                       \ rS rSrSrS rSrg)PreCommitShellHooku   zpre-commit shell hookc                 t    [         R                  R                  USS5      n[        R	                  U SUSUS9  g )Nhooksz
pre-commitr   r$   osr    joinr   r!   r
   
controldirr   s      r   r!   PreCommitShellHook.__init__x   s1    77<<
G\B4x
Kr   r   Nr   r   r   r   r   r!   r   r   r   r   r/   r/   u   s    Lr   r/   c                       \ rS rSrSrS rSrg)PostCommitShellHook~   zpost-commit shell hookc                 t    [         R                  R                  USS5      n[        R	                  U SUSUS9  g )Nr2   zpost-commitr   r$   r3   r6   s      r   r!   PostCommitShellHook.__init__   s1    77<<
G]C4!Lr   r   Nr9   r   r   r   r;   r;   ~   s     Mr   r;   c                       \ rS rSrSrS rSrg)CommitMsgShellHook   z]commit-msg shell hook

Args:
  args[0]: commit message
Returns:
  new commit message or None
c           	          [         R                  R                  USS5      nS nS n[        R	                  U SUSX4U5        g )Nr2   z
commit-msgc                      SS K nUR                  5       u  p#[        R                  " US5       nUR	                  U S   5        S S S 5        U4$ ! , (       d  f       U4$ = f)Nr   wb)tempfilemkstempr4   fdopenwrite)r   rE   fdr    fs        r   prepare_msg0CommitMsgShellHook.__init__.<locals>.prepare_msg   sU    !))+JR2t$Q  % 7N %$ 7Ns   A
Ac                     U (       aC  [        US   S5       nUR                  5       nS S S 5        [        R                  " US   5        W$ [        R                  " US   5        g ! , (       d  f       NC= f)Nr   rb)openreadr4   unlink)successr   rJ   new_msgs       r   	clean_msg.CommitMsgShellHook.__init__.<locals>.clean_msg   sS    $q'4(AffhG )		$q'"IId1g	 )(s   A%%
A3r%   r3   )r
   r7   r   rK   rT   s        r   r!   CommitMsgShellHook.__init__   s?    77<<
G\B		 	,![Z	
r   r   Nr9   r   r   r   r@   r@      s    
r   r@   c                   $    \ rS rSrSrS rS rSrg)PostReceiveShellHook   zpost-receive shell hookc                     Xl         [        R                  R                  USS5      n[        R                  U SUS5        g )Nr2   zpost-receiver   )r7   r4   r    r5   r   r!   r6   s      r   r!   PostReceiveShellHook.__init__   s1    $77<<
G^D41=r   c                    [         R                  R                  U R                  5      (       d  g  [         R                  R                  5       nU R                  US'   [        R                  " U R                  [        R                  [        R                  [        R                  US9nSR                  U Vs/ s H  nSR                  U5      PM     sn5      nUR                  U5      u  pgUR                  S:w  d  U(       a-  SnXR                  Xg4-  n	[        U	R                  SS5      5      eU$ s  snf ! [         a  n
[        [!        U
5      5      eS n
A
ff = f)	NGIT_DIR)stdinstdoutstderrenv
 r   z0post-receive exit code: %d
stdout:
%s
stderr:
%szutf-8backslashreplace)r4   r    existsr   environcopyr7   r'   PopenPIPEr5   communicate
returncoder   decoder*   repr)r
   client_refsra   prefin_dataout_dataerr_dataerr_fmterr_msgerrs              r   r	   PostReceiveShellHook.execute   s   ww~~dmm,,	'**//#C!__C	N   oo!!A ii+ F+3#+ FGG!"w!7H!hU!\\8$FFw8J KLLO !G  	'DI&&	's+   BD9 9D4AD9 4D9 9
EEE)r7   Nr-   r   r   r   rX   rX      s    !>
'r   rX   )r   r4   r'   dulwich.errorsr   objectr   r   r/   r;   r@   rX   r   r   r   <module>rz      se   *  	 
06 0 C2 C2LL LM) M 
  
F$'9 $'r   