From e3f38ffe1c3e37ec5a8f18d60961ddd0cd0f62f4 Mon Sep 17 00:00:00 2001
From: George Ogden <george-ogden@outlook.com>
Date: Thu, 27 Nov 2025 17:32:48 +0000
Subject: [PATCH] Move clone tests into dedicated file

---
 test/test_clone.py | 294 ++++++++++++++++++++++++++++++++++++++++++++-
 test/test_repo.py  | 283 +------------------------------------------
 2 files changed, 294 insertions(+), 283 deletions(-)

Index: GitPython-3.1.34.1693646983.2a2ae77/test/test_clone.py
===================================================================
--- GitPython-3.1.34.1693646983.2a2ae77.orig/test/test_clone.py
+++ GitPython-3.1.34.1693646983.2a2ae77/test/test_clone.py
@@ -2,17 +2,24 @@
 # This module is part of GitPython and is released under
 # the BSD License: http://www.opensource.org/licenses/bsd-license.php
 
+import os
+import os.path as osp
+import pathlib
+import sys
+import tempfile
+from unittest import skip
+
+from git import GitCommandError, Repo
+from git.exc import UnsafeOptionError, UnsafeProtocolError
+
+from test.lib import TestBase, with_rw_directory, with_rw_repo
+
 from pathlib import Path
 import re
 
 import git
 
-from .lib import (
-    TestBase,
-    with_rw_directory,
-    with_rw_repo,
-)
-
+import pytest
 
 class TestClone(TestBase):
     @with_rw_directory
@@ -35,6 +42,128 @@ class TestClone(TestBase):
         else:
             self.fail("GitCommandError not raised")
 
+
+    @with_rw_directory
+    def test_clone_from_pathlib(self, rw_dir):
+        original_repo = Repo.init(osp.join(rw_dir, "repo"))
+
+        Repo.clone_from(original_repo.git_dir, pathlib.Path(rw_dir) / "clone_pathlib")
+
+    @with_rw_directory
+    def test_clone_from_pathlib_withConfig(self, rw_dir):
+        original_repo = Repo.init(osp.join(rw_dir, "repo"))
+
+        cloned = Repo.clone_from(
+            original_repo.git_dir,
+            pathlib.Path(rw_dir) / "clone_pathlib_withConfig",
+            multi_options=[
+                "--recurse-submodules=repo",
+                "--config core.filemode=false",
+                "--config submodule.repo.update=checkout",
+                "--config filter.lfs.clean='git-lfs clean -- %f'",
+            ],
+            allow_unsafe_options=True,
+        )
+
+        self.assertEqual(cloned.config_reader().get_value("submodule", "active"), "repo")
+        self.assertEqual(cloned.config_reader().get_value("core", "filemode"), False)
+        self.assertEqual(cloned.config_reader().get_value('submodule "repo"', "update"), "checkout")
+        self.assertEqual(
+            cloned.config_reader().get_value('filter "lfs"', "clean"),
+            "git-lfs clean -- %f",
+        )
+
+    def test_clone_from_with_path_contains_unicode(self):
+        with tempfile.TemporaryDirectory() as tmpdir:
+            unicode_dir_name = "\u0394"
+            path_with_unicode = os.path.join(tmpdir, unicode_dir_name)
+            os.makedirs(path_with_unicode)
+
+            try:
+                Repo.clone_from(
+                    url=self._small_repo_url(),
+                    to_path=path_with_unicode,
+                )
+            except UnicodeEncodeError:
+                self.fail("Raised UnicodeEncodeError")
+
+    @with_rw_directory
+    @skip(
+        """The referenced repository was removed, and one needs to set up a new
+        password controlled repo under the org's control."""
+    )
+    def test_leaking_password_in_clone_logs(self, rw_dir):
+        password = "fakepassword1234"
+        try:
+            Repo.clone_from(
+                url="https://fakeuser:{}@fakerepo.example.com/testrepo".format(password),
+                to_path=rw_dir,
+            )
+        except GitCommandError as err:
+            assert password not in str(err), "The error message '%s' should not contain the password" % err
+        # Working example from a blank private project.
+        Repo.clone_from(
+            url="https://gitlab+deploy-token-392045:mLWhVus7bjLsy8xj8q2V@gitlab.com/mercierm/test_git_python",
+            to_path=rw_dir,
+        )
+
+    @with_rw_repo("HEAD")
+    def test_clone_unsafe_options(self, rw_repo):
+        with tempfile.TemporaryDirectory() as tdir:
+            tmp_dir = pathlib.Path(tdir)
+            tmp_file = tmp_dir / "pwn"
+            unsafe_options = [
+                f"--upload-pack='touch {tmp_file}'",
+                f"-u 'touch {tmp_file}'",
+                f"-utouch {tmp_file}; false",
+                f"-futouch${{IFS}}{tmp_file}; false",
+                f"-qutouch${{IFS}}{tmp_file}; false",
+                "--config=protocol.ext.allow=always",
+                "-c protocol.ext.allow=always",
+                "-cprotocol.ext.allow=always",
+                "-vcprotocol.ext.allow=always",
+            ]
+            for unsafe_option in unsafe_options:
+                with self.assertRaises(UnsafeOptionError):
+                    rw_repo.clone(tmp_dir, multi_options=[unsafe_option])
+                assert not tmp_file.exists()
+
+            unsafe_options = [
+                {"upload-pack": f"touch {tmp_file}"},
+                {"u": f"touch {tmp_file}"},
+                {"config": "protocol.ext.allow=always"},
+                {"c": "protocol.ext.allow=always"},
+            ]
+            for unsafe_option in unsafe_options:
+                with self.assertRaises(UnsafeOptionError):
+                    rw_repo.clone(tmp_dir, **unsafe_option)
+                assert not tmp_file.exists()
+
+    @with_rw_repo("HEAD")
+    def test_clone_unsafe_options_abbreviated(self, rw_repo):
+        with tempfile.TemporaryDirectory() as tdir:
+            tmp_dir = pathlib.Path(tdir)
+            tmp_file = tmp_dir / "pwn"
+            unsafe_options = [
+                f"--upl='touch {tmp_file}'",
+                f"--upload-pac='touch {tmp_file}'",
+                "--conf=protocol.ext.allow=always",
+            ]
+            for unsafe_option in unsafe_options:
+                with self.assertRaises(UnsafeOptionError):
+                    rw_repo.clone(tmp_dir, multi_options=[unsafe_option])
+                assert not tmp_file.exists()
+
+            unsafe_kwargs = [
+                {"upl": f"touch {tmp_file}"},
+                {"upload_pac": f"touch {tmp_file}"},
+                {"conf": "protocol.ext.allow=always"},
+            ]
+            for unsafe_option in unsafe_kwargs:
+                with self.assertRaises(UnsafeOptionError):
+                    rw_repo.clone(tmp_dir, **unsafe_option)
+                assert not tmp_file.exists()
+
     @with_rw_repo("HEAD")
     def test_clone_unsafe_options_are_checked_after_splitting_multi_options(self, rw_repo):
         with tempfile.TemporaryDirectory() as tdir:
