Skip to content

Commit 2f66d1e

Browse files
committed
Merge remote-tracking branch 'upstream/master' into tmp-unicode-path
* upstream/master: chore(lint): flake8 pacification fix(refs): handle quoted branch names chore(repo): remove comment chore(lint): flake8 fix(submodule): don't fail if tracking branch can't be setup Don't change the meaning of string literals Fixes to support Python 2.6 again.
2 parents 1a09edb + b0c1872 commit 2f66d1e

20 files changed

+107
-35
lines changed

.appveyor.yml

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ environment:
77
matrix:
88
## MINGW
99
#
10+
- PYTHON: "C:\\Python26"
11+
PYTHON_VERSION: "2.6"
12+
GIT_PATH: "%GIT_DAEMON_PATH%"
1013
- PYTHON: "C:\\Python27"
1114
PYTHON_VERSION: "2.7"
1215
GIT_PATH: "%GIT_DAEMON_PATH%"

.travis.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
language: python
22
python:
3+
- "2.6"
34
- "2.7"
45
- "3.3"
56
- "3.4"
67
- "3.5"
78
# - "pypy" - won't work as smmap doesn't work (see gitdb/.travis.yml for details)
9+
#matrix:
10+
# allow_failures:
11+
# - python: "2.6"
812
git:
913
# a higher depth is needed for most of the tests - must be high enough to not actually be shallow
1014
# as we clone our own repository in the process
@@ -18,7 +22,8 @@ install:
1822
- git fetch --tags
1923
- pip install -r test-requirements.txt
2024
- pip install codecov sphinx
21-
25+
- if [ "$TRAVIS_PYTHON_VERSION" == '2.6' ]; then pip install unittest2; fi
26+
2227
- if [ ! -z "$TMPDIR" ]; then echo "Symlinking $TMPDIR"; ln -s /tmp "$TMPDIR"; fi
2328

2429
# generate some reflog as git-python tests need it (in master)

git/cmd.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,14 @@ def dict_to_slots_and__excluded_are_none(self, d, excluded=()):
135135

136136
## -- End Utilities -- @}
137137

138+
138139
# value of Windows process creation flag taken from MSDN
139140
CREATE_NO_WINDOW = 0x08000000
140141

141142
## CREATE_NEW_PROCESS_GROUP is needed to allow killing it afterwards,
142-
# seehttps://docs.python.org/3/library/subprocess.html#subprocess.Popen.send_signal
143+
# see https://docs.python.org/3/library/subprocess.html#subprocess.Popen.send_signal
143144
PROC_CREATIONFLAGS = (CREATE_NO_WINDOW | subprocess.CREATE_NEW_PROCESS_GROUP
144-
if is_win
145+
if is_win and sys.version_info >= (2, 7)
145146
else 0)
146147

147148

@@ -245,7 +246,7 @@ def __del__(self):
245246
return
246247

247248
# can be that nothing really exists anymore ...
248-
if os is None or os.kill is None:
249+
if os is None or getattr(os, 'kill', None) is None:
249250
return
250251

251252
# try to kill it
@@ -831,8 +832,12 @@ def _call_process(self, method, *args, **kwargs):
831832
:return: Same as ``execute``"""
832833
# Handle optional arguments prior to calling transform_kwargs
833834
# otherwise these'll end up in args, which is bad.
834-
_kwargs = {k: v for k, v in kwargs.items() if k in execute_kwargs}
835-
kwargs = {k: v for k, v in kwargs.items() if k not in execute_kwargs}
835+
_kwargs = dict()
836+
for kwarg in execute_kwargs:
837+
try:
838+
_kwargs[kwarg] = kwargs.pop(kwarg)
839+
except KeyError:
840+
pass
836841

837842
insert_after_this_arg = kwargs.pop('insert_kwargs_after', None)
838843

git/objects/submodule/base.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
import logging
44
import os
55
import stat
6-
from unittest.case import SkipTest
6+
try:
7+
from unittest import SkipTest
8+
except ImportError:
9+
from unittest2 import SkipTest
710
import uuid
811

912
import git
@@ -537,7 +540,7 @@ def update(self, recursive=False, init=True, to_latest_revision=False, progress=
537540
# make sure HEAD is not detached
538541
mrepo.head.set_reference(local_branch, logmsg="submodule: attaching head to %s" % local_branch)
539542
mrepo.head.ref.set_tracking_branch(remote_branch)
540-
except IndexError:
543+
except (IndexError, InvalidGitRepositoryError):
541544
log.warn("Failed to checkout tracking branch %s", self.branch_path)
542545
# END handle tracking branch
543546

git/objects/submodule/root.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717

1818

1919
class RootUpdateProgress(UpdateProgress):
20-
2120
"""Utility class which adds more opcodes to the UpdateProgress"""
2221
REMOVE, PATHCHANGE, BRANCHCHANGE, URLCHANGE = [
2322
1 << x for x in range(UpdateProgress._num_op_codes, UpdateProgress._num_op_codes + 4)]
2423
_num_op_codes = UpdateProgress._num_op_codes + 4
2524

2625
__slots__ = tuple()
2726

27+
2828
BEGIN = RootUpdateProgress.BEGIN
2929
END = RootUpdateProgress.END
3030
REMOVE = RootUpdateProgress.REMOVE

git/refs/head.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
__all__ = ["HEAD", "Head"]
99

1010

11+
def strip_quotes(string):
12+
if string.startswith('"') and string.endswith('"'):
13+
return string[1:-1]
14+
return string
15+
16+
1117
class HEAD(SymbolicReference):
1218

1319
"""Special case of a Symbolic Reference as it represents the repository's
@@ -152,7 +158,7 @@ def tracking_branch(self):
152158
from .remote import RemoteReference
153159
reader = self.config_reader()
154160
if reader.has_option(self.k_config_remote) and reader.has_option(self.k_config_remote_ref):
155-
ref = Head(self.repo, Head.to_full_path(reader.get_value(self.k_config_remote_ref)))
161+
ref = Head(self.repo, Head.to_full_path(strip_quotes(reader.get_value(self.k_config_remote_ref))))
156162
remote_refpath = RemoteReference.to_full_path(join_path(reader.get_value(self.k_config_remote), ref.name))
157163
return RemoteReference(self.repo, remote_refpath)
158164
# END handle have tracking branch

