From 086af072907946295f1a3870df30bfa5cf8bf7b6 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Mon, 27 Nov 2017 20:38:17 -0500 Subject: BF(PY26): {} -> {0}, i.e. explicit index for .format() --- git/test/test_index.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'git/test/test_index.py') diff --git a/git/test/test_index.py b/git/test/test_index.py index cf746140..f601cc16 100644 --- a/git/test/test_index.py +++ b/git/test/test_index.py @@ -882,11 +882,11 @@ class TestIndex(TestBase): 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)) + fp.write('#!/usr/bin/env sh\necho -n " {0}" >> "$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)) + self.assertEqual(new_commit.message, u"{0} {1}".format(commit_message, from_hook_message)) @with_rw_repo('HEAD', bare=True) def test_commit_msg_hook_fail(self, rw_repo): -- cgit v1.2.1 From 42e89cc7c7091bb1f7a29c1a4d986d70ee5854ca Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Tue, 28 Nov 2017 09:19:02 -0500 Subject: RF(+BF?): refactor hooks creation in a test, and may be make it compat with windows --- git/test/test_index.py | 71 +++++++++++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 32 deletions(-) (limited to 'git/test/test_index.py') diff --git a/git/test/test_index.py b/git/test/test_index.py index f601cc16..109589d8 100644 --- a/git/test/test_index.py +++ b/git/test/test_index.py @@ -54,6 +54,23 @@ from gitdb.base import IStream import os.path as osp from git.cmd import Git +HOOKS_SHEBANG = \ + "!C:/Program\ Files/Git/usr/bin/sh.exe\n" if is_win \ + else "#!/usr/bin/env sh\n" + + +def _make_hook(git_dir, name, content, make_exec=True): + """A helper to create a hook""" + hp = hook_path(name, git_dir) + hpd = osp.dirname(hp) + if not osp.isdir(hpd): + os.mkdir(hpd) + with open(hp, "wt") as fp: + fp.write(HOOKS_SHEBANG + content) + if make_exec: + os.chmod(hp, 0o744) + return hp + class TestIndex(TestBase): @@ -834,25 +851,21 @@ class TestIndex(TestBase): @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) + _make_hook( + index.repo.git_dir, + 'pre-commit', + "exit 0" + ) 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) + hp = _make_hook( + index.repo.git_dir, + 'pre-commit', + "echo stdout; echo stderr 1>&2; exit 1" + ) try: index.commit("This should fail") except HookExecutionError as err: @@ -869,35 +882,29 @@ class TestIndex(TestBase): self.assertEqual(err.stderr, "\n stderr: 'stderr\n'") assert str(err) else: - raise AssertionError("Should have cought a HookExecutionError") + raise AssertionError("Should have caught 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 " {0}" >> "$1"'.format(from_hook_message)) - os.chmod(hp, 0o744) - + index = rw_repo.index + _make_hook( + index.repo.git_dir, + 'commit-msg', + 'echo -n " {0}" >> "$1"'.format(from_hook_message) + ) new_commit = index.commit(commit_message) self.assertEqual(new_commit.message, u"{0} {1}".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) + hp = _make_hook( + index.repo.git_dir, + 'commit-msg', + "echo stdout; echo stderr 1>&2; exit 1" + ) try: index.commit("This should fail") except HookExecutionError as err: -- cgit v1.2.1 From 0a67f25298c80aaeb3633342c36d6e00e91d7bd1 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Tue, 28 Nov 2017 11:51:48 -0500 Subject: RF: no "need" for custom shebang on windows since just does not work --- git/test/test_index.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'git/test/test_index.py') diff --git a/git/test/test_index.py b/git/test/test_index.py index 109589d8..2553e493 100644 --- a/git/test/test_index.py +++ b/git/test/test_index.py @@ -54,9 +54,7 @@ from gitdb.base import IStream import os.path as osp from git.cmd import Git -HOOKS_SHEBANG = \ - "!C:/Program\ Files/Git/usr/bin/sh.exe\n" if is_win \ - else "#!/usr/bin/env sh\n" +HOOKS_SHEBANG = "#!/usr/bin/env sh\n" def _make_hook(git_dir, name, content, make_exec=True): -- cgit v1.2.1 From 91b9bc4c5ecae9d5c2dff08842e23c32536d4377 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Tue, 28 Nov 2017 11:54:08 -0500 Subject: RF(TST): skip all tests dealing with hooks on windows --- git/test/test_index.py | 1 + 1 file changed, 1 insertion(+) (limited to 'git/test/test_index.py') diff --git a/git/test/test_index.py b/git/test/test_index.py index 2553e493..8431ba71 100644 --- a/git/test/test_index.py +++ b/git/test/test_index.py @@ -57,6 +57,7 @@ from git.cmd import Git HOOKS_SHEBANG = "#!/usr/bin/env sh\n" +@skipIf(is_win, "TODO: fix hooks execution on Windows: #703") def _make_hook(git_dir, name, content, make_exec=True): """A helper to create a hook""" hp = hook_path(name, git_dir) -- cgit v1.2.1 From cc340779c5cd6efb6ac3c8d21141638970180f41 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Tue, 28 Nov 2017 12:34:43 -0500 Subject: RF: use HIDE_WINDOWS_KNOWN_ERRORS instead of is_win to skip hooks tests --- git/test/test_index.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'git/test/test_index.py') diff --git a/git/test/test_index.py b/git/test/test_index.py index 8431ba71..757bec9f 100644 --- a/git/test/test_index.py +++ b/git/test/test_index.py @@ -57,7 +57,7 @@ from git.cmd import Git HOOKS_SHEBANG = "#!/usr/bin/env sh\n" -@skipIf(is_win, "TODO: fix hooks execution on Windows: #703") +@skipIf(HIDE_WINDOWS_KNOWN_ERRORS, "TODO: fix hooks execution on Windows: #703") def _make_hook(git_dir, name, content, make_exec=True): """A helper to create a hook""" hp = hook_path(name, git_dir) -- cgit v1.2.1