@@ -44,6 +173,92 @@ class TestClone(TestBase):
             with self.assertRaises(UnsafeOptionError):
                 rw_repo.clone(tmp_dir, multi_options=[payload])
 
+    @pytest.mark.xfail(
+        sys.platform == "win32",
+        reason=(
+            "File not created. A separate Windows command may be needed. This and the "
+            "currently passing test test_clone_unsafe_options must be adjusted in the "
+            "same way. Until then, test_clone_unsafe_options is unreliable on Windows."
+        ),
+        raises=AssertionError,
+    )
+    @with_rw_repo("HEAD")
+    def test_clone_unsafe_options_allowed(self, rw_repo):
+        with tempfile.TemporaryDirectory() as tdir:
+            tmp_dir = pathlib.Path(tdir)
+            tmp_file = tmp_dir / "pwn"
+            unsafe_options = [
+                f"--upload-pack='touch {tmp_file}'",
+                f"-u 'touch {tmp_file}'",
+            ]
+            for i, unsafe_option in enumerate(unsafe_options):
+                destination = tmp_dir / str(i)
+                assert not tmp_file.exists()
+                # The options will be allowed, but the command will fail.
+                with self.assertRaises(GitCommandError):
+                    rw_repo.clone(destination, multi_options=[unsafe_option], allow_unsafe_options=True)
+                assert tmp_file.exists()
+                tmp_file.unlink()
+
+            unsafe_options = [
+                "--config=protocol.ext.allow=always",
+                "-c protocol.ext.allow=always",
+            ]
+            for i, unsafe_option in enumerate(unsafe_options):
+                destination = tmp_dir / str(i)
+                assert not destination.exists()
+                rw_repo.clone(destination, multi_options=[unsafe_option], allow_unsafe_options=True)
+                assert destination.exists()
+
+    @with_rw_repo("HEAD")
+    def test_clone_safe_options(self, rw_repo):
+        with tempfile.TemporaryDirectory() as tdir:
+            tmp_dir = pathlib.Path(tdir)
+            options = [
+                "--depth=1",
+                "--single-branch",
+                "--origin upload",
+                "-q",
+                "-oupstream",
+            ]
+            for option in options:
+                destination = tmp_dir / option
+                assert not destination.exists()
+                rw_repo.clone(destination, multi_options=[option])
+                assert destination.exists()
+
+    @with_rw_repo("HEAD")
+    def test_clone_from_unsafe_options(self, rw_repo):
+        with tempfile.TemporaryDirectory() as tdir:
+            tmp_dir = pathlib.Path(tdir)
+            tmp_file = tmp_dir / "pwn"
+            unsafe_options = [
+                f"--upload-pack='touch {tmp_file}'",
+                f"-u 'touch {tmp_file}'",
+                f"-utouch {tmp_file}; false",
+                f"-futouch${{IFS}}{tmp_file}; false",
+                f"-qutouch${{IFS}}{tmp_file}; false",
+                "--config=protocol.ext.allow=always",
+                "-c protocol.ext.allow=always",
+                "-cprotocol.ext.allow=always",
+                "-vcprotocol.ext.allow=always",
+            ]
+            for unsafe_option in unsafe_options:
+                with self.assertRaises(UnsafeOptionError):
+                    Repo.clone_from(rw_repo.working_dir, tmp_dir, multi_options=[unsafe_option])
+                assert not tmp_file.exists()
+
+            unsafe_options = [
+                {"upload-pack": f"touch {tmp_file}"},
+                {"u": f"touch {tmp_file}"},
+                {"config": "protocol.ext.allow=always"},
+                {"c": "protocol.ext.allow=always"},
+            ]
+            for unsafe_option in unsafe_options:
+                with self.assertRaises(UnsafeOptionError):
+                    Repo.clone_from(rw_repo.working_dir, tmp_dir, **unsafe_option)
+                assert not tmp_file.exists()
+
     @with_rw_repo("HEAD")
     def test_clone_from_unsafe_options_are_checked_after_splitting_multi_options(self, rw_repo):
         with tempfile.TemporaryDirectory() as tdir:
@@ -53,3 +268,112 @@ class TestClone(TestBase):
             with self.assertRaises(UnsafeOptionError):
                 Repo.clone_from(rw_repo.working_dir, tmp_dir, multi_options=[payload])
 
+    @pytest.mark.xfail(
+        sys.platform == "win32",
+        reason=(
+            "File not created. A separate Windows command may be needed. This and the "
+            "currently passing test test_clone_from_unsafe_options must be adjusted in the "
+            "same way. Until then, test_clone_from_unsafe_options is unreliable on Windows."
+        ),
+        raises=AssertionError,
+    )
+    @with_rw_repo("HEAD")
+    def test_clone_from_unsafe_options_allowed(self, rw_repo):
+        with tempfile.TemporaryDirectory() as tdir:
+            tmp_dir = pathlib.Path(tdir)
+            tmp_file = tmp_dir / "pwn"
+            unsafe_options = [
+                f"--upload-pack='touch {tmp_file}'",
+                f"-u 'touch {tmp_file}'",
+            ]
+            for i, unsafe_option in enumerate(unsafe_options):
+                destination = tmp_dir / str(i)
+                assert not tmp_file.exists()
+                # The options will be allowed, but the command will fail.
+                with self.assertRaises(GitCommandError):
+                    Repo.clone_from(
+                        rw_repo.working_dir, destination, multi_options=[unsafe_option], allow_unsafe_options=True
+                    )
+                assert tmp_file.exists()
+                tmp_file.unlink()
+
+            unsafe_options = [
+                "--config=protocol.ext.allow=always",
+                "-c protocol.ext.allow=always",
+            ]
+            for i, unsafe_option in enumerate(unsafe_options):
+                destination = tmp_dir / str(i)
+                assert not destination.exists()
+                Repo.clone_from(
+                    rw_repo.working_dir, destination, multi_options=[unsafe_option], allow_unsafe_options=True
+                )
+                assert destination.exists()
+
+    @with_rw_repo("HEAD")
+    def test_clone_from_safe_options(self, rw_repo):
+        with tempfile.TemporaryDirectory() as tdir:
+            tmp_dir = pathlib.Path(tdir)
+            options = [
+                "--depth=1",
+                "--single-branch",
+                "-q",
+            ]
+            for option in options:
+                destination = tmp_dir / option
+                assert not destination.exists()
+                Repo.clone_from(rw_repo.common_dir, destination, multi_options=[option])
+                assert destination.exists()
+
+    def test_clone_from_unsafe_protocol(self):
+        with tempfile.TemporaryDirectory() as tdir:
+            tmp_dir = pathlib.Path(tdir)
+            tmp_file = tmp_dir / "pwn"
+            urls = [
+                f"ext::sh -c touch% {tmp_file}",
+                "fd::17/foo",
+            ]
+            for url in urls:
+                with self.assertRaises(UnsafeProtocolError):
+                    Repo.clone_from(url, tmp_dir / "repo")
+                assert not tmp_file.exists()
+
+    def test_clone_from_unsafe_protocol_allowed(self):
+        with tempfile.TemporaryDirectory() as tdir:
+            tmp_dir = pathlib.Path(tdir)
+            tmp_file = tmp_dir / "pwn"
+            urls = [
+                f"ext::sh -c touch% {tmp_file}",
+                "fd::/foo",
+            ]
+            for url in urls:
+                # The URL will be allowed into the command, but the command will
+                # fail since we don't have that protocol enabled in the Git config file.
+                with self.assertRaises(GitCommandError):
+                    Repo.clone_from(url, tmp_dir / "repo", allow_unsafe_protocols=True)
+                assert not tmp_file.exists()
+
+    def test_clone_from_unsafe_protocol_allowed_and_enabled(self):
+        with tempfile.TemporaryDirectory() as tdir:
+            tmp_dir = pathlib.Path(tdir)
+            tmp_file = tmp_dir / "pwn"
+            urls = [
+                f"ext::sh -c touch% {tmp_file}",
+            ]
+            allow_ext = [
+                "--config=protocol.ext.allow=always",
+            ]
+            for url in urls:
+                # The URL will be allowed into the command, and the protocol is enabled,
+                # but the command will fail since it can't read from the remote repo.
+                assert not tmp_file.exists()
+                with self.assertRaises(GitCommandError):
+                    Repo.clone_from(
+                        url,
+                        tmp_dir / "repo",
+                        multi_options=allow_ext,
+                        allow_unsafe_protocols=True,
+                        allow_unsafe_options=True,
+                    )
+                assert tmp_file.exists()
+                tmp_file.unlink()
+
Index: GitPython-3.1.34.1693646983.2a2ae77/test/test_repo.py
===================================================================
--- GitPython-3.1.34.1693646983.2a2ae77.orig/test/test_repo.py
+++ GitPython-3.1.34.1693646983.2a2ae77/test/test_repo.py
@@ -13,7 +13,7 @@ import pathlib
 import pickle
 import sys
 import tempfile