git/repo/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,7 @@ def _clone(cls, git, url, path, odb_default_type, progress, **kwargs):
875875
if progress:
876876
handle_process_output(proc, None, progress.new_message_handler(), finalize_process)
877877
else:
878-
(stdout, stderr) = proc.communicate() # FIXME: Will block if outputs are big!
878+
(stdout, stderr) = proc.communicate()
879879
log.debug("Cmd(%s)'s unused stdout: %s", getattr(proc, 'args', ''), stdout)
880880
finalize_process(proc, stderr=stderr)
881881

git/test/lib/helper.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,24 @@
77

88
import contextlib
99
from functools import wraps
10+
import sys
1011
import io
1112
import logging
1213
import os
1314
import tempfile
1415
import textwrap
1516
import time
16-
from unittest import TestCase
17-
import unittest
1817

19-
from git.compat import string_types, is_win, PY3
18+
from git.compat import string_types, is_win
2019
from git.util import rmtree, cwd
2120

2221
import os.path as osp
22+
if sys.version_info[0:2] == (2, 6):
23+
import unittest2 as unittest
24+
else:
25+
import unittest
2326

27+
TestCase = unittest.TestCase
2428

2529
ospd = osp.dirname
2630

@@ -335,8 +339,11 @@ class TestBase(TestCase):
335339
of the project history ( to assure tests don't fail for others ).
336340
"""
337341

338-
if not PY3:
339-
assertRaisesRegex = unittest.TestCase.assertRaisesRegexp
342+
# On py26, unittest2 has assertRaisesRegex
343+
# On py3, unittest has assertRaisesRegex
344+
# On py27, we use unittest, which names it differently:
345+
if sys.version_info[0:2] == (2, 7):
346+
assertRaisesRegex = TestCase.assertRaisesRegexp
340347

341348
def _small_repo_url(self):
342349
""":return" a path to a small, clonable repository"""

git/test/test_base.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
import os
88
import sys
99
import tempfile
10-
from unittest import skipIf
10+
try:
11+
from unittest import SkipTest, skipIf
12+
except ImportError:
13+
from unittest2 import SkipTest, skipIf
1114

1215
from git import (
1316
Blob,
@@ -131,7 +134,6 @@ def test_add_unicode(self, rw_repo):
131134
try:
132135
file_path.encode(sys.getfilesystemencoding())
133136
except UnicodeEncodeError:
134-
from unittest import SkipTest
135137
raise SkipTest("Environment doesn't support unicode filenames")
136138

137139
with open(file_path, "wb") as fp:

git/test/test_fun.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
from io import BytesIO
22
from stat import S_IFDIR, S_IFREG, S_IFLNK
3-
from unittest.case import skipIf
3+
try:
4+
from unittest import skipIf
5+
except ImportError:
6+
from unittest2 import skipIf
47

58
from git.compat import PY3
69
from git.index import IndexFile

git/test/test_index.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
)
1414
import sys
1515
import tempfile
16-
from unittest.case import skipIf
16+
try:
17+
from unittest import skipIf
18+
except ImportError:
19+
from unittest2 import skipIf
1720

1821
from git import (
1922
IndexFile,
@@ -149,8 +152,9 @@ def add_bad_blob():
149152
except Exception as ex:
150153
msg_py3 = "required argument is not an integer"
151154
msg_py2 = "cannot convert argument to integer"
152-
## msg_py26 ="unsupported operand type(s) for &: 'str' and 'long'"
153-
assert msg_py2 in str(ex) or msg_py3 in str(ex), str(ex)
155+
msg_py26 = "unsupported operand type(s) for &: 'str' and 'long'"
156+
assert msg_py2 in str(ex) or msg_py3 in str(ex) or \
157+
msg_py26 in str(ex), str(ex)
154158

155159
## 2nd time should not fail due to stray lock file
156160
try:

git/test/test_refs.py

+11
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,17 @@ def test_heads(self, rwrepo):
119119
assert head.tracking_branch() == remote_ref
120120
head.set_tracking_branch(None)
121121
assert head.tracking_branch() is None
122+
123+
special_name = 'feature#123'
124+
special_name_remote_ref = SymbolicReference.create(rwrepo, 'refs/remotes/origin/%s' % special_name)
125+
gp_tracking_branch = rwrepo.create_head('gp_tracking#123')
126+
special_name_remote_ref = rwrepo.remotes[0].refs[special_name] # get correct type
127+
gp_tracking_branch.set_tracking_branch(special_name_remote_ref)
128+
assert gp_tracking_branch.tracking_branch().path == special_name_remote_ref.path
129+
130+
git_tracking_branch = rwrepo.create_head('git_tracking#123')
131+
rwrepo.git.branch('-u', special_name_remote_ref.name, git_tracking_branch.name)
132+
assert git_tracking_branch.tracking_branch().name == special_name_remote_ref.name
122133
# END for each head
123134

124135
# verify REFLOG gets altered

git/test/test_remote.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66

77
import random
88
import tempfile
9-
from unittest.case import skipIf
9+
try:
10+
from unittest import skipIf
11+
except ImportError:
12+
from unittest2 import skipIf
1013

1114
from git import (
1215
RemoteProgress,

git/test/test_repo.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
import pickle
1212
import sys
1313
import tempfile
14-
from unittest.case import skipIf
14+
try:
15+
from unittest import skipIf, SkipTest
16+
except ImportError:
17+
from unittest2 import skipIf, SkipTest
1518

1619
from git import (
1720
InvalidGitRepositoryError,
@@ -53,7 +56,6 @@
5356
from git.util import HIDE_WINDOWS_KNOWN_ERRORS, cygpath
5457
from git.test.lib import with_rw_directory
5558
from git.util import join_path_native, rmtree, rmfile, bin_to_hex
56-
from unittest import SkipTest
5759

5860
import functools as fnt
5961
import os.path as osp

git/test/test_submodule.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
44
import os
55
import sys
6-
from unittest.case import skipIf
6+
try:
7+
from unittest import skipIf
8+
except ImportError:
9+
from unittest2 import skipIf
710

811
import git
912
from git.cmd import Git
@@ -29,12 +32,12 @@
2932

3033

3134
class TestRootProgress(RootUpdateProgress):
32-
3335
"""Just prints messages, for now without checking the correctness of the states"""
3436

3537
def update(self, op, cur_count, max_count, message=''):
3638
print(op, cur_count, max_count, message)
3739

40+
3841
prog = TestRootProgress()
3942

4043

git/test/test_tree.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66

77
from io import BytesIO
88
import sys
9-
from unittest.case import skipIf
9+
try:
10+
from unittest import skipIf
11+
except ImportError:
12+
from unittest2 import skipIf
1013

1114
from git import (
1215
Tree,

git/test/test_util.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66

77
import tempfile
88
import time
9-
from unittest.case import skipIf
9+
try:
10+
from unittest import skipIf
11+
except ImportError:
12+
from unittest2 import skipIf
13+
1014

1115
import ddt
1216

git/util.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,21 @@
33
#
44
# This module is part of GitPython and is released under
55
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
6-
from __future__ import unicode_literals
7-
86
import contextlib
97
from functools import wraps
108
import getpass
119
import logging
1210
import os
1311
import platform
12+
import subprocess
1413
import re
1514
import shutil
1615
import stat
1716
import time
18-
from unittest.case import SkipTest
17+
try:
18+
from unittest import SkipTest
19+
except ImportError:
20+
from unittest2 import SkipTest
1921

2022
from gitdb.util import (# NOQA @IgnorePep8
2123
make_sha,
@@ -303,7 +305,7 @@ def is_cygwin_git(git_executable):
303305
if not is_win:
304306
return False
305307

306-
from subprocess import check_output
308+
#from subprocess import check_output
307309

308310
is_cygwin = _is_cygwin_cache.get(git_executable)
309311
if is_cygwin is None:
@@ -316,8 +318,11 @@ def is_cygwin_git(git_executable):
316318

317319
## Just a name given, not a real path.
318320
uname_cmd = osp.join(git_dir, 'uname')
319-
uname = check_output(uname_cmd, universal_newlines=True)
320-
is_cygwin = 'CYGWIN' in uname
321+
process = subprocess.Popen([uname_cmd], stdout=subprocess.PIPE,
322+
universal_newlines=True)
323+
uname_out, _ = process.communicate()
324+
#retcode = process.poll()
325+
is_cygwin = 'CYGWIN' in uname_out
321326
except Exception as ex:
322327
log.debug('Failed checking if running in CYGWIN due to: %r', ex)
323328
_is_cygwin_cache[git_executable] = is_cygwin
@@ -940,6 +945,7 @@ class NullHandler(logging.Handler):
940945
def emit(self, record):
941946
pass
942947

948+
943949
# In Python 2.6, there is no NullHandler yet. Let's monkey-patch it for a workaround.
944950
if not hasattr(logging, 'NullHandler'):
945951
logging.NullHandler = NullHandler

0 commit comments

Comments
 (0)