Skip to content

Commit

Permalink
Merge pull request #702 from yarikoptic/bf-happy-travis
Browse files Browse the repository at this point in the history
BF (codename "happy travis"): trying to address lints etc to make Travis green again
  • Loading branch information
Byron authored Dec 11, 2017
2 parents 0a96030 + f48d087 commit a14277e
Show file tree
Hide file tree
Showing 15 changed files with 107 additions and 93 deletions.
10 changes: 9 additions & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ install:
echo %PATH%
uname -a
git --version
where git git-daemon python pip pip3 pip34
where git git-daemon python pip pip3 pip34 sh
python --version
python -c "import struct; print(struct.calcsize('P') * 8)"
Expand Down Expand Up @@ -91,3 +91,11 @@ test_script:

on_success:
- IF "%PYTHON_VERSION%" == "3.5" IF NOT "%IS_CYGWIN%" == "yes" (codecov)

# Enable this to be able to login to the build worker. You can use the
# `remmina` program in Ubuntu, use the login information that the line below
# prints into the log.
#on_finish:
# - |
# echo "Running on_finish to establish connection back to the instance"
# - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ Contributors are:
-Piotr Babij <piotr.babij _at_ gmail.com>
-Mikuláš Poul <mikulaspoul _at_ gmail.com>
-Charles Bouchard-Légaré <cblegare.atl _at_ ntis.ca>
-Yaroslav Halchenko <debian _at_ onerussian.com>

Portions derived from other open source works and are clearly marked.
2 changes: 1 addition & 1 deletion git/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,5 +309,5 @@ def register_surrogateescape():

try:
b"100644 \x9f\0aaa".decode(defenc, "surrogateescape")
except:
except Exception:
register_surrogateescape()
14 changes: 7 additions & 7 deletions git/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,20 +313,20 @@ def __str__(self):
h %= self.b_blob.path

msg = ''
l = None # temp line
ll = 0 # line length
line = None # temp line
line_length = 0 # line length
for b, n in zip((self.a_blob, self.b_blob), ('lhs', 'rhs')):
if b:
l = "\n%s: %o | %s" % (n, b.mode, b.hexsha)
line = "\n%s: %o | %s" % (n, b.mode, b.hexsha)
else:
l = "\n%s: None" % n
line = "\n%s: None" % n
# END if blob is not None
ll = max(len(l), ll)
msg += l
line_length = max(len(line), line_length)
msg += line
# END for each blob

# add headline
h += '\n' + '=' * ll
h += '\n' + '=' * line_length

if self.deleted_file:
msg += '\nfile deleted in rhs'
Expand Down
2 changes: 1 addition & 1 deletion git/exc.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def __init__(self, command, status=None, stderr=None, stdout=None):
else:
try:
status = u'exit code(%s)' % int(status)
except:
except (ValueError, TypeError):
s = safe_decode(str(status))
status = u"'%s'" % s if isinstance(status, string_types) else s

Expand Down
2 changes: 1 addition & 1 deletion git/refs/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def to_file(self, filepath):
try:
self._serialize(fp)
lfd.commit()
except:
except Exception:
# on failure it rolls back automatically, but we make it clear
lfd.rollback()
raise
Expand Down
8 changes: 5 additions & 3 deletions git/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,9 +542,11 @@ def urls(self):
if ' Push URL:' in line:
yield line.split(': ')[-1]
except GitCommandError as ex:
if any([msg in str(ex) for msg in ['correct access rights','cannot run ssh']]):
# If ssh is not setup to access this repository, see issue 694
result = Git().execute(['git','config','--get','remote.%s.url' % self.name])
if any([msg in str(ex) for msg in ['correct access rights', 'cannot run ssh']]):
# If ssh is not setup to access this repository, see issue 694
result = Git().execute(
['git', 'config', '--get', 'remote.%s.url' % self.name]
)
yield result
else:
raise ex
Expand Down
2 changes: 1 addition & 1 deletion git/repo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def __exit__(self, exc_type, exc_value, traceback):
def __del__(self):
try:
self.close()
except:
except Exception:
pass

def close(self):
Expand Down
6 changes: 3 additions & 3 deletions git/test/lib/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def repo_creator(self):
try:
try:
return func(self, rw_repo)
except:
except: # noqa E722
log.info("Keeping repo after failure: %s", repo_dir)
repo_dir = None
raise
Expand Down Expand Up @@ -227,7 +227,7 @@ def with_rw_and_rw_remote_repo(working_tree_ref):
Same as with_rw_repo, but also provides a writable remote repository from which the
rw_repo has been forked as well as a handle for a git-daemon that may be started to
run the remote_repo.
The remote repository was cloned as bare repository from the rorepo, whereas
The remote repository was cloned as bare repository from the ro repo, whereas
the rw repo has a working tree and was cloned from the remote repository.
remote_repo has two remotes: origin and daemon_origin. One uses a local url,
Expand Down Expand Up @@ -296,7 +296,7 @@ def remote_repo_creator(self):
with cwd(rw_repo.working_dir):
try:
return func(self, rw_repo, rw_daemon_repo)
except:
except: # noqa E722
log.info("Keeping repos after failure: \n rw_repo_dir: %s \n rw_daemon_repo_dir: %s",
rw_repo_dir, rw_daemon_repo_dir)
rw_repo_dir = rw_daemon_repo_dir = None
Expand Down
3 changes: 1 addition & 2 deletions git/test/test_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,7 @@ def test_traversal(self):
# at some point, both iterations should stop
self.assertEqual(list(bfirst)[-1], first)
stoptraverse = self.rorepo.commit("254d04aa3180eb8b8daf7b7ff25f010cd69b4e7d").traverse(as_edge=True)
l = list(stoptraverse)
self.assertEqual(len(l[0]), 2)
self.assertEqual(len(next(stoptraverse)), 2)