-from unittest import mock, skipIf, SkipTest, skip
+from unittest import mock, skipIf, SkipTest
 
 import pytest
 
@@ -35,11 +35,7 @@ from git import (
     BadName,
     GitCommandError,
 )
-from git.exc import (
-    BadObject,
-    UnsafeOptionError,
-    UnsafeProtocolError,
-)
+from git.exc import BadObject
 from git.repo.fun import touch
 from test.lib import TestBase, with_rw_repo, fixture
 from git.util import HIDE_WINDOWS_KNOWN_ERRORS, cygpath
@@ -206,263 +202,6 @@ class TestRepo(TestBase):
         # @-timestamp is the format used by git commit hooks
         repo.index.commit("Commit messages", commit_date="@1400000000 +0000")
 
-    @with_rw_directory
-    def test_clone_from_pathlib(self, rw_dir):
-        original_repo = Repo.init(osp.join(rw_dir, "repo"))
-
-        Repo.clone_from(original_repo.git_dir, pathlib.Path(rw_dir) / "clone_pathlib")
-
-    @with_rw_directory
-    def test_clone_from_pathlib_withConfig(self, rw_dir):
-        original_repo = Repo.init(osp.join(rw_dir, "repo"))
-
-        cloned = Repo.clone_from(
-            original_repo.git_dir,
-            pathlib.Path(rw_dir) / "clone_pathlib_withConfig",
-            multi_options=[
-                "--recurse-submodules=repo",
-                "--config core.filemode=false",
-                "--config submodule.repo.update=checkout",
-                "--config filter.lfs.clean='git-lfs clean -- %f'",
-            ],
-            allow_unsafe_options=True,
-        )
-
-        self.assertEqual(cloned.config_reader().get_value("submodule", "active"), "repo")
-        self.assertEqual(cloned.config_reader().get_value("core", "filemode"), False)
-        self.assertEqual(cloned.config_reader().get_value('submodule "repo"', "update"), "checkout")
-        self.assertEqual(
-            cloned.config_reader().get_value('filter "lfs"', "clean"),
-            "git-lfs clean -- %f",
-        )
-
-    def test_clone_from_with_path_contains_unicode(self):
-        with tempfile.TemporaryDirectory() as tmpdir:
-            unicode_dir_name = "\u0394"
-            path_with_unicode = os.path.join(tmpdir, unicode_dir_name)
-            os.makedirs(path_with_unicode)
-
-            try:
-                Repo.clone_from(
-                    url=self._small_repo_url(),
-                    to_path=path_with_unicode,
-                )
-            except UnicodeEncodeError:
-                self.fail("Raised UnicodeEncodeError")
-
-    @skipIf(os.environ.get('SKIP_GITHUB', 'false') == 'true', 'Gitlab connection error')
-    @with_rw_directory
-    @skip("the referenced repository was removed, and one needs to setup a new password controlled repo under the orgs control")
-    def test_leaking_password_in_clone_logs(self, rw_dir):
-        password = "fakepassword1234"
-        try:
-            Repo.clone_from(
-                url="https://fakeuser:{}@fakerepo.example.com/testrepo".format(password),
-                to_path=rw_dir,
-            )
-        except GitCommandError as err:
-            assert password not in str(err), "The error message '%s' should not contain the password" % err
-        # Working example from a blank private project
-        Repo.clone_from(
-            url="https://gitlab+deploy-token-392045:mLWhVus7bjLsy8xj8q2V@gitlab.com/mercierm/test_git_python",
-            to_path=rw_dir,
-        )
-
-    @with_rw_repo("HEAD")
-    def test_clone_unsafe_options(self, rw_repo):
-        with tempfile.TemporaryDirectory() as tdir:
-            tmp_dir = pathlib.Path(tdir)
-            tmp_file = tmp_dir / "pwn"
-            unsafe_options = [
-                f"--upload-pack='touch {tmp_file}'",
-                f"-u 'touch {tmp_file}'",
-                "--config=protocol.ext.allow=always",
-                "-c protocol.ext.allow=always",
-            ]
-            for unsafe_option in unsafe_options:
-                with self.assertRaises(UnsafeOptionError):
-                    rw_repo.clone(tmp_dir, multi_options=[unsafe_option])
-                assert not tmp_file.exists()
-
-            unsafe_options = [
-                {"upload-pack": f"touch {tmp_file}"},
-                {"u": f"touch {tmp_file}"},
-                {"config": "protocol.ext.allow=always"},
-                {"c": "protocol.ext.allow=always"},
-            ]
-            for unsafe_option in unsafe_options:
-                with self.assertRaises(UnsafeOptionError):
-                    rw_repo.clone(tmp_dir, **unsafe_option)
-                assert not tmp_file.exists()
-
-    @with_rw_repo("HEAD")
-    def test_clone_unsafe_options_allowed(self, rw_repo):
-        with tempfile.TemporaryDirectory() as tdir:
-            tmp_dir = pathlib.Path(tdir)
-            tmp_file = tmp_dir / "pwn"
-            unsafe_options = [
-                f"--upload-pack='touch {tmp_file}'",
-                f"-u 'touch {tmp_file}'",
-            ]
-            for i, unsafe_option in enumerate(unsafe_options):
-                destination = tmp_dir / str(i)
-                assert not tmp_file.exists()
-                # The options will be allowed, but the command will fail.
-                with self.assertRaises(GitCommandError):
-                    rw_repo.clone(destination, multi_options=[unsafe_option], allow_unsafe_options=True)
-                assert tmp_file.exists()
-                tmp_file.unlink()
-
-            unsafe_options = [
-                "--config=protocol.ext.allow=always",
-                "-c protocol.ext.allow=always",
-            ]
-            for i, unsafe_option in enumerate(unsafe_options):
-                destination = tmp_dir / str(i)
-                assert not destination.exists()
-                rw_repo.clone(destination, multi_options=[unsafe_option], allow_unsafe_options=True)
-                assert destination.exists()
-
-    @with_rw_repo("HEAD")
-    def test_clone_safe_options(self, rw_repo):
-        with tempfile.TemporaryDirectory() as tdir:
-            tmp_dir = pathlib.Path(tdir)
-            options = [
-                "--depth=1",
-                "--single-branch",
-                "-q",
-            ]
-            for option in options:
-                destination = tmp_dir / option
-                assert not destination.exists()
-                rw_repo.clone(destination, multi_options=[option])
-                assert destination.exists()
-
-    @with_rw_repo("HEAD")
-    def test_clone_from_unsafe_options(self, rw_repo):
-        with tempfile.TemporaryDirectory() as tdir:
-            tmp_dir = pathlib.Path(tdir)
-            tmp_file = tmp_dir / "pwn"
-            unsafe_options = [
-                f"--upload-pack='touch {tmp_file}'",
-                f"-u 'touch {tmp_file}'",
-                "--config=protocol.ext.allow=always",
-                "-c protocol.ext.allow=always",
-            ]
-            for unsafe_option in unsafe_options:
-                with self.assertRaises(UnsafeOptionError):
-                    Repo.clone_from(rw_repo.working_dir, tmp_dir, multi_options=[unsafe_option])
-                assert not tmp_file.exists()
-
-            unsafe_options = [
-                {"upload-pack": f"touch {tmp_file}"},
-                {"u": f"touch {tmp_file}"},
-                {"config": "protocol.ext.allow=always"},
-                {"c": "protocol.ext.allow=always"},
-            ]
-            for unsafe_option in unsafe_options:
-                with self.assertRaises(UnsafeOptionError):
-                    Repo.clone_from(rw_repo.working_dir, tmp_dir, **unsafe_option)
-                assert not tmp_file.exists()
-
-    @with_rw_repo("HEAD")
-    def test_clone_from_unsafe_options_allowed(self, rw_repo):
-        with tempfile.TemporaryDirectory() as tdir:
-            tmp_dir = pathlib.Path(tdir)
-            tmp_file = tmp_dir / "pwn"
-            unsafe_options = [
-                f"--upload-pack='touch {tmp_file}'",
-                f"-u 'touch {tmp_file}'",
-            ]
-            for i, unsafe_option in enumerate(unsafe_options):
-                destination = tmp_dir / str(i)
-                assert not tmp_file.exists()
-                # The options will be allowed, but the command will fail.
-                with self.assertRaises(GitCommandError):
-                    Repo.clone_from(
-                        rw_repo.working_dir, destination, multi_options=[unsafe_option], allow_unsafe_options=True
-                    )
-                assert tmp_file.exists()
-                tmp_file.unlink()
-
-            unsafe_options = [
-                "--config=protocol.ext.allow=always",
-                "-c protocol.ext.allow=always",
-            ]
-            for i, unsafe_option in enumerate(unsafe_options):
-                destination = tmp_dir / str(i)
-                assert not destination.exists()
-                Repo.clone_from(rw_repo.working_dir, destination, multi_options=[unsafe_option], allow_unsafe_options=True)
-                assert destination.exists()
-
-    @with_rw_repo("HEAD")
-    def test_clone_from_safe_options(self, rw_repo):
-        with tempfile.TemporaryDirectory() as tdir:
-            tmp_dir = pathlib.Path(tdir)
-            options = [
-                "--depth=1",
-                "--single-branch",
-                "-q",
-            ]
-            for option in options:
-                destination = tmp_dir / option
-                assert not destination.exists()
-                Repo.clone_from(rw_repo.common_dir, destination, multi_options=[option])
-                assert destination.exists()
-
-    def test_clone_from_unsafe_protocol(self):
-        with tempfile.TemporaryDirectory() as tdir:
-            tmp_dir = pathlib.Path(tdir)
-            tmp_file = tmp_dir / "pwn"
-            urls = [
-                f"ext::sh -c touch% {tmp_file}",
-                "fd::17/foo",
-            ]
-            for url in urls:
-                with self.assertRaises(UnsafeProtocolError):
-                    Repo.clone_from(url, tmp_dir / "repo")
-                assert not tmp_file.exists()
-
-    def test_clone_from_unsafe_protocol_allowed(self):
-        with tempfile.TemporaryDirectory() as tdir:
-            tmp_dir = pathlib.Path(tdir)
-            tmp_file = tmp_dir / "pwn"
-            urls = [
-                f"ext::sh -c touch% {tmp_file}",
-                "fd::/foo",
-            ]
-            for url in urls:
-                # The URL will be allowed into the command, but the command will
-                # fail since we don't have that protocol enabled in the Git config file.
-                with self.assertRaises(GitCommandError):
-                    Repo.clone_from(url, tmp_dir / "repo", allow_unsafe_protocols=True)
-                assert not tmp_file.exists()
-
-    def test_clone_from_unsafe_protocol_allowed_and_enabled(self):
-        with tempfile.TemporaryDirectory() as tdir:
-            tmp_dir = pathlib.Path(tdir)
-            tmp_file = tmp_dir / "pwn"
-            urls = [
-                f"ext::sh -c touch% {tmp_file}",
-            ]
-            allow_ext = [
-                "--config=protocol.ext.allow=always",
-            ]
-            for url in urls:
-                # The URL will be allowed into the command, and the protocol is enabled,
-                # but the command will fail since it can't read from the remote repo.
-                assert not tmp_file.exists()
-                with self.assertRaises(GitCommandError):
-                    Repo.clone_from(
-                        url,
-                        tmp_dir / "repo",
-                        multi_options=allow_ext,
-                        allow_unsafe_protocols=True,
-                        allow_unsafe_options=True,
-                    )
-                assert tmp_file.exists()
-                tmp_file.unlink()
-
     @with_rw_repo("HEAD")
     def test_max_chunk_size(self, repo):
         class TestOutputStream(TestBase):
