aboutsummaryrefslogtreecommitdiff
path: root/git/test
diff options
context:
space:
mode:
Diffstat (limited to 'git/test')
-rw-r--r--git/test/test_index.py114
-rw-r--r--git/test/test_repo.py23
-rw-r--r--git/test/test_submodule.py12
3 files changed, 119 insertions, 30 deletions
diff --git a/git/test/test_index.py b/git/test/test_index.py
index e8d38a09..cf746140 100644
--- a/git/test/test_index.py
+++ b/git/test/test_index.py
@@ -729,35 +729,6 @@ class TestIndex(TestBase):
assert fkey not in index.entries
index.add(files, write=True)
- if is_win:
- hp = hook_path('pre-commit', index.repo.git_dir)
- hpd = osp.dirname(hp)
- if not osp.isdir(hpd):
- os.mkdir(hpd)
- with open(hp, "wt") as fp:
- fp.write("#!/usr/bin/env sh\necho stdout; echo stderr 1>&2; exit 1")
- # end
- os.chmod(hp, 0o744)
- try:
- index.commit("This should fail")
- except HookExecutionError as err:
- if is_win:
- self.assertIsInstance(err.status, OSError)
- self.assertEqual(err.command, [hp])
- self.assertEqual(err.stdout, '')
- self.assertEqual(err.stderr, '')
- assert str(err)
- else:
- self.assertEqual(err.status, 1)
- self.assertEqual(err.command, hp)
- self.assertEqual(err.stdout, 'stdout\n')
- self.assertEqual(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:
@@ -859,3 +830,88 @@ class TestIndex(TestBase):
r = Repo.init(rw_dir)
r.index.add([fp])
r.index.commit('Added [.exe')
+
+ @with_rw_repo('HEAD', bare=True)
+ def test_pre_commit_hook_success(self, rw_repo):
+ index = rw_repo.index
+ hp = hook_path('pre-commit', index.repo.git_dir)
+ hpd = osp.dirname(hp)
+ if not osp.isdir(hpd):
+ os.mkdir(hpd)
+ with open(hp, "wt") as fp:
+ fp.write("#!/usr/bin/env sh\nexit 0")
+ os.chmod(hp, 0o744)
+ index.commit("This should not fail")
+
+ @with_rw_repo('HEAD', bare=True)
+ def test_pre_commit_hook_fail(self, rw_repo):
+ index = rw_repo.index
+ hp = hook_path('pre-commit', index.repo.git_dir)
+ hpd = osp.dirname(hp)
+ if not osp.isdir(hpd):
+ os.mkdir(hpd)
+ with open(hp, "wt") as fp:
+ fp.write("#!/usr/bin/env sh\necho stdout; echo stderr 1>&2; exit 1")
+ os.chmod(hp, 0o744)
+ try:
+ index.commit("This should fail")
+ except HookExecutionError as err:
+ if is_win:
+ self.assertIsInstance(err.status, OSError)
+ self.assertEqual(err.command, [hp])
+ self.assertEqual(err.stdout, '')
+ self.assertEqual(err.stderr, '')
+ assert str(err)
+ else:
+ self.assertEqual(err.status, 1)
+ self.assertEqual(err.command, [hp])
+ self.assertEqual(err.stdout, "\n stdout: 'stdout\n'")
+ self.assertEqual(err.stderr, "\n stderr: 'stderr\n'")
+ assert str(err)
+ else:
+ raise AssertionError("Should have cought a HookExecutionError")
+
+ @with_rw_repo('HEAD', bare=True)
+ def test_commit_msg_hook_success(self, rw_repo):
+ index = rw_repo.index
+ commit_message = u"commit default head by Frèderic Çaufl€"
+ from_hook_message = u"from commit-msg"
+
+ hp = hook_path('commit-msg', index.repo.git_dir)
+ hpd = osp.dirname(hp)
+ if not osp.isdir(hpd):
+ os.mkdir(hpd)
+ with open(hp, "wt") as fp:
+ fp.write('#!/usr/bin/env sh\necho -n " {}" >> "$1"'.format(from_hook_message))
+ os.chmod(hp, 0o744)
+
+ new_commit = index.commit(commit_message)
+ self.assertEqual(new_commit.message, u"{} {}".format(commit_message, from_hook_message))
+
+ @with_rw_repo('HEAD', bare=True)
+ def test_commit_msg_hook_fail(self, rw_repo):
+ index = rw_repo.index
+ hp = hook_path('commit-msg', index.repo.git_dir)
+ hpd = osp.dirname(hp)
+ if not osp.isdir(hpd):
+ os.mkdir(hpd)
+ with open(hp, "wt") as fp:
+ fp.write("#!/usr/bin/env sh\necho stdout; echo stderr 1>&2; exit 1")
+ os.chmod(hp, 0o744)
+ try:
+ index.commit("This should fail")
+ except HookExecutionError as err:
+ if is_win:
+ self.assertIsInstance(err.status, OSError)
+ self.assertEqual(err.command, [hp])
+ self.assertEqual(err.stdout, '')
+ self.assertEqual(err.stderr, '')
+ assert str(err)
+ else:
+ self.assertEqual(err.status, 1)
+ self.assertEqual(err.command, [hp])
+ self.assertEqual(err.stdout, "\n stdout: 'stdout\n'")
+ self.assertEqual(err.stderr, "\n stderr: 'stderr\n'")
+ assert str(err)
+ else:
+ raise AssertionError("Should have cought a HookExecutionError")
diff --git a/git/test/test_repo.py b/git/test/test_repo.py
index 312e67f9..2c3ad957 100644
--- a/git/test/test_repo.py
+++ b/git/test/test_repo.py
@@ -16,6 +16,11 @@ try:
except ImportError:
from unittest2 import skipIf, SkipTest
+try:
+ import pathlib
+except ImportError:
+ pathlib = None
+
from git import (
InvalidGitRepositoryError,
Repo,
@@ -201,6 +206,24 @@ class TestRepo(TestBase):
pass
# END test repos with working tree
+ @with_rw_directory
+ def test_clone_from_keeps_env(self, rw_dir):
+ original_repo = Repo.init(osp.join(rw_dir, "repo"))
+ environment = {"entry1": "value", "another_entry": "10"}
+
+ cloned = Repo.clone_from(original_repo.git_dir, osp.join(rw_dir, "clone"), env=environment)
+
+ assert_equal(environment, cloned.git.environment())
+
+ @with_rw_directory
+ def test_clone_from_pathlib(self, rw_dir):
+ if pathlib is None: # pythons bellow 3.4 don't have pathlib
+ raise SkipTest("pathlib was introduced in 3.4")
+
+ original_repo = Repo.init(osp.join(rw_dir, "repo"))
+
+ Repo.clone_from(original_repo.git_dir, pathlib.Path(rw_dir) / "clone_pathlib")
+
def test_init(self):
prev_cwd = os.getcwd()
os.chdir(tempfile.gettempdir())
diff --git a/git/test/test_submodule.py b/git/test/test_submodule.py
index e667ae17..f970dd2c 100644
--- a/git/test/test_submodule.py
+++ b/git/test/test_submodule.py
@@ -10,7 +10,7 @@ except ImportError:
import git
from git.cmd import Git
-from git.compat import string_types
+from git.compat import string_types, is_win
from git.exc import (
InvalidGitRepositoryError,
RepositoryDirtyError
@@ -911,3 +911,13 @@ class TestSubmodule(TestBase):
parent_repo.submodule_update(to_latest_revision=True, force_reset=True)
assert sm_mod.commit() == sm_pfb.commit, "Now head should have been reset"
assert sm_mod.head.ref.name == sm_pfb.name
+
+ @skipIf(not is_win, "Specifically for Windows.")
+ def test_to_relative_path_with_super_at_root_drive(self):
+ class Repo(object):
+ working_tree_dir = 'D:\\'
+ super_repo = Repo()
+ submodule_path = 'D:\\submodule_path'
+ relative_path = Submodule._to_relative_path(super_repo, submodule_path)
+ msg = '_to_relative_path should be "submodule_path" but was "%s"' % relative_path
+ assert relative_path == 'submodule_path', msg \ No newline at end of file