The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 03:15 UTC
fix(shared): recognize numeric bare-repository config (#27500)
Co-authored-by: maria-rcks <maria@kuuro.net>
maco committed
Nov 6, 2026 at 05:20 UTC
260d84387fbfbf97c0b7391e3f95e9d10429cdd2
2 files changed
+57
-1
packages/shared/src/git.test.ts
+41
@@ -66,6 +66,47 @@ describe("normalizeGitRemoteUrl", () => {
66
});
67
68
describe("isBareGitConfig", () => {
69
+ it("reads Git's numeric booleans without accepting invalid or overflowing values", () => {
70
+ for (const value of [
71
+ "true",
72
+ "yes",
73
+ "on",
74
+ "1",
75
+ "2",
76
+ "-1",
77
+ "+1",
78
+ "01",
79
+ "0x10",
80
+ "1k",
81
+ "1m",
82
+ "1g",
83
+ "2147483647",
84
+ "-2147483648",
85
+ ]) {
86
+ expect(isBareGitConfig(`[core]\nbare = ${value}\n`), value).toBe(true);
87
+ }
88
+ for (const value of [
89
+ "false",
90
+ "no",
91
+ "off",
92
+ "0",
93
+ "-0",
94
+ "00",
95
+ "0x0",
96
+ "0k",
97
+ "08",
98
+ "1.5",
99
+ "2no",
100
+ "2g",
101
+ "2147483648",
102
+ "-2147483649",
103
+ ]) {
104
+ expect(isBareGitConfig(`[core]\nbare = ${value}\n`), value).toBe(false);
105
+ }
106
+ expect(isBareGitConfig("[core]\nbare = 2\nbare = 0\n")).toBe(false);
107
+ expect(isBareGitConfig("[core]\nbare = false\nbare = -2\n")).toBe(true);
108
+ });
109
+
110
it("reads continued bare values after comments and at end of input", () => {
111
const config = ["[core] bare = false # ignored backslash \\", 'bare = "tr\\', 'ue"'].join("\n");
112
packages/shared/src/git.ts
+16
-1
@@ -213,6 +213,21 @@ function parseGitConfigValue(raw: string): string {
213
return out.trim();
214
}
215
216
+function isTrueGitConfigValue(value: string): boolean {
217
+ if (value === "true" || value === "yes" || value === "on") return true;
218
+ const numeric = /^([+-]?)(0x[0-9a-f]+|0[0-7]*|[1-9][0-9]*)([kmg]?)$/.exec(value);
219
+ if (numeric === null) return false;
220
+ const digits = numeric[2]!;
221
+ const magnitude = digits.startsWith("0x")
222
+ ? Number.parseInt(digits.slice(2), 16)
223
+ : Number.parseInt(digits, digits.startsWith("0") ? 8 : 10);
224
+ const scale =
225
+ numeric[3] === "k" ? 1024 : numeric[3] === "m" ? 1024 ** 2 : numeric[3] === "g" ? 1024 ** 3 : 1;
226
+ const number = magnitude * scale * (numeric[1] === "-" ? -1 : 1);
227
+ // Git's boolean parser accepts integers only within its signed 32-bit range.
228
+ return number !== 0 && number >= -2147483648 && number <= 2147483647;
229
+}
230
+
231
export function isBareGitConfig(configText: string): boolean {
232
let inCore = false;
233
let bare = false;
@@ -228,7 +243,7 @@ export function isBareGitConfig(configText: string): boolean {
243
const match = /^bare\s*(?:=(.*)|[#;].*)?$/i.exec(line);
244
if (match === null) continue;
245
const value = match[1] === undefined ? "true" : parseGitConfigValue(match[1]).toLowerCase();
231
- bare = value === "true" || value === "yes" || value === "on" || value === "1";
246
+ bare = isTrueGitConfigValue(value);
247
}
248
return bare;
249
}