Index: GitPython-3.1.34.1693646983.2a2ae77/git/cmd.py
===================================================================
--- GitPython-3.1.34.1693646983.2a2ae77.orig/git/cmd.py
+++ GitPython-3.1.34.1693646983.2a2ae77/git/cmd.py
@@ -497,18 +497,66 @@ class Git(LazyMixin):
 
     @classmethod
     def check_unsafe_options(cls, options: List[str], unsafe_options: List[str]) -> None:
-        """
-        Check for unsafe options.
+        """Raise :class:`~git.exc.UnsafeOptionError` for blocked option spellings.
+
+        In addition to exact matches, this rejects abbreviated long options accepted
+        by Git (for example, ``--upl`` for ``--upload-pack``) and unsafe short options
+        whose values are joined to the same token, including after clusterable flags
+        (for example, ``-uVALUE`` and ``-fuVALUE``).
+
+        A list containing only bare names is treated as normalized keyword arguments,
+        so multi-character names such as ``upload_p`` are checked as long-option
+        abbreviations. If any item starts with ``-``, the list is treated as tokenized
+        command-line input: bare items can be option values and are not checked as
+        abbreviations. Thus ``["--origin", "upload"]`` is allowed. Single-dash options
+        use short-option parsing rather than broad prefix matching, preserving safe
+        attached values such as ``-oupstream`` and ``-bcurrent``.
 
