Skip to content

Commit fd2c6da

Browse files
committed
Updates from review
1 parent e6108c7 commit fd2c6da

File tree

3 files changed

+16
-19
lines changed

3 files changed

+16
-19
lines changed

Diff for: git/cmd.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -488,12 +488,12 @@ def check_unsafe_options(cls, options: List[str], unsafe_options: List[str]) ->
488488
"""
489489
# Options can be of the form `foo` or `--foo bar` `--foo=bar`,
490490
# so we need to check if they start with "--foo" or if they are equal to "foo".
491-
bare_options = [
491+
bare_unsafe_options = [
492492
option.lstrip("-")
493493
for option in unsafe_options
494494
]
495495
for option in options:
496-
for unsafe_option, bare_option in zip(unsafe_options, bare_options):
496+
for unsafe_option, bare_option in zip(unsafe_options, bare_unsafe_options):
497497
if option.startswith(unsafe_option) or option == bare_option:
498498
raise UnsafeOptionError(
499499
f"{unsafe_option} is not allowed, use `allow_unsafe_options=True` to allow it."
@@ -1193,12 +1193,12 @@ def transform_kwargs(self, split_single_char_options: bool = True, **kwargs: Any
11931193
return args
11941194

11951195
@classmethod
1196-
def __unpack_args(cls, arg_list: Sequence[str]) -> List[str]:
1196+
def _unpack_args(cls, arg_list: Sequence[str]) -> List[str]:
11971197

11981198
outlist = []
11991199
if isinstance(arg_list, (list, tuple)):
12001200
for arg in arg_list:
1201-
outlist.extend(cls.__unpack_args(arg))
1201+
outlist.extend(cls._unpack_args(arg))
12021202
else:
12031203
outlist.append(str(arg_list))
12041204

@@ -1283,7 +1283,7 @@ def _call_process(
12831283
# Prepare the argument list
12841284

12851285
opt_args = self.transform_kwargs(**opts_kwargs)
1286-
ext_args = self.__unpack_args([a for a in args if a is not None])
1286+
ext_args = self._unpack_args([a for a in args if a is not None])
12871287

12881288
if insert_after_this_arg is None:
12891289
args_list = opt_args + ext_args

Diff for: git/remote.py

+9-12
Original file line numberDiff line numberDiff line change
@@ -1029,12 +1029,11 @@ def pull(
10291029
self._assert_refspec()
10301030
kwargs = add_progress(kwargs, self.repo.git, progress)
10311031

1032-
if not allow_unsafe_protocols and refspec:
1033-
if isinstance(refspec, str):
1034-
Git.check_unsafe_protocols(refspec)
1035-
else:
1036-
for ref in refspec:
1037-
Git.check_unsafe_protocols(ref)
1032+
refspec = Git._unpack_args(refspec or [])
1033+
if not allow_unsafe_protocols:
1034+
for ref in refspec:
1035+
Git.check_unsafe_protocols(ref)
1036+
10381037
if not allow_unsafe_options:
10391038
Git.check_unsafe_options(options=list(kwargs.keys()), unsafe_options=self.unsafe_git_pull_options)
10401039

@@ -1084,12 +1083,10 @@ def push(
10841083
be 0."""
10851084
kwargs = add_progress(kwargs, self.repo.git, progress)
10861085

1087-
if not allow_unsafe_protocols and refspec:
1088-
if isinstance(refspec, str):
1089-
Git.check_unsafe_protocols(refspec)
1090-
else:
1091-
for ref in refspec:
1092-
Git.check_unsafe_protocols(ref)
1086+
refspec = Git._unpack_args(refspec or [])
1087+
if not allow_unsafe_protocols:
1088+
for ref in refspec:
1089+
Git.check_unsafe_protocols(ref)
10931090

10941091
if not allow_unsafe_options:
10951092
Git.check_unsafe_options(options=list(kwargs.keys()), unsafe_options=self.unsafe_git_push_options)

Diff for: test/test_git.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ def test_call_process_calls_execute(self, git):
3939
self.assertEqual(git.call_args, ((["git", "version"],), {}))
4040

4141
def test_call_unpack_args_unicode(self):
42-
args = Git._Git__unpack_args("Unicode€™")
42+
args = Git._unpack_args("Unicode€™")
4343
mangled_value = "Unicode\u20ac\u2122"
4444
self.assertEqual(args, [mangled_value])
4545

4646
def test_call_unpack_args(self):
47-
args = Git._Git__unpack_args(["git", "log", "--", "Unicode€™"])
47+
args = Git._unpack_args(["git", "log", "--", "Unicode€™"])
4848
mangled_value = "Unicode\u20ac\u2122"
4949
self.assertEqual(args, ["git", "log", "--", mangled_value])
5050

0 commit comments

Comments
 (0)