
    d1                     z    d Z ddlZddlZddlZddlZddlZddlmZ ddlm	Z	 ddl
mZmZmZ  G d de	          ZdS )	zTests for executing hooks.    N)errors)TestCase   )CommitMsgShellHookPostCommitShellHookPreCommitShellHookc                   0     e Zd Z fdZd Zd Zd Z xZS )ShellHookTestsc                     t                                                       t          j        dk    r|                     d           |                     t          j                            d                     d S )Nposixz%shell hook tests requires POSIX shellz/bin/sh)supersetUposnameskipTest
assertTruepathexists)self	__class__s    \/home/feoh/.local/pipx/venvs/poetry/lib/python3.11/site-packages/dulwich/tests/test_hooks.pyr   zShellHookTests.setUp#   sZ    7gMMABBBy1122222    c                    t           j                            t          j                              }t          j        t           j                            |d                     |                     t          j        |           d}d}d|z   dz   |z   dz   }t           j                            |dd          }t          ||          }t          |d          5 }|                    |           d d d            n# 1 swxY w Y   t          j        |t          j        t          j        z  t          j        z             |                     t$          j        |j                   t*          j        d	k    rt          |d          5 }|                    |           d d d            n# 1 swxY w Y   t          j        |t          j        t          j        z  t          j        z             |                                 t          |d          5 }|                    |           d d d            n# 1 swxY w Y   t          j        |t          j        t          j        z  t          j        z             |                                 d S )
Nhooks#!/bin/sh
exit 1
#!/bin/sh
exit 0
z#!/bin/sh
if [ "$(pwd)" != 'z#' ]; then
    echo "Expected path 'z'', got '$(pwd)'"
    exit 1
fi

exit 0
z
pre-commitwdarwin)r   r   jointempfilemkdtempmkdir
addCleanupshutilrmtreer   openwritechmodstatS_IREADS_IWRITES_IEXECassertRaisesr   	HookErrorexecutesysplatform)r   repo_dirpre_commit_failpre_commit_successpre_commit_cwd
pre_commithookfs           r   test_hook_pre_commitz#ShellHookTests.test_hook_pre_commit)   s   7<< 0 2 233
h00111x000
  	 W\\(G\BB
!(H55*c"" 	%aGGO$$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%
T\DM9DLHIII&*DL999<8## j#&& (!'''( ( ( ( ( ( ( ( ( ( ( ( ( ( (HZ!=!LMMMLLNNN*c"" 	(aGG&'''	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	(
T\DM9DLHIIIs6   C88C<?C<F##F'*F'H--H14H1c                    t           j                            t          j                              }t          j        t           j                            |d                     |                     t          j        |           d}d}d|z   dz   }t           j                            |dd          }t          |          }t          |d          5 }|                    |           d d d            n# 1 swxY w Y   t          j        |t          j        t          j        z  t          j        z             |                     t$          j        |j        d           t*          j        d	k    rt          |d          5 }|                    |           d d d            n# 1 swxY w Y   t          j        |t          j        t          j        z  t          j        z             |                    d
           t          |d          5 }|                    |           d d d            n# 1 swxY w Y   t          j        |t          j        t          j        z  t          j        z             |                    d           d S )Nr   r   r   #!/bin/sh
if [ "$(pwd)" = '"' ]; then exit 0; else exit 1; fi
z
commit-msgr   s   failed commitr   s   cwd test commits   empty commit)r   r   r   r    r!   r"   r#   r$   r%   r   r&   r'   r(   r)   r*   r+   r,   r-   r   r.   r/   r0   r1   )r   r2   commit_msg_failcommit_msg_successcommit_msg_cwd
commit_msgr7   r8   s           r   test_hook_commit_msgz#ShellHookTests.test_hook_commit_msg\   s   7<< 0 2 233
h00111x000
 44 	 W\\(G\BB
!(++*c"" 	%aGGO$$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%
T\DM9DLHIII&*DL:JKKK<8## j#&& (!'''( ( ( ( ( ( ( ( ( ( ( ( ( ( (HZ!=!LMMMLL+,,,*c"" 	(aGG&'''	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	(
T\DM9DLHIII_%%%%%s6   C11C58C5;FF!$F!H((H,/H,c                    t          j                    \  }}t          j        |           t          j                            t          j                              }t          j        t          j                            |d                     |                     t          j
        |           d|z   dz   }d}d|z   dz   }t          j                            |dd          }t          |          }t          |d          5 }	|	                    |           d d d            n# 1 swxY w Y   t          j        |t          j        t          j        z  t          j        z             |                     t(          j        |j                   t.          j        d	k    rt          |d          5 }	|	                    |           d d d            n# 1 swxY w Y   t          j        |t          j        t          j        z  t          j        z             |                                 t          |d          5 }	|	                    |           d d d            n# 1 swxY w Y   t          j        |t          j        t          j        z  t          j        z             |                                 |                     t          j                            |                     d S )
Nr   z#!/bin/sh
rm 
r   r;   r<   zpost-commitr   r   )r    mkstempr   closer   r   r!   r"   r#   r$   r%   r   r&   r'   r(   r)   r*   r+   r,   r-   r   r.   r/   r0   r1   assertFalser   )
r   fdr   r2   post_commit_successpost_commit_failpost_commit_cwdpost_commitr7   r8   s
             r   test_hook_post_commitz$ShellHookTests.test_hook_post_commit   s	   %''
T
7<< 0 2 233
h00111x000  	
 44 	 gll8WmDD"8,,+s## 	&qGG$%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&
dlT]:T\IJJJ&*DL999<8## k3'' )1((() ) ) ) ) ) ) ) ) ) ) ) ) ) )H[$,">"MNNNLLNNN+s## 	)qGG'(((	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	)
dlT]:T\IJJJ--.....s6   ?D!!D%(D%*GGG4III)__name__
__module____qualname__r   r9   rA   rL   __classcell__)r   s   @r   r
   r
   "   sg        3 3 3 3 31 1 1f+& +& +&Z2/ 2/ 2/ 2/ 2/ 2/ 2/r   r
   )__doc__r   r$   r)   r0   r    dulwichr   dulwich.testsr   r   r   r   r   r
    r   r   <module>rU      s   ( !   				   



        " " " " " " O O O O O O O O O OY/ Y/ Y/ Y/ Y/X Y/ Y/ Y/ Y/ Y/r   