-        Some options that are passed to `git <command>` can be used to execute
-        arbitrary commands, this are blocked by default.
+        Some options passed to ``git <command>`` can execute arbitrary commands and
+        are therefore blocked by default unless the caller explicitly allows them.
         """
         # Options can be of the form `foo`, `--foo`, `--foo bar`, or `--foo=bar`.
+        # Git accepts any unambiguous prefix of a long option, so an abbreviated
+        # spelling such as `--upl` for `--upload-pack` must be rejected too. An
+        # option is unsafe if its canonical name is a prefix of any blocked
+        # option's canonical name. Only long options and multi-character kwargs
+        # can be abbreviations; single-character short options remain exact-match
+        # only.
         canonical_unsafe_options = {cls._canonicalize_option_name(option): option for option in unsafe_options}
+        unsafe_short_options = {
+            canonical: option
+            for canonical, option in canonical_unsafe_options.items()
+            if option.startswith("-") and not option.startswith("--") and len(canonical) == 1
+        }
+        # These value-less Git flags can be clustered before another short option
+        # (for example, ``-fuVALUE``). Stop at any other character because it may
+        # begin an attached value, as ``o`` does in the safe option ``-oupstream``.
+        clusterable_short_options = frozenset("46flnqsv")
+        options_are_kwargs = all(not option.startswith("-") for option in options)
         for option in options:
-            unsafe_option = canonical_unsafe_options.get(cls._canonicalize_option_name(option))
+            candidate = cls._canonicalize_option_name(option)
+            if not candidate:
+                continue
+            unsafe_option = canonical_unsafe_options.get(candidate)
             if unsafe_option is not None:
                 raise UnsafeOptionError(f"{unsafe_option} is not allowed, use `allow_unsafe_options=True` to allow it.")
+            option_token = option.split("=", 1)[0].split(None, 1)[0]
+            if option_token.startswith("-") and not option_token.startswith("--"):
+                for option_char in option_token[1:]:
+                    unsafe_option = unsafe_short_options.get(option_char)
+                    if unsafe_option is not None:
+                        raise UnsafeOptionError(
+                            f"{unsafe_option} is not allowed, use `allow_unsafe_options=True` to allow it."
+                        )
+                    if option_char not in clusterable_short_options:
+                        break
+            if not (option.startswith("--") or (options_are_kwargs and len(candidate) > 1)):
+                continue
+            for canonical, unsafe_option in canonical_unsafe_options.items():
+                if canonical.startswith(candidate):
+                    raise UnsafeOptionError(
+                        f"{unsafe_option} is not allowed, use `allow_unsafe_options=True` to allow it."
+                    )
 
 
     class AutoInterrupt(object):
Index: GitPython-3.1.34.1693646983.2a2ae77/test/test_git.py
===================================================================
--- GitPython-3.1.34.1693646983.2a2ae77.orig/test/test_git.py
+++ GitPython-3.1.34.1693646983.2a2ae77/test/test_git.py
@@ -101,6 +101,35 @@ class TestGit(TestBase):
             with self.assertRaises(UnsafeOptionError):
                 Git.check_unsafe_options(options=options, unsafe_options=unsafe_options)
 
+    def test_check_unsafe_options_does_not_treat_short_options_as_abbreviations(self):
+        unsafe_options = ["--upload-pack"]
+
+        Git.check_unsafe_options(options=["-u", "u", "-upl"], unsafe_options=unsafe_options)
+        with self.assertRaises(UnsafeOptionError):
+            Git.check_unsafe_options(options=["--u"], unsafe_options=unsafe_options)
+
+    def test_check_unsafe_options_does_not_treat_option_values_as_abbreviations(self):
+        Git.check_unsafe_options(options=["--branch", "conf"], unsafe_options=["--config"])
+
+    def test_check_unsafe_options_rejects_joined_unsafe_short_options(self):
+        cases = [
+            (["-utouch /tmp/pwn"], ["-u"]),
+            (["-futouch /tmp/pwn"], ["-u"]),
+            (["-qutouch${IFS}/tmp/pwn"], ["-u"]),
+            (["-cprotocol.ext.allow=always"], ["-c"]),
+            (["-vcprotocol.ext.allow=always"], ["-c"]),
+        ]
+
+        for options, unsafe_options in cases:
+            with self.assertRaises(UnsafeOptionError):
+                Git.check_unsafe_options(options=options, unsafe_options=unsafe_options)
+
+    def test_check_unsafe_options_allows_attached_safe_short_option_values(self):
+        unsafe_options = ["--upload-pack", "-u", "--config", "-c"]
+
+        Git.check_unsafe_options(options=["-oupstream", "-bcurrent"], unsafe_options=unsafe_options)
+
+
     def test_it_executes_git_to_shell_and_returns_result(self):
         self.assertRegex(self.git.execute(["git", "version"]), r"^git version [\d\.]{2}.*$")
 
Index: GitPython-3.1.34.1693646983.2a2ae77/test/test_remote.py
===================================================================
--- GitPython-3.1.34.1693646983.2a2ae77.orig/test/test_remote.py
+++ GitPython-3.1.34.1693646983.2a2ae77/test/test_remote.py
@@ -821,7 +821,11 @@ class TestRemote(TestBase):
             remote = rw_repo.remote("origin")
             tmp_dir = Path(tdir)
             tmp_file = tmp_dir / "pwn"
-            unsafe_options = [{"upload-pack": f"touch {tmp_file}"}, {"upload_pack": f"touch {tmp_file}"}]
+            unsafe_options = [
+                {"upload-pack": f"touch {tmp_file}"},
+                {"upload_pack": f"touch {tmp_file}"},
+                {"upload_p": f"touch {tmp_file}"},
+            ]
             for unsafe_option in unsafe_options:
                 with self.assertRaises(UnsafeOptionError):
                     remote.fetch(**unsafe_option)
@@ -880,7 +884,11 @@ class TestRemote(TestBase):
             remote = rw_repo.remote("origin")
             tmp_dir = Path(tdir)
             tmp_file = tmp_dir / "pwn"
-            unsafe_options = [{"upload-pack": f"touch {tmp_file}"}, {"upload_pack": f"touch {tmp_file}"}]
+            unsafe_options = [
+                {"upload-pack": f"touch {tmp_file}"},
+                {"upload_pack": f"touch {tmp_file}"},
+                {"upload_p": f"touch {tmp_file}"},
+            ]
             for unsafe_option in unsafe_options:
                 with self.assertRaises(UnsafeOptionError):
                     remote.pull(**unsafe_option)
@@ -942,7 +950,9 @@ class TestRemote(TestBase):
             unsafe_options = [
                 {"receive-pack": f"touch {tmp_file}"},
                 {"receive_pack": f"touch {tmp_file}"},
+                {"receive_p": f"touch {tmp_file}"},
                 {"exec": f"touch {tmp_file}"},
+                {"exe": f"touch {tmp_file}"},
             ]
             for unsafe_option in unsafe_options:
                 assert not tmp_file.exists()
