Skip to content

Commit 5c11ece

Browse files
committed
test using pygit2 for branch creation instead of subprocess call, but fails because of surrogates not allowed
1 parent af8e73d commit 5c11ece

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

pygit2/utils.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ def maybe_string(ptr):
3434
if not ptr:
3535
return None
3636

37-
return ffi.string(ptr).decode("utf8", errors="surrogateescape")
37+
return ffi.string(ptr).decode('utf8', errors='surrogateescape')
3838

3939

40-
def to_bytes(s, encoding="utf-8", errors="strict"):
40+
def to_bytes(s, encoding='utf-8', errors='strict'):
4141
if s == ffi.NULL or s is None:
4242
return ffi.NULL
4343

44-
if hasattr(s, "__fspath__"):
44+
if hasattr(s, '__fspath__'):
4545
s = os.fspath(s)
4646

4747
if isinstance(s, bytes):
@@ -51,7 +51,7 @@ def to_bytes(s, encoding="utf-8", errors="strict"):
5151

5252

5353
def to_str(s):
54-
if hasattr(s, "__fspath__"):
54+
if hasattr(s, '__fspath__'):
5555
s = os.fspath(s)
5656

5757
if type(s) is str:
@@ -69,13 +69,13 @@ def ptr_to_bytes(ptr_cdata):
6969
to a byte buffer containing the address that the pointer refers to.
7070
"""
7171

72-
pp = ffi.new("void **", ptr_cdata)
72+
pp = ffi.new('void **', ptr_cdata)
7373
return bytes(ffi.buffer(pp)[:])
7474

7575

7676
@contextlib.contextmanager
7777
def new_git_strarray():
78-
strarray = ffi.new("git_strarray *")
78+
strarray = ffi.new('git_strarray *')
7979
yield strarray
8080
C.git_strarray_dispose(strarray)
8181

@@ -88,7 +88,7 @@ def strarray_to_strings(arr):
8888
calling this function.
8989
"""
9090
try:
91-
return [ffi.string(arr.strings[i]).decode("utf-8") for i in range(arr.count)]
91+
return [ffi.string(arr.strings[i]).decode('utf-8') for i in range(arr.count)]
9292
finally:
9393
C.git_strarray_dispose(arr)
9494

@@ -120,19 +120,19 @@ def __init__(self, l):
120120
return
121121

122122
if not isinstance(l, (list, tuple)):
123-
raise TypeError("Value must be a list")
123+
raise TypeError('Value must be a list')
124124

125125
strings = [None] * len(l)
126126
for i in range(len(l)):
127127
li = l[i]
128-
if not isinstance(li, str) and not hasattr(li, "__fspath__"):
129-
raise TypeError("Value must be a string or PathLike object")
128+
if not isinstance(li, str) and not hasattr(li, '__fspath__'):
129+
raise TypeError('Value must be a string or PathLike object')
130130

131-
strings[i] = ffi.new("char []", to_bytes(li))
131+
strings[i] = ffi.new('char []', to_bytes(li))
132132

133-
self.__arr = ffi.new("char *[]", strings)
133+
self.__arr = ffi.new('char *[]', strings)
134134
self.__strings = strings
135-
self.__array = ffi.new("git_strarray *", [self.__arr, len(strings)])
135+
self.__array = ffi.new('git_strarray *', [self.__arr, len(strings)])
136136

137137
def __enter__(self):
138138
return self

test/test_nonunicode.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ def bstring(request):
4141

4242

4343
def test_nonunicode_branchname(testrepo, bstring):
44-
cmd = b"git checkout -b " + bstring
45-
subprocess.check_output(cmd.split(b" "), cwd=testrepo.workdir)
44+
testrepo.branches.local.create(bstring.decode("utf8", errors="surrogateescape"),commit=testrepo.head.target)
4645
newrepo = pygit2.clone_repository(
4746
testrepo.workdir,
4847
os.path.join(os.path.dirname(testrepo.workdir), "test_nonunicode_repo"),

0 commit comments

Comments
 (0)