summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.appveyor.yml3
-rw-r--r--git/cmd.py3
-rw-r--r--git/config.py25
-rw-r--r--git/index/util.py11
-rw-r--r--git/repo/base.py8
-rw-r--r--git/test/lib/helper.py11
-rw-r--r--git/test/test_config.py38
-rw-r--r--git/util.py4
8 files changed, 63 insertions, 40 deletions
diff --git a/.appveyor.yml b/.appveyor.yml
index 47bd1f0b..df957c20 100644
--- a/.appveyor.yml
+++ b/.appveyor.yml
@@ -38,9 +38,10 @@ environment:
install:
- set PATH=%PYTHON%;%PYTHON%\Scripts;%GIT_PATH%;%PATH%
- ## Print architecture, python & git used for debugging.
+ ## Print configuration for debugging.
#
- |
+ echo %PATH%
uname -a
where git git-daemon python pip pip3 pip34
python --version
diff --git a/git/cmd.py b/git/cmd.py
index f4f5f99a..88d62aa4 100644
--- a/git/cmd.py
+++ b/git/cmd.py
@@ -539,7 +539,8 @@ class Git(LazyMixin):
cmd_not_found_exception = OSError
# end handle
- log.debug("Popen(%s, cwd=%s, universal_newlines=%s", command, cwd, universal_newlines)
+ log.debug("Popen(%s, cwd=%s, universal_newlines=%s, shell=%s)",
+ command, cwd, universal_newlines, shell)
try:
proc = Popen(command,
env=env,
diff --git a/git/config.py b/git/config.py
index ad6192ff..3c6a32eb 100644
--- a/git/config.py
+++ b/git/config.py
@@ -17,6 +17,8 @@ import logging
import abc
import os
+from functools import wraps
+
from git.odict import OrderedDict
from git.util import LockFile
from git.compat import (
@@ -67,11 +69,11 @@ class MetaParserBuilder(abc.ABCMeta):
def needs_values(func):
"""Returns method assuring we read values (on demand) before we try to access them"""
+ @wraps(func)
def assure_data_present(self, *args, **kwargs):
self.read()
return func(self, *args, **kwargs)
# END wrapper method
- assure_data_present.__name__ = func.__name__
return assure_data_present
@@ -477,20 +479,15 @@ class GitConfigParser(with_metaclass(MetaParserBuilder, cp.RawConfigParser, obje
is_file_lock = isinstance(fp, string_types + (FileType, ))
if is_file_lock:
self._lock._obtain_lock()
- try:
- if not hasattr(fp, "seek"):
- with open(self._file_or_files, "wb") as fp:
- self._write(fp)
- else:
- fp.seek(0)
- # make sure we do not overwrite into an existing file
- if hasattr(fp, 'truncate'):
- fp.truncate()
+ if not hasattr(fp, "seek"):
+ with open(self._file_or_files, "wb") as fp:
self._write(fp)
- finally:
- # we release the lock - it will not vanish automatically in PY3.5+
- if is_file_lock:
- self._lock._release_lock()
+ else:
+ fp.seek(0)
+ # make sure we do not overwrite into an existing file
+ if hasattr(fp, 'truncate'):
+ fp.truncate()
+ self._write(fp)
def _assure_writable(self, method_name):
if self.read_only:
diff --git a/git/index/util.py b/git/index/util.py
index 0340500c..ce798851 100644
--- a/git/index/util.py
+++ b/git/index/util.py
@@ -2,6 +2,9 @@
import struct
import tempfile
import os
+
+from functools import wraps
+
from git.compat import is_win
__all__ = ('TemporaryFileSwap', 'post_clear_cache', 'default_index', 'git_working_dir')
@@ -48,13 +51,13 @@ def post_clear_cache(func):
natively which in fact is possible, but probably not feasible performance wise.
"""
+ @wraps(func)
def post_clear_cache_if_not_raised(self, *args, **kwargs):
rval = func(self, *args, **kwargs)
self._delete_entries_cache()
return rval
-
# END wrapper method
- post_clear_cache_if_not_raised.__name__ = func.__name__
+
return post_clear_cache_if_not_raised
@@ -63,6 +66,7 @@ def default_index(func):
repository index. This is as we rely on git commands that operate
on that index only. """
+ @wraps(func)
def check_default_index(self, *args, **kwargs):
if self._file_path != self._index_path():
raise AssertionError(
@@ -70,7 +74,6 @@ def default_index(func):
return func(self, *args, **kwargs)
# END wrpaper method
- check_default_index.__name__ = func.__name__
return check_default_index
@@ -78,6 +81,7 @@ def git_working_dir(func):
"""Decorator which changes the current working dir to the one of the git
repository in order to assure relative paths are handled correctly"""
+ @wraps(func)
def set_git_working_dir(self, *args, **kwargs):
cur_wd = os.getcwd()
os.chdir(self.repo.working_tree_dir)
@@ -88,7 +92,6 @@ def git_working_dir(func):
# END handle working dir
# END wrapper
- set_git_working_dir.__name__ = func.__name__
return set_git_working_dir
#} END decorators
diff --git a/git/repo/base.py b/git/repo/base.py
index 947d77d2..26753bab 100644
--- a/git/repo/base.py
+++ b/git/repo/base.py
@@ -899,8 +899,12 @@ class Repo(object):
try:
proc = git.clone(url, path, with_extended_output=True, as_process=True,
v=True, **add_progress(kwargs, git, progress))
- progress_handler = progress and progress.new_message_handler() or None
- handle_process_output(proc, None, progress_handler, finalize_process)
+ if progress:
+ handle_process_output(proc, None, progress.new_message_handler(), finalize_process)
+ else:
+ (stdout, stderr) = proc.communicate() # FIXME: Will block of outputs are big!
+ finalize_process(proc, stderr=stderr)
+ # end handle progress
finally:
if prev_cwd is not None:
os.chdir(prev_cwd)
diff --git a/git/test/lib/helper.py b/git/test/lib/helper.py
index 2d21f5bf..4335a977 100644
--- a/git/test/lib/helper.py
+++ b/git/test/lib/helper.py
@@ -12,6 +12,8 @@ import tempfile
import io
import logging
+from functools import wraps
+
from git import Repo, Remote, GitCommandError, Git
from git.util import rmtree
from git.compat import string_types, is_win
@@ -86,6 +88,7 @@ def with_rw_directory(func):
"""Create a temporary directory which can be written to, remove it if the
test succeeds, but leave it otherwise to aid additional debugging"""
+ @wraps(func)
def wrapper(self):
path = tempfile.mktemp(prefix=func.__name__)
os.mkdir(path)
@@ -107,7 +110,7 @@ def with_rw_directory(func):
gc.collect()
if not keep:
rmtree(path)
- wrapper.__name__ = func.__name__
+
return wrapper
@@ -124,6 +127,7 @@ def with_rw_repo(working_tree_ref, bare=False):
assert isinstance(working_tree_ref, string_types), "Decorator requires ref name for working tree checkout"
def argument_passer(func):
+ @wraps(func)
def repo_creator(self):
prefix = 'non_'
if bare:
@@ -157,7 +161,6 @@ def with_rw_repo(working_tree_ref, bare=False):
# END rm test repo if possible
# END cleanup
# END rw repo creator
- repo_creator.__name__ = func.__name__
return repo_creator
# END argument passer
return argument_passer
@@ -213,6 +216,7 @@ def with_rw_and_rw_remote_repo(working_tree_ref):
def argument_passer(func):
+ @wraps(func)
def remote_repo_creator(self):
remote_repo_dir = _mktemp("remote_repo_%s" % func.__name__)
repo_dir = _mktemp("remote_clone_non_bare_repo")
@@ -321,10 +325,9 @@ def with_rw_and_rw_remote_repo(working_tree_ref):
gd.proc.wait()
# END cleanup
# END bare repo creator
- remote_repo_creator.__name__ = func.__name__
return remote_repo_creator
# END remote repo creator
- # END argument parsser
+ # END argument parser
return argument_passer
diff --git a/git/test/test_config.py b/git/test/test_config.py
index 154aaa24..32873f24 100644
--- a/git/test/test_config.py
+++ b/git/test/test_config.py
@@ -60,7 +60,8 @@ class TestBase(TestCase):
self.assertEqual(file_obj.getvalue(), self._to_memcache(fixture_path(filename)).getvalue())
# creating an additional config writer must fail due to exclusive access
- self.failUnlessRaises(IOError, GitConfigParser, file_obj, read_only=False)
+ with self.assertRaises(IOError):
+ GitConfigParser(file_obj, read_only=False)
# should still have a lock and be able to make changes
assert w_config._lock._has_lock()
@@ -91,18 +92,21 @@ class TestBase(TestCase):
@with_rw_directory
def test_lock_reentry(self, rw_dir):
fpl = os.path.join(rw_dir, 'l')
- with GitConfigParser(fpl, read_only=False) as gcp:
- gcp.set_value('include', 'some_value', 'a')
+ gcp = GitConfigParser(fpl, read_only=False)
+ with gcp as cw:
+ cw.set_value('include', 'some_value', 'a')
# entering again locks the file again...
with gcp as cw:
cw.set_value('include', 'some_other_value', 'b')
# ...so creating an additional config writer must fail due to exclusive access
- self.failUnlessRaises(IOError, GitConfigParser, fpl, read_only=False)
+ with self.assertRaises(IOError):
+ GitConfigParser(fpl, read_only=False)
# but work when the lock is removed
with GitConfigParser(fpl, read_only=False):
assert os.path.exists(fpl)
# reentering with an existing lock must fail due to exclusive access
- self.failUnlessRaises(IOError, gcp.__enter__)
+ with self.assertRaises(IOError):
+ gcp.__enter__()
def test_multi_line_config(self):
file_obj = self._to_memcache(fixture_path("git_config_with_comments"))
@@ -144,10 +148,13 @@ class TestBase(TestCase):
assert "\n" not in val
# writing must fail
- self.failUnlessRaises(IOError, r_config.set, section, option, None)
- self.failUnlessRaises(IOError, r_config.remove_option, section, option)
+ with self.assertRaises(IOError):
+ r_config.set(section, option, None)
+ with self.assertRaises(IOError):
+ r_config.remove_option(section, option)
# END for each option
- self.failUnlessRaises(IOError, r_config.remove_section, section)
+ with self.assertRaises(IOError):
+ r_config.remove_section(section)
# END for each section
assert num_sections and num_options
assert r_config._is_initialized is True
@@ -157,7 +164,8 @@ class TestBase(TestCase):
assert r_config.get_value("doesnt", "exist", default) == default
# it raises if there is no default though
- self.failUnlessRaises(cp.NoSectionError, r_config.get_value, "doesnt", "exist")
+ with self.assertRaises(cp.NoSectionError):
+ r_config.get_value("doesnt", "exist")
@with_rw_directory
def test_config_include(self, rw_dir):
@@ -206,7 +214,8 @@ class TestBase(TestCase):
write_test_value(cw, tv)
with GitConfigParser(fpa, read_only=True) as cr:
- self.failUnlessRaises(cp.NoSectionError, check_test_value, cr, tv)
+ with self.assertRaises(cp.NoSectionError):
+ check_test_value(cr, tv)
# But can make it skip includes alltogether, and thus allow write-backs
with GitConfigParser(fpa, read_only=False, merge_includes=False) as cw:
@@ -218,8 +227,10 @@ class TestBase(TestCase):
def test_rename(self):
file_obj = self._to_memcache(fixture_path('git_config'))
with GitConfigParser(file_obj, read_only=False, merge_includes=False) as cw:
- self.failUnlessRaises(ValueError, cw.rename_section, "doesntexist", "foo")
- self.failUnlessRaises(ValueError, cw.rename_section, "core", "include")
+ with self.assertRaises(ValueError):
+ cw.rename_section("doesntexist", "foo")
+ with self.assertRaises(ValueError):
+ cw.rename_section("core", "include")
nn = "bee"
assert cw.rename_section('core', nn) is cw
@@ -237,4 +248,5 @@ class TestBase(TestCase):
assert cr.get_value('core', 'filemode'), "Should read keys with values"
- self.failUnlessRaises(cp.NoOptionError, cr.get_value, 'color', 'ui')
+ with self.assertRaises(cp.NoOptionError):
+ cr.get_value('color', 'ui')
diff --git a/git/util.py b/git/util.py
index 814cd7f4..9640a74f 100644
--- a/git/util.py
+++ b/git/util.py
@@ -14,6 +14,8 @@ import shutil
import stat
import time
+from functools import wraps
+
from git.compat import is_win
from gitdb.util import ( # NOQA
make_sha,
@@ -50,13 +52,13 @@ def unbare_repo(func):
"""Methods with this decorator raise InvalidGitRepositoryError if they
encounter a bare repository"""
+ @wraps(func)
def wrapper(self, *args, **kwargs):
if self.repo.bare:
raise InvalidGitRepositoryError("Method '%s' cannot operate on bare repositories" % func.__name__)
# END bare method
return func(self, *args, **kwargs)
# END wrapper
- wrapper.__name__ = func.__name__
return wrapper