summaryrefslogtreecommitdiff
path: root/git/test/test_index.py
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2015-01-12 14:55:31 +0100
committerSebastian Thiel <byronimo@gmail.com>2015-01-12 14:55:31 +0100
commite8eae18dcc360e6ab96c2291982bd4306adc01b9 (patch)
tree804cc52c1a9976a7274000d9a446bae2b4f032b3 /git/test/test_index.py
parente7671110bc865786ffe61cf9b92bf43c03759229 (diff)
downloadgitpython-e8eae18dcc360e6ab96c2291982bd4306adc01b9.tar.gz
IndexFile.commit() now runs pre-commit and post-commit hooks.
However, it does so only on posix. The test-case will run on posix only as well. Please note that in theory, even on windows we will attempt to run hooks, even though I am not sure that this will actually work. Fixes #81
Diffstat (limited to 'git/test/test_index.py')
-rw-r--r--git/test/test_index.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/git/test/test_index.py b/git/test/test_index.py
index 021a8cd9..2be776cd 100644
--- a/git/test/test_index.py
+++ b/git/test/test_index.py
@@ -12,6 +12,7 @@ from git.test.lib import (
with_rw_repo
)
from git.util import Actor
+from git.exc import HookExecutionError
from git import (
IndexFile,
BlobFilter,
@@ -40,6 +41,7 @@ from git.index.typ import (
BaseIndexEntry,
IndexEntry
)
+from git.index.fun import hook_path
class TestIndex(TestBase):
@@ -665,6 +667,25 @@ class TestIndex(TestBase):
assert fkey not in index.entries
index.add(files, write=True)
+ if os.name != 'nt':
+ hp = hook_path('pre-commit', index.repo.git_dir)
+ with open(hp, "wt") as fp:
+ fp.write("#!/usr/bin/env sh\necho stdout; echo stderr 1>&2; exit 1")
+ # end
+ os.chmod(hp, 0o544)
+ try:
+ index.commit("This should fail")
+ except HookExecutionError as err:
+ assert err.status == 1
+ assert err.command == hp
+ assert err.stdout == 'stdout\n'
+ assert err.stderr == 'stderr\n'
+ assert str(err)
+ else:
+ raise AssertionError("Should have cought a HookExecutionError")
+ # end exception handling
+ os.remove(hp)
+ # end hook testing
nc = index.commit("2 files committed", head=False)
for fkey in keys: