Skip to content

Commit 8868028

Browse files
committed
git.credentials: in/out protocol uses newlines and not os linesep
1 parent 150ca52 commit 8868028

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

src/scmrepo/git/credentials.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def get(self, credential: "Credential", **kwargs) -> "Credential":
164164
cmd,
165165
check=True,
166166
capture_output=True,
167-
input=os.linesep.join(helper_input),
167+
input="\n".join(helper_input),
168168
encoding=self._encoding,
169169
**self._run_kwargs,
170170
)
@@ -204,7 +204,7 @@ def store(self, credential: "Credential", **kwargs):
204204
res = subprocess.run( # type: ignore # nosec B603 # pylint: disable=W1510
205205
cmd,
206206
capture_output=True,
207-
input=os.linesep.join(helper_input),
207+
input="\n".join(helper_input),
208208
encoding=self._encoding,
209209
**self._run_kwargs,
210210
)
@@ -228,7 +228,7 @@ def erase(self, credential: "Credential", **kwargs):
228228
res = subprocess.run( # type: ignore # nosec B603 # pylint: disable=W1510
229229
cmd,
230230
capture_output=True,
231-
input=os.linesep.join(helper_input),
231+
input="\n".join(helper_input),
232232
encoding=self._encoding,
233233
**self._run_kwargs,
234234
)

tests/test_credentials.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ def test_subprocess_get(git_helper, mocker):
2121
run = mocker.patch(
2222
"subprocess.run",
2323
return_value=mocker.Mock(
24-
stdout=os.linesep.join(
24+
stdout="\n".join(
2525
["protocol=https", "host=foo.com", "username=foo", "password=bar", ""]
2626
)
2727
),
2828
)
2929
creds = git_helper.get(Credential(protocol="https", host="foo.com", path="foo.git"))
3030
assert run.call_args.args[0] == ["git-credential-foo", "get"]
31-
assert run.call_args.kwargs.get("input") == os.linesep.join(
31+
assert run.call_args.kwargs.get("input") == "\n".join(
3232
["protocol=https", "host=foo.com", ""]
3333
)
3434
assert creds == Credential(url="https://foo:bar@foo.com")
@@ -39,12 +39,12 @@ def test_subprocess_get_use_http_path(git_helper, mocker):
3939
run = mocker.patch(
4040
"subprocess.run",
4141
return_value=mocker.Mock(
42-
stdout=os.linesep.join(["username=foo", "password=bar", ""])
42+
stdout="\n".join(["username=foo", "password=bar", ""])
4343
),
4444
)
4545
creds = git_helper.get(Credential(protocol="https", host="foo.com", path="foo.git"))
4646
assert run.call_args.args[0] == ["git-credential-foo", "get"]
47-
assert run.call_args.kwargs.get("input") == os.linesep.join(
47+
assert run.call_args.kwargs.get("input") == "\n".join(
4848
["protocol=https", "host=foo.com", "path=foo.git", ""]
4949
)
5050
assert creds == Credential(username="foo", password="bar")
@@ -59,7 +59,7 @@ def test_subprocess_get_failed(git_helper, mocker):
5959

6060

6161
def test_subprocess_get_no_output(git_helper, mocker):
62-
mocker.patch("subprocess.run", return_value=mocker.Mock(stdout=os.linesep))
62+
mocker.patch("subprocess.run", return_value=mocker.Mock(stdout="\n"))
6363
with pytest.raises(CredentialNotFoundError):
6464
git_helper.get(Credential(protocol="https", host="foo.com"))
6565

@@ -70,7 +70,7 @@ def test_subprocess_store(git_helper, mocker):
7070
Credential(protocol="https", host="foo.com", username="foo", password="bar")
7171
)
7272
assert run.call_args.args[0] == ["git-credential-foo", "store"]
73-
assert run.call_args.kwargs.get("input") == os.linesep.join(
73+
assert run.call_args.kwargs.get("input") == "\n".join(
7474
["protocol=https", "host=foo.com", "username=foo", "password=bar", ""]
7575
)
7676

@@ -79,7 +79,7 @@ def test_subprocess_erase(git_helper, mocker):
7979
run = mocker.patch("subprocess.run")
8080
git_helper.erase(Credential(protocol="https", host="foo.com"))
8181
assert run.call_args.args[0] == ["git-credential-foo", "erase"]
82-
assert run.call_args.kwargs.get("input") == os.linesep.join(
82+
assert run.call_args.kwargs.get("input") == "\n".join(
8383
["protocol=https", "host=foo.com", ""]
8484
)
8585

@@ -149,7 +149,7 @@ def test_memory_helper_prompt_askpass(mocker):
149149
"subprocess.run",
150150
side_effect=[
151151
mocker.Mock(stdout="foo"),
152-
mocker.Mock(stdout=os.linesep.join(["bar", ""])),
152+
mocker.Mock(stdout="\n".join(["bar", ""])),
153153
],
154154
)
155155
expected = Credential(

0 commit comments

Comments
 (0)