# ignore self
self.assertEqual(next(start.traverse(ignore_self=False)), start)
Expand Down
5 changes: 4 additions & 1 deletion git/test/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
except ImportError:
import mock

from git.compat import is_win


class TestGit(TestBase):

Expand Down Expand Up @@ -177,7 +179,8 @@ def test_refresh(self):
self.assertRaises(GitCommandNotFound, refresh, "yada")

# test a good path refresh
path = os.popen("which git").read().strip()
which_cmd = "where" if is_win else "which"
path = os.popen("{0} git".format(which_cmd)).read().strip().split('\n')[0]
refresh(path)

def test_options_are_passed_to_git(self):
Expand Down
72 changes: 39 additions & 33 deletions git/test/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,22 @@
import os.path as osp
from git.cmd import Git

HOOKS_SHEBANG = "#!/usr/bin/env sh\n"


@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)
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):

Expand Down Expand Up @@ -834,25 +850,21 @@ def test_add_a_file_with_wildcard_chars(self, rw_dir):
@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:
Expand All @@ -869,35 +881,29 @@ def test_pre_commit_hook_fail(self, rw_repo):
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 " {}" >> "$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"{} {}".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):
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:
Expand Down
2 changes: 1 addition & 1 deletion git/test/test_submodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -920,4 +920,4 @@ class Repo(object):
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
assert relative_path == 'submodule_path', msg
54 changes: 27 additions & 27 deletions git/test/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,49 +217,49 @@ def test_actor(self):
@ddt.data(('name', ''), ('name', 'prefix_'))
def test_iterable_list(self, case):
name, prefix = case
l = IterableList(name, prefix)
ilist = IterableList(name, prefix)

name1 = "one"
name2 = "two"
m1 = TestIterableMember(prefix + name1)
m2 = TestIterableMember(prefix + name2)

l.extend((m1, m2))
ilist.extend((m1, m2))

self.assertEqual(len(l), 2)
self.assertEqual(len(ilist), 2)

# contains works with name and identity
self.assertIn(name1, l)
self.assertIn(name2, l)
self.assertIn(m2, l)
self.assertIn(m2, l)
self.assertNotIn('invalid', l)
self.assertIn(name1, ilist)
self.assertIn(name2, ilist)
self.assertIn(m2, ilist)
self.assertIn(m2, ilist)
self.assertNotIn('invalid', ilist)

# with string index
self.assertIs(l[name1], m1)
self.assertIs(l[name2], m2)
self.assertIs(ilist[name1], m1)
self.assertIs(ilist[name2], m2)

# with int index
self.assertIs(l[0], m1)
self.assertIs(l[1], m2)
self.assertIs(ilist[0], m1)
self.assertIs(ilist[1], m2)

# with getattr
self.assertIs(l.one, m1)
self.assertIs(l.two, m2)
self.assertIs(ilist.one, m1)
self.assertIs(ilist.two, m2)

# test exceptions
self.failUnlessRaises(AttributeError, getattr, l, 'something')
self.failUnlessRaises(IndexError, l.__getitem__, 'something')
self.failUnlessRaises(AttributeError, getattr, ilist, 'something')
self.failUnlessRaises(IndexError, ilist.__getitem__, 'something')

# delete by name and index
self.failUnlessRaises(IndexError, l.__delitem__, 'something')
del(l[name2])
self.assertEqual(len(l), 1)
self.assertNotIn(name2, l)
self.assertIn(name1, l)
del(l[0])
self.assertNotIn(name1, l)
self.assertEqual(len(l), 0)

self.failUnlessRaises(IndexError, l.__delitem__, 0)
self.failUnlessRaises(IndexError, l.__delitem__, 'something')
self.failUnlessRaises(IndexError, ilist.__delitem__, 'something')
del(ilist[name2])
self.assertEqual(len(ilist), 1)
self.assertNotIn(name2, ilist)
self.assertIn(name1, ilist)
del(ilist[0])
self.assertNotIn(name1, ilist)
self.assertEqual(len(ilist), 0)

self.failUnlessRaises(IndexError, ilist.__delitem__, 0)
self.failUnlessRaises(IndexError, ilist.__delitem__, 'something')
17 changes: 6 additions & 11 deletions git/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,20 +188,15 @@ def assure_directory_exists(path, is_file=False):


def _get_exe_extensions():
try:
winprog_exts = tuple(p.upper() for p in os.environ['PATHEXT'].split(os.pathsep))
except:
winprog_exts = ('.BAT', 'COM', '.EXE')

return winprog_exts
PATHEXT = os.environ.get('PATHEXT', None)
return tuple(p.upper() for p in PATHEXT.split(os.pathsep)) \
if PATHEXT \
else (('.BAT', 'COM', '.EXE') if is_win else ())


def py_where(program, path=None):
# From: http://stackoverflow.com/a/377028/548792
try:
winprog_exts = tuple(p.upper() for p in os.environ['PATHEXT'].split(os.pathsep))
except:
winprog_exts = is_win and ('.BAT', 'COM', '.EXE') or ()
winprog_exts = _get_exe_extensions()

def is_exec(fpath):
return osp.isfile(fpath) and os.access(fpath, os.X_OK) and (
Expand Down Expand Up @@ -347,7 +342,7 @@ def expand_path(p, expand_vars=True):
if expand_vars:
p = osp.expandvars(p)
return osp.normpath(osp.abspath(p))
except:
except Exception:
return None

#} END utilities
Expand Down

0 comments on commit a14277e

Please sign in to comment.