summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.travis.yml5
-rw-r--r--doc/source/changes.rst15
-rw-r--r--doc/source/conf.py1
-rw-r--r--git/__init__.py3
-rw-r--r--git/cmd.py60
-rw-r--r--git/diff.py9
-rw-r--r--git/exc.py6
-rw-r--r--git/index/base.py42
-rw-r--r--git/objects/commit.py7
-rw-r--r--git/objects/submodule/base.py19
-rw-r--r--git/objects/util.py2
-rw-r--r--git/refs/symbolic.py3
-rw-r--r--git/remote.py39
-rw-r--r--git/test/lib/helper.py14
-rw-r--r--git/test/test_commit.py13
-rw-r--r--git/test/test_git.py11
-rw-r--r--git/test/test_remote.py6
-rw-r--r--git/util.py15
18 files changed, 197 insertions, 73 deletions
diff --git a/.travis.yml b/.travis.yml
index 1fda2018..b53228ca 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -15,18 +15,19 @@ install:
- pip install coveralls flake8 sphinx
# generate some reflog as git-python tests need it (in master)
+ - git tag __testing_point__
- git checkout master
- git reset --hard HEAD~1
- git reset --hard HEAD~1
- git reset --hard HEAD~1
- - git reset --hard origin/master
+ - git reset --hard __testing_point__
# as commits are performed with the default user, it needs to be set for travis too
- git config --global user.email "travis@ci.com"
- git config --global user.name "Travis Runner"
script:
# Make sure we limit open handles to see if we are leaking them
- - ulimit -n 64
+ - ulimit -n 96
- ulimit -n
- nosetests -v --with-coverage
- flake8
diff --git a/doc/source/changes.rst b/doc/source/changes.rst
index 5b85e56a..99b578bd 100644
--- a/doc/source/changes.rst
+++ b/doc/source/changes.rst
@@ -2,6 +2,21 @@
Changelog
=========
+0.3.7 - Fixes
+=============
+* `IndexFile.add()` will now write the index without any extension data by default. However, you may override this behaviour with the new `write_extension_data` keyword argument.
+
+ - Renamed `ignore_tree_extension_data` keyword argument in `IndexFile.write(...)` to `ignore_extension_data`
+* If the git command executed during `Remote.push(...)|fetch(...)` returns with an non-zero exit code and GitPython didn't
+ obtain any head-information, the corresponding `GitCommandError` will be raised. This may break previous code which expected
+ these operations to never raise. However, that behavious is undesirable as it would effectively hide the fact that there
+ was an error. See `this issue <https://github.com/gitpython-developers/GitPython/issues/271>`_ for more information.
+
+* If the git executable can't be found in the PATH or at the path provided by `GIT_PYTHON_GIT_EXECUTABLE`, this is made
+ obvious by throwing `GitCommandNotFound`, both on unix and on windows.
+
+ - Those who support **GUI on windows** will now have to set `git.Git.USE_SHELL = True` to get the previous behaviour.
+
0.3.6 - Features
================
* **DOCS**
diff --git a/doc/source/conf.py b/doc/source/conf.py
index f86f08ac..add686d3 100644
--- a/doc/source/conf.py
+++ b/doc/source/conf.py
@@ -94,7 +94,6 @@ pygments_style = 'sphinx'
# -----------------------
html_theme_options = {
- "stickysidebar": "true"
}
# The style sheet to use for HTML and HTML Help pages. A file of that name
diff --git a/git/__init__.py b/git/__init__.py
index 5630b91d..e8dae272 100644
--- a/git/__init__.py
+++ b/git/__init__.py
@@ -15,7 +15,8 @@ __version__ = 'git'
#{ Initialization
def _init_externals():
"""Initialize external projects by putting them into the path"""
- sys.path.append(os.path.join(os.path.dirname(__file__), 'ext', 'gitdb'))
+ if __version__ == 'git':
+ sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'ext', 'gitdb'))
try:
import gitdb
diff --git a/git/cmd.py b/git/cmd.py
index 7e15d4ea..429046be 100644
--- a/git/cmd.py
+++ b/git/cmd.py
@@ -26,7 +26,10 @@ from .util import (
stream_copy,
WaitGroup
)
-from .exc import GitCommandError
+from .exc import (
+ GitCommandError,
+ GitCommandNotFound
+)
from git.compat import (
string_types,
defenc,
@@ -241,6 +244,12 @@ class Git(LazyMixin):
_git_exec_env_var = "GIT_PYTHON_GIT_EXECUTABLE"
GIT_PYTHON_GIT_EXECUTABLE = os.environ.get(_git_exec_env_var, git_exec_name)
+ # If True, a shell will be used when executing git commands.
+ # This should only be desirable on windows, see https://github.com/gitpython-developers/GitPython/pull/126
+ # for more information
+ # Override this value using `Git.USE_SHELL = True`
+ USE_SHELL = False
+
class AutoInterrupt(object):
"""Kill/Interrupt the stored process instance once this instance goes out of scope. It is
@@ -543,18 +552,29 @@ class Git(LazyMixin):
env["LC_MESSAGES"] = "C"
env.update(self._environment)
- proc = Popen(command,
- env=env,
- cwd=cwd,
- stdin=istream,
- stderr=PIPE,
- stdout=PIPE,
- # Prevent cmd prompt popups on windows by using a shell ... .
- # See https://github.com/gitpython-developers/GitPython/pull/126
- shell=sys.platform == 'win32',
- close_fds=(os.name == 'posix'), # unsupported on windows
- **subprocess_kwargs
- )
+ if sys.platform == 'win32':
+ cmd_not_found_exception = WindowsError
+ else:
+ if sys.version_info[0] > 2:
+ cmd_not_found_exception = FileNotFoundError # NOQA # this is defined, but flake8 doesn't know
+ else:
+ cmd_not_found_exception = OSError
+ # end handle
+
+ try:
+ proc = Popen(command,
+ env=env,
+ cwd=cwd,
+ stdin=istream,
+ stderr=PIPE,
+ stdout=PIPE,
+ shell=self.USE_SHELL,
+ close_fds=(os.name == 'posix'), # unsupported on windows
+ **subprocess_kwargs
+ )
+ except cmd_not_found_exception as err:
+ raise GitCommandNotFound(str(err))
+
if as_process:
return self.AutoInterrupt(proc, command)
@@ -753,11 +773,23 @@ class Git(LazyMixin):
except KeyError:
pass
+ insert_after_this_arg = kwargs.pop('insert_kwargs_after', None)
+
# Prepare the argument list
opt_args = self.transform_kwargs(**kwargs)
ext_args = self.__unpack_args([a for a in args if a is not None])
- args = opt_args + ext_args
+ if insert_after_this_arg is None:
+ args = opt_args + ext_args
+ else:
+ try:
+ index = ext_args.index(insert_after_this_arg)
+ except ValueError:
+ raise ValueError("Couldn't find argument '%s' in args %s to insert kwargs after"
+ % (insert_after_this_arg, str(ext_args)))
+ # end handle error
+ args = ext_args[:index + 1] + opt_args + ext_args[index + 1:]
+ # end handle kwargs
def make_call():
call = [self.GIT_PYTHON_GIT_EXECUTABLE]
diff --git a/git/diff.py b/git/diff.py
index 37882369..dc53f3f7 100644
--- a/git/diff.py
+++ b/git/diff.py
@@ -168,11 +168,13 @@ class Diff(object):
a_mode is None
a_blob is None
+ a_path is None
``Deleted File``::
b_mode is None
b_blob is None
+ b_path is None
``Working Tree Blobs``
@@ -200,8 +202,8 @@ class Diff(object):
NULL_HEX_SHA = "0" * 40
NULL_BIN_SHA = b"\0" * 20
- __slots__ = ("a_blob", "b_blob", "a_mode", "b_mode", "new_file", "deleted_file",
- "rename_from", "rename_to", "diff")
+ __slots__ = ("a_blob", "b_blob", "a_mode", "b_mode", "a_path", "b_path",
+ "new_file", "deleted_file", "rename_from", "rename_to", "diff")
def __init__(self, repo, a_path, b_path, a_blob_id, b_blob_id, a_mode,
b_mode, new_file, deleted_file, rename_from,
@@ -210,6 +212,9 @@ class Diff(object):
self.a_mode = a_mode
self.b_mode = b_mode
+ self.a_path = a_path
+ self.b_path = b_path
+
if self.a_mode:
self.a_mode = mode_str_to_int(self.a_mode)
if self.b_mode:
diff --git a/git/exc.py b/git/exc.py
index 7ee6726e..f5b52374 100644
--- a/git/exc.py
+++ b/git/exc.py
@@ -18,6 +18,12 @@ class NoSuchPathError(OSError):
""" Thrown if a path could not be access by the system. """
+class GitCommandNotFound(Exception):
+ """Thrown if we cannot find the `git` executable in the PATH or at the path given by
+ the GIT_PYTHON_GIT_EXECUTABLE environment variable"""
+ pass
+
+
class GitCommandError(Exception):
""" Thrown if execution of the git command fails with non-zero status code. """
diff --git a/git/index/base.py b/git/index/base.py
index b73edd6f..10de3358 100644
--- a/git/index/base.py
+++ b/git/index/base.py
@@ -172,16 +172,17 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
""":return: list of entries, in a sorted fashion, first by path, then by stage"""
return sorted(self.entries.values(), key=lambda e: (e.path, e.stage))
- def _serialize(self, stream, ignore_tree_extension_data=False):
+ def _serialize(self, stream, ignore_extension_data=False):
entries = self._entries_sorted()
- write_cache(entries,
- stream,
- (ignore_tree_extension_data and None) or self._extension_data)
+ extension_data = self._extension_data
+ if ignore_extension_data:
+ extension_data = None
+ write_cache(entries, stream, extension_data)
return self
#} END serializable interface
- def write(self, file_path=None, ignore_tree_extension_data=False):
+ def write(self, file_path=None, ignore_extension_data=False):
"""Write the current state to our file path or to the given one
:param file_path:
@@ -190,9 +191,10 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
Please note that this will change the file_path of this index to
the one you gave.
- :param ignore_tree_extension_data:
+ :param ignore_extension_data:
If True, the TREE type extension data read in the index will not
- be written to disk. Use this if you have altered the index and
+ be written to disk. NOTE that no extension data is actually written.
+ Use this if you have altered the index and
would like to use git-write-tree afterwards to create a tree
representing your written changes.
If this data is present in the written index, git-write-tree
@@ -208,7 +210,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
lfd = LockedFD(file_path or self._file_path)
stream = lfd.open(write=True, stream=True)
- self._serialize(stream, ignore_tree_extension_data)
+ self._serialize(stream, ignore_extension_data)
lfd.commit()
@@ -577,6 +579,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
fprogress(filepath, False, filepath)
istream = self.repo.odb.store(IStream(Blob.type, st.st_size, stream))
fprogress(filepath, True, filepath)
+ stream.close()
return BaseIndexEntry((stat_mode_to_index_mode(st.st_mode),
istream.binsha, 0, to_native_path_linux(filepath)))
@@ -612,7 +615,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
return entries_added
def add(self, items, force=True, fprogress=lambda *args: None, path_rewriter=None,
- write=True):
+ write=True, write_extension_data=False):
"""Add files from the working tree, specific blobs or BaseIndexEntries
to the index.
@@ -625,6 +628,10 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
strings denote a relative or absolute path into the repository pointing to
an existing file, i.e. CHANGES, lib/myfile.ext, '/home/gitrepo/lib/myfile.ext'.
+ Absolute paths must start with working tree directory of this index's repository
+ to be considered valid. For example, if it was initialized with a non-normalized path, like
+ `/root/repo/../repo`, absolute paths to be added must start with `/root/repo/../repo`.
+
Paths provided like this must exist. When added, they will be written
into the object database.
@@ -685,8 +692,19 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
Please note that entry.path is relative to the git repository.
:param write:
- If True, the index will be written once it was altered. Otherwise
- the changes only exist in memory and are not available to git commands.
+ If True, the index will be written once it was altered. Otherwise
+ the changes only exist in memory and are not available to git commands.
+
+ :param write_extension_data:
+ If True, extension data will be written back to the index. This can lead to issues in case
+ it is containing the 'TREE' extension, which will cause the `git commit` command to write an
+ old tree, instead of a new one representing the now changed index.
+ This doesn't matter if you use `IndexFile.commit()`, which ignores the `TREE` extension altogether.
+ You should set it to True if you intend to use `IndexFile.commit()` exclusively while maintaining
+ support for third-party extensions. Besides that, you can usually safely ignore the built-in
+ extensions when using GitPython on repositories that are not handled manually at all.
+ All current built-in extensions are listed here:
+ http://opensource.apple.com/source/Git/Git-26/src/git-htmldocs/technical/index-format.txt
:return:
List(BaseIndexEntries) representing the entries just actually added.
@@ -759,7 +777,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
self.entries[(entry.path, 0)] = IndexEntry.from_base(entry)
if write:
- self.write()
+ self.write(ignore_extension_data=not write_extension_data)
# END handle write
return entries_added
diff --git a/git/objects/commit.py b/git/objects/commit.py
index b9718694..f13760fd 100644
--- a/git/objects/commit.py
+++ b/git/objects/commit.py
@@ -189,9 +189,12 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable):
if 'pretty' in kwargs:
raise ValueError("--pretty cannot be used as parsing expects single sha's only")
# END handle pretty
- args = list()
+
+ # use -- in any case, to prevent possibility of ambiguous arguments
+ # see https://github.com/gitpython-developers/GitPython/issues/264
+ args = ['--']
if paths:
- args.extend(('--', paths))
+ args.extend((paths, ))
# END if paths
proc = repo.git.rev_list(rev, args, as_process=True, **kwargs)
diff --git a/git/objects/submodule/base.py b/git/objects/submodule/base.py
index be243acc..f9b0b6ad 100644
--- a/git/objects/submodule/base.py
+++ b/git/objects/submodule/base.py
@@ -37,7 +37,7 @@ import git
import os
import logging
-import tempfile
+import uuid
__all__ = ["Submodule", "UpdateProgress"]
@@ -136,7 +136,7 @@ class Submodule(util.IndexObject, Iterable, Traversable):
@classmethod
def _need_gitfile_submodules(cls, git):
- return git.version_info[:3] >= (1, 8, 0)
+ return git.version_info[:3] >= (1, 7, 0)
def __eq__(self, other):
"""Compare with another submodule"""
@@ -293,7 +293,8 @@ class Submodule(util.IndexObject, Iterable, Traversable):
fp.close()
writer = GitConfigParser(os.path.join(module_abspath, 'config'), read_only=False, merge_includes=False)
- writer.set_value('core', 'worktree', os.path.relpath(working_tree_dir, start=module_abspath))
+ writer.set_value('core', 'worktree',
+ to_native_path_linux(os.path.relpath(working_tree_dir, start=module_abspath)))
writer.release()
#{ Edit Interface
@@ -578,11 +579,13 @@ class Submodule(util.IndexObject, Iterable, Traversable):
base_commit = mrepo.merge_base(mrepo.head.commit, hexsha)
if len(base_commit) == 0 or base_commit[0].hexsha == hexsha:
if force:
- log.debug("Will force checkout or reset on local branch that is possibly in the future of"
- + "the commit it will be checked out to, effectively 'forgetting' new commits")
+ msg = "Will force checkout or reset on local branch that is possibly in the future of"
+ msg += "the commit it will be checked out to, effectively 'forgetting' new commits"
+ log.debug(msg)
else:
- log.info("Skipping %s on branch '%s' of submodule repo '%s' as it contains "
- + "un-pushed commits", is_detached and "checkout" or "reset", mrepo.head, mrepo)
+ msg = "Skipping %s on branch '%s' of submodule repo '%s' as it contains un-pushed commits"
+ msg %= (is_detached and "checkout" or "reset", mrepo.head, mrepo)
+ log.info(msg)
may_reset = False
# end handle force
# end handle if we are in the future
@@ -992,7 +995,7 @@ class Submodule(util.IndexObject, Iterable, Traversable):
source_dir = mod.git_dir
# Let's be sure the submodule name is not so obviously tied to a directory
if destination_module_abspath.startswith(mod.git_dir):
- tmp_dir = self._module_abspath(self.repo, self.path, os.path.basename(tempfile.mkdtemp()))
+ tmp_dir = self._module_abspath(self.repo, self.path, str(uuid.uuid4()))
os.renames(source_dir, tmp_dir)
source_dir = tmp_dir
# end handle self-containment
diff --git a/git/objects/util.py b/git/objects/util.py
index cefef862..567b1d5b 100644
--- a/git/objects/util.py
+++ b/git/objects/util.py
@@ -216,7 +216,7 @@ class ProcessStreamAdapter(object):
class Traversable(object):
- """Simple interface to perforam depth-first or breadth-first traversals
+ """Simple interface to perform depth-first or breadth-first traversals
into one direction.
Subclasses only need to implement one function.
Instances of the Subclass must be hashable"""
diff --git a/git/refs/symbolic.py b/git/refs/symbolic.py
index fed7006e..d884250f 100644
--- a/git/refs/symbolic.py
+++ b/git/refs/symbolic.py
@@ -140,6 +140,7 @@ class SymbolicReference(object):
# Don't only split on spaces, but on whitespace, which allows to parse lines like
# 60b64ef992065e2600bfef6187a97f92398a9144 branch 'master' of git-server:/path/to/repo
tokens = value.split()
+ assert(len(tokens) != 0)
except (OSError, IOError):
# Probably we are just packed, find our entry in the packed refs file
# NOTE: We are not a symbolic ref if we are in a packed file, as these
@@ -582,6 +583,8 @@ class SymbolicReference(object):
# END prune non-refs folders
for f in files:
+ if f == 'packed-refs':
+ continue
abs_path = to_native_path_linux(join_path(root, f))
rela_paths.add(abs_path.replace(to_native_path_linux(repo.git_dir) + '/', ""))
# END for each file in root directory
diff --git a/git/remote.py b/git/remote.py
index 2267c203..4baa2838 100644
--- a/git/remote.py
+++ b/git/remote.py
@@ -455,7 +455,13 @@ class Remote(LazyMixin, Iterable):
remote side, but are still available locally.
The IterableList is prefixed, hence the 'origin' must be omitted. See
- 'refs' property for an example."""
+ 'refs' property for an example.
+
+ To make things more complicated, it can be possble for the list to include
+ other kinds of references, for example, tag references, if these are stale
+ as well. This is a fix for the issue described here:
+ https://github.com/gitpython-developers/GitPython/issues/260
+ """
out_refs = IterableList(RemoteReference._id_attribute_, "%s/" % self.name)
for line in self.repo.git.remote("prune", "--dry-run", self).splitlines()[2:]:
# expecting
@@ -463,8 +469,14 @@ class Remote(LazyMixin, Iterable):
token = " * [would prune] "
if not line.startswith(token):
raise ValueError("Could not parse git-remote prune result: %r" % line)
- fqhn = "%s/%s" % (RemoteReference._common_path_default, line.replace(token, ""))
- out_refs.append(RemoteReference(self.repo, fqhn))
+ ref_name = line.replace(token, "")
+ # sometimes, paths start with a full ref name, like refs/tags/foo, see #260
+ if ref_name.startswith(Reference._common_path_default + '/'):
+ out_refs.append(SymbolicReference.from_path(self.repo, ref_name))
+ else:
+ fqhn = "%s/%s" % (RemoteReference._common_path_default, ref_name)
+ out_refs.append(RemoteReference(self.repo, fqhn))
+ # end special case handlin
# END for each line
return out_refs
@@ -477,7 +489,9 @@ class Remote(LazyMixin, Iterable):
:param kwargs: Additional arguments to be passed to the git-remote add command
:return: New Remote instance
:raise GitCommandError: in case an origin with that name already exists"""
- repo.git.remote("add", name, url, **kwargs)
+ scmd = 'add'
+ kwargs['insert_kwargs_after'] = scmd
+ repo.git.remote(scmd, name, url, **kwargs)
return cls(repo, name)
# add is an alias
@@ -517,7 +531,9 @@ class Remote(LazyMixin, Iterable):
Additional arguments passed to git-remote update
:return: self """
- self.repo.git.remote("update", self.name, **kwargs)
+ scmd = 'update'
+ kwargs['insert_kwargs_after'] = scmd
+ self.repo.git.remote(scmd, self.name, **kwargs)
return self
def _get_fetch_info_from_stderr(self, proc, progress):
@@ -552,7 +568,12 @@ class Remote(LazyMixin, Iterable):
# end
# We are only interested in stderr here ...
- finalize_process(proc)
+ try:
+ finalize_process(proc)
+ except Exception:
+ if len(fetch_info_lines) == 0:
+ raise
+ # end exception handler
# read head information
fp = open(join(self.repo.git_dir, 'FETCH_HEAD'), 'rb')
@@ -585,7 +606,11 @@ class Remote(LazyMixin, Iterable):
# END exception handling
# END for each line
- handle_process_output(proc, stdout_handler, progress_handler, finalize_process)
+ try:
+ handle_process_output(proc, stdout_handler, progress_handler, finalize_process)
+ except Exception:
+ if len(output) == 0:
+ raise
return output
def fetch(self, refspec=None, progress=None, **kwargs):
diff --git a/git/test/lib/helper.py b/git/test/lib/helper.py
index 31bee78f..541b972d 100644
--- a/git/test/lib/helper.py
+++ b/git/test/lib/helper.py
@@ -232,7 +232,13 @@ def with_rw_and_rw_remote_repo(working_tree_ref):
prev_cwd = os.getcwd()
os.chdir(rw_repo.working_dir)
try:
- return func(self, rw_repo, rw_remote_repo)
+ try:
+ return func(self, rw_repo, rw_remote_repo)
+ except:
+ print("Keeping repos after failure: repo_dir = %s, remote_repo_dir = %s"
+ % (repo_dir, remote_repo_dir), file=sys.stderr)
+ repo_dir = remote_repo_dir = None
+ raise
finally:
# gd.proc.kill() ... no idea why that doesn't work
if gd is not None:
@@ -241,8 +247,10 @@ def with_rw_and_rw_remote_repo(working_tree_ref):
os.chdir(prev_cwd)
rw_repo.git.clear_cache()
rw_remote_repo.git.clear_cache()
- shutil.rmtree(repo_dir, onerror=_rmtree_onerror)
- shutil.rmtree(remote_repo_dir, onerror=_rmtree_onerror)
+ if repo_dir:
+ shutil.rmtree(repo_dir, onerror=_rmtree_onerror)
+ if remote_repo_dir:
+ shutil.rmtree(remote_repo_dir, onerror=_rmtree_onerror)
if gd is not None:
gd.proc.wait()
diff --git a/git/test/test_commit.py b/git/test/test_commit.py
index 1f0f8c56..3e958edf 100644
--- a/git/test/test_commit.py
+++ b/git/test/test_commit.py
@@ -19,15 +19,19 @@ from git import (
Actor,
)
from gitdb import IStream
+from gitdb.test.lib import with_rw_directory
from git.compat import (
string_types,
text_type
)
+from git import Repo
+from git.repo.fun import touch
from io import BytesIO
import time
import sys
import re
+import os
def assert_commit_serialization(rwrepo, commit_id, print_performance_info=False):
@@ -219,6 +223,15 @@ class TestCommit(TestBase):
for sha1, commit in zip(expected_ids, commits):
assert_equal(sha1, commit.hexsha)
+ @with_rw_directory
+ def test_ambiguous_arg_iteration(self, rw_dir):
+ rw_repo = Repo.init(os.path.join(rw_dir, 'test_ambiguous_arg'))
+ path = os.path.join(rw_repo.working_tree_dir, 'master')
+ touch(path)
+ rw_repo.index.add([path])
+ rw_repo.index.commit('initial commit')
+ list(rw_repo.iter_commits(rw_repo.head.ref)) # should fail unless bug is fixed
+
def test_count(self):
assert self.rorepo.tag('refs/tags/0.1.5').commit.count() == 143
diff --git a/git/test/test_git.py b/git/test/test_git.py
index 8087bc45..742c842d 100644
--- a/git/test/test_git.py
+++ b/git/test/test_git.py
@@ -19,6 +19,7 @@ from git.test.lib import (
from git import (
Git,
GitCommandError,
+ GitCommandNotFound,
Repo
)
from gitdb.test.lib import with_rw_directory
@@ -127,11 +128,7 @@ class TestGit(TestBase):
def test_cmd_override(self):
prev_cmd = self.git.GIT_PYTHON_GIT_EXECUTABLE
- if os.name == 'nt':
- exc = GitCommandError
- else:
- exc = OSError
- # end handle windows case
+ exc = GitCommandNotFound
try:
# set it to something that doens't exist, assure it raises
type(self.git).GIT_PYTHON_GIT_EXECUTABLE = os.path.join(
@@ -155,6 +152,10 @@ class TestGit(TestBase):
def test_change_to_transform_kwargs_does_not_break_command_options(self):
self.git.log(n=1)
+ def test_insert_after_kwarg_raises(self):
+ # This isn't a complete add command, which doesn't matter here
+ self.failUnlessRaises(ValueError, self.git.remote, 'add', insert_kwargs_after='foo')
+
def test_env_vars_passed_to_git(self):
editor = 'non_existant_editor'
with mock.patch.dict('os.environ', {'GIT_EDITOR': editor}):
diff --git a/git/test/test_remote.py b/git/test/test_remote.py
index 2540e49b..c419ecee 100644
--- a/git/test/test_remote.py
+++ b/git/test/test_remote.py
@@ -313,8 +313,7 @@ class TestRemote(TestBase):
self._do_test_push_result(res, remote)
# invalid refspec
- res = remote.push("hellothere")
- assert len(res) == 0
+ self.failUnlessRaises(GitCommandError, remote.push, "hellothere")
# push new tags
progress = TestRemoteProgress()
@@ -486,6 +485,9 @@ class TestRemote(TestBase):
# END if deleted remote matches existing remote's name
# END for each remote
+ # Issue #262 - the next call would fail if bug wasn't fixed
+ bare_rw_repo.create_remote('bogus', '/bogus/path', mirror='push')
+
def test_fetch_info(self):
# assure we can handle remote-tracking branches
fetch_info_line_fmt = "c437ee5deb8d00cf02f03720693e4c802e99f390 not-for-merge %s '0.3' of "
diff --git a/git/util.py b/git/util.py
index 02c54bc3..1147cb53 100644
--- a/git/util.py
+++ b/git/util.py
@@ -16,10 +16,7 @@ import threading
# NOTE: Some of the unused imports might be used/imported by others.
# Handle once test-cases are back up and running.
-from .exc import (
- GitCommandError,
- InvalidGitRepositoryError
-)
+from .exc import InvalidGitRepositoryError
from .compat import (
MAXSIZE,
@@ -154,15 +151,7 @@ def get_user_id():
def finalize_process(proc):
"""Wait for the process (clone, fetch, pull or push) and handle its errors accordingly"""
- try:
- proc.wait()
- except GitCommandError:
- # if a push has rejected items, the command has non-zero return status
- # a return status of 128 indicates a connection error - reraise the previous one
- if proc.poll() == 128:
- raise
- pass
- # END exception handling
+ proc.wait()
#} END utilities