Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion git/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,10 @@ def _canonicalize_option_name(cls, option: str) -> str:
option_tokens = option_name.split(None, 1)
if not option_tokens:
return ""
return dashify(option_tokens[0])
option_token = option_tokens[0]
if option.startswith("-") and not option.startswith("--") and len(option_token) > 1:
option_token = option_token[:1]
return dashify(option_token)

@classmethod
def check_unsafe_options(cls, options: List[str], unsafe_options: List[str]) -> None:
Expand Down
4 changes: 4 additions & 0 deletions test/test_clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,10 @@ def test_clone_unsafe_options(self, rw_repo):
unsafe_options = [
f"--upload-pack='touch {tmp_file}'",
f"-u 'touch {tmp_file}'",
f"-u{tmp_file}",
"--config=protocol.ext.allow=always",
"-c protocol.ext.allow=always",
"-cprotocol.ext.allow=always",
]
for unsafe_option in unsafe_options:
with self.assertRaises(UnsafeOptionError):
Expand Down Expand Up @@ -207,8 +209,10 @@ def test_clone_from_unsafe_options(self, rw_repo):
unsafe_options = [
f"--upload-pack='touch {tmp_file}'",
f"-u 'touch {tmp_file}'",
f"-u{tmp_file}",
"--config=protocol.ext.allow=always",
"-c protocol.ext.allow=always",
"-cprotocol.ext.allow=always",
]
for unsafe_option in unsafe_options:
with self.assertRaises(UnsafeOptionError):
Expand Down
2 changes: 2 additions & 0 deletions test/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ def test_check_unsafe_options_normalizes_kwargs(self):
(["exec"], ["--exec"]),
(["u"], ["-u"]),
(["c"], ["-c"]),
(["-u/tmp/helper"], ["-u"]),
(["-cprotocol.ext.allow=always"], ["-c"]),
(["--upload-pack=/tmp/helper"], ["--upload-pack"]),
(["--config core.filemode=false"], ["--config"]),
]
Expand Down
Loading