From e8d0fbf774d1f6baa3b481adfe48bd262e43b453 Mon Sep 17 00:00:00 2001
From: "GPT 5.6" <codex@openai.com>
Date: Wed, 22 Jul 2026 04:39:00 +0200
Subject: [PATCH] fix: validate split short-option values

<!-- agent -->

Single-character keyword arguments are transformed into an option token and
a separate value token. The unsafe-option candidate builder only checked the
keyword name, allowing an option-like value to bypass guards shared by clone,
remote, revision, blame, and archive operations.

Include dash-prefixed values only when short options are actually split,
including sequence values, while preserving bare values and the non-splitting
compatibility path.

Git baseline a23bace9 defines clone -n and --upload-pack as distinct options,
matching the argv boundary this validation now preserves.

Refs GHSA-r9mr-m37c-5fr3.

Co-authored-by: Sebastian Thiel <sebastian.thiel@icloud.com>
---
 git/cmd.py       |  7 +++++++
 test/test_git.py | 17 +++++++++++++++++
 2 files changed, 24 insertions(+)

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
@@ -575,11 +575,18 @@ class Git(LazyMixin):
             option for option in cls._unpack_args([arg for arg in args if arg is not None]) if option.startswith("-")
         ]
         if kwargs:
+            split_single_char_options = kwargs.get("split_single_char_options", True)
             for key, value in kwargs.items():
                 values = value if isinstance(value, (list, tuple)) else (value,)
                 if any(value is True or (value is not False and value is not None) for value in values):
                     key = str(key)
                     options.append(f"-{key}" if len(key) == 1 else f"--{dashify(key)}")
+                    if len(key) == 1 and split_single_char_options:
+                        options.extend(
+                            str(value)
+                            for value in values
+                            if value is not True and value not in (False, None) and str(value).startswith("-")
+                        )
         return options
 
 
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
@@ -145,6 +145,23 @@ class TestGit(TestBase):
 
         self.assertEqual(options, ["--max-count"])
 
+    def test_option_candidates_include_split_single_char_option_values(self):
+        cases = [
+            ({"n": "--upload-pack=helper"}, ["-n", "--upload-pack=helper"], ["--upload-pack"]),
+            ({"g": ("safe", "--out=target")}, ["-g", "--out=target"], ["--output"]),
+        ]
+
+        for kwargs, candidates, unsafe_options in cases:
+            self.assertEqual(Git._option_candidates(kwargs=kwargs), candidates)
+            with self.assertRaises(UnsafeOptionError):
+                Git.check_unsafe_options(options=candidates, unsafe_options=unsafe_options)
+
+        self.assertEqual(self.git.transform_kwargs(n="--upload-pack=helper"), ["-n", "--upload-pack=helper"])
+
+        unsplit_kwargs = {"n": "--upload-pack=helper", "split_single_char_options": False}
+        self.assertEqual(self.git.transform_kwargs(**unsplit_kwargs), ["-n--upload-pack=helper"])
+        self.assertEqual(Git._option_candidates(kwargs=unsplit_kwargs), ["-n"])
+
     def test_check_unsafe_options_rejects_joined_unsafe_short_options(self):
         cases = [
             (["-utouch /tmp/pwn"], ["-u"]),
