[Python-modules-commits] [dulwich] 02/19: add tests for hook cwd

Jelmer Vernooij jelmer at moszumanska.debian.org
Sun Oct 29 17:22:26 UTC 2017


This is an automated email from the git hooks/post-receive script.

jelmer pushed a commit to branch master
in repository dulwich.

commit 55e29023827a8caa9c5a7e7f7b715f8c28a8278b
Author: Fabian Grünbichler <fabian.gruenbichler at student.tuwien.ac.at>
Date:   Sun Oct 1 20:10:49 2017 +0200

    add tests for hook cwd
---
 dulwich/tests/test_hooks.py | 46 +++++++++++++++++++++++++++++++++++----------
 1 file changed, 36 insertions(+), 10 deletions(-)

diff --git a/dulwich/tests/test_hooks.py b/dulwich/tests/test_hooks.py
index 8c8e180..5715e40 100644
--- a/dulwich/tests/test_hooks.py
+++ b/dulwich/tests/test_hooks.py
@@ -43,6 +43,10 @@ class ShellHookTests(TestCase):
             self.skipTest('shell hook tests requires POSIX shell')
 
     def test_hook_pre_commit(self):
+        repo_dir = os.path.join(tempfile.mkdtemp())
+        os.mkdir(os.path.join(repo_dir, 'hooks'))
+        self.addCleanup(shutil.rmtree, repo_dir)
+
         pre_commit_fail = """#!/bin/sh
 exit 1
 """
@@ -50,10 +54,8 @@ exit 1
         pre_commit_success = """#!/bin/sh
 exit 0
 """
-
-        repo_dir = os.path.join(tempfile.mkdtemp())
-        os.mkdir(os.path.join(repo_dir, 'hooks'))
-        self.addCleanup(shutil.rmtree, repo_dir)
+        pre_commit_cwd = """#!/bin/sh
+if [ "$(pwd)" = '""" + repo_dir + "' ]; then exit 0; else exit 1; fi\n"
 
         pre_commit = os.path.join(repo_dir, 'hooks', 'pre-commit')
         hook = PreCommitShellHook(repo_dir)
@@ -65,6 +67,12 @@ exit 0
         self.assertRaises(errors.HookError, hook.execute)
 
         with open(pre_commit, 'w') as f:
+            f.write(pre_commit_cwd)
+        os.chmod(pre_commit, stat.S_IREAD | stat.S_IWRITE | stat.S_IEXEC)
+
+        hook.execute()
+
+        with open(pre_commit, 'w') as f:
             f.write(pre_commit_success)
         os.chmod(pre_commit, stat.S_IREAD | stat.S_IWRITE | stat.S_IEXEC)
 
@@ -72,6 +80,10 @@ exit 0
 
     def test_hook_commit_msg(self):
 
+        repo_dir = os.path.join(tempfile.mkdtemp())
+        os.mkdir(os.path.join(repo_dir, 'hooks'))
+        self.addCleanup(shutil.rmtree, repo_dir)
+
         commit_msg_fail = """#!/bin/sh
 exit 1
 """
@@ -80,9 +92,8 @@ exit 1
 exit 0
 """
 
-        repo_dir = os.path.join(tempfile.mkdtemp())
-        os.mkdir(os.path.join(repo_dir, 'hooks'))
-        self.addCleanup(shutil.rmtree, repo_dir)
+        commit_msg_cwd = """#!/bin/sh
+if [ "$(pwd)" = '""" + repo_dir + "' ]; then exit 0; else exit 1; fi\n"
 
         commit_msg = os.path.join(repo_dir, 'hooks', 'commit-msg')
         hook = CommitMsgShellHook(repo_dir)
@@ -94,6 +105,12 @@ exit 0
         self.assertRaises(errors.HookError, hook.execute, b'failed commit')
 
         with open(commit_msg, 'w') as f:
+            f.write(commit_msg_cwd)
+        os.chmod(commit_msg, stat.S_IREAD | stat.S_IWRITE | stat.S_IEXEC)
+
+        hook.execute(b'cwd test commit')
+
+        with open(commit_msg, 'w') as f:
             f.write(commit_msg_success)
         os.chmod(commit_msg, stat.S_IREAD | stat.S_IWRITE | stat.S_IEXEC)
 
@@ -104,6 +121,10 @@ exit 0
         (fd, path) = tempfile.mkstemp()
         os.close(fd)
 
+        repo_dir = os.path.join(tempfile.mkdtemp())
+        os.mkdir(os.path.join(repo_dir, 'hooks'))
+        self.addCleanup(shutil.rmtree, repo_dir)
+
         post_commit_msg = """#!/bin/sh
 rm """ + path + "\n"
 
@@ -111,9 +132,8 @@ rm """ + path + "\n"
 exit 1
 """
 
-        repo_dir = os.path.join(tempfile.mkdtemp())
-        os.mkdir(os.path.join(repo_dir, 'hooks'))
-        self.addCleanup(shutil.rmtree, repo_dir)
+        post_commit_cwd = """#!/bin/sh
+if [ "$(pwd)" = '""" + repo_dir + "' ]; then exit 0; else exit 1; fi\n"
 
         post_commit = os.path.join(repo_dir, 'hooks', 'post-commit')
         hook = PostCommitShellHook(repo_dir)
@@ -125,6 +145,12 @@ exit 1
         self.assertRaises(errors.HookError, hook.execute)
 
         with open(post_commit, 'w') as f:
+            f.write(post_commit_cwd)
+        os.chmod(post_commit, stat.S_IREAD | stat.S_IWRITE | stat.S_IEXEC)
+
+        hook.execute()
+
+        with open(post_commit, 'w') as f:
             f.write(post_commit_msg)
         os.chmod(post_commit, stat.S_IREAD | stat.S_IWRITE | stat.S_IEXEC)
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/dulwich.git



More information about the Python-modules-commits mailing list