Skip to content

Commit c25f420

Browse files
committed
fix: Replace parse-git-config with ini + fs
1 parent da77ef1 commit c25f420

File tree

4 files changed

+49
-64
lines changed

4 files changed

+49
-64
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
"@types/async-retry": "^1.4.1",
104104
"@types/debug": "0.0.30",
105105
"@types/get-stdin": "^5.0.1",
106+
"@types/ini": "^4.1.1",
106107
"@types/jest": "^28.0.0",
107108
"@types/json5": "^2.2.0",
108109
"@types/jsonpointer": "^4.0.0",
@@ -156,6 +157,7 @@
156157
"http-proxy-agent": "^5.0.0",
157158
"https-proxy-agent": "^5.0.1",
158159
"hyperlinker": "^1.0.0",
160+
"ini": "^5.0.0",
159161
"json5": "^2.2.3",
160162
"jsonpointer": "^5.0.0",
161163
"jsonwebtoken": "^9.0.0",
@@ -172,7 +174,6 @@
172174
"override-require": "^1.1.1",
173175
"p-limit": "^2.1.0",
174176
"parse-diff": "^0.7.0",
175-
"parse-git-config": "^2.0.3",
176177
"parse-github-url": "^1.0.2",
177178
"parse-link-header": "^2.0.0",
178179
"pinpoint": "^1.1.0",

source/ambient.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ declare module "supports-hyperlinks"
3939
// export default function(code: string, filename?: string, opts?: Partial<RequireOptions>): any
4040
// }
4141

42-
declare module "parse-git-config"
4342
declare module "parse-github-url"
4443
// Basically does one thing
4544
declare module "override-require"

source/commands/init/get-repo-slug.ts

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,42 @@
1-
import parseGitConfig from "parse-git-config"
1+
import fs from "fs"
2+
import path from "path"
3+
import ini from "ini"
24
import parseGithubURL from "parse-github-url"
35

46
export const getRepoSlug = () => {
5-
const config = parseGitConfig.sync()
6-
const possibleRemotes = [config['remote "upstream"'], config['remote "origin"']].filter((f) => f)
7-
if (possibleRemotes.length === 0) {
7+
try {
8+
// Find .git/config in the current directory or parent directories
9+
const gitConfigPath = path.join(process.cwd(), ".git", "config")
10+
11+
if (!fs.existsSync(gitConfigPath)) {
12+
return null
13+
}
14+
15+
// Read and parse the git config file
16+
const configContent = fs.readFileSync(gitConfigPath, "utf8")
17+
18+
// Parse the git config and transform to match parse-git-config's output format
19+
const parsedConfig = ini.parse(configContent)
20+
21+
// Transform the ini output to match parse-git-config's structure
22+
const config: Record<string, any> = {}
23+
24+
// Handle the remotes section specifically
25+
if (parsedConfig.remote) {
26+
for (const remoteName in parsedConfig.remote) {
27+
config[`remote "${remoteName}"`] = parsedConfig.remote[remoteName]
28+
}
29+
}
30+
31+
const possibleRemotes = [config['remote "upstream"'], config['remote "origin"']].filter((f) => f)
32+
if (possibleRemotes.length === 0) {
33+
return null
34+
}
35+
36+
const ghData = possibleRemotes.map((r) => parseGithubURL(r.url))
37+
return ghData.length ? ghData[0].repo : undefined
38+
} catch (error) {
39+
console.error("Error reading git config:", error)
840
return null
941
}
10-
11-
const ghData = possibleRemotes.map((r) => parseGithubURL(r.url))
12-
return ghData.length ? ghData[0].repo : undefined
1342
}

yarn.lock

Lines changed: 11 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1873,6 +1873,11 @@
18731873
resolved "https://registry.yarnpkg.com/@types/highlight.js/-/highlight.js-9.1.8.tgz#d227f18bcb8f3f187e16965f2444859a04689758"
18741874
integrity sha512-dPqwDerUWRYT5Ek6ozB/Hbwrm876WaRZNmXwE+uCTJlGfZlTBF3ubPAAd0hwjoO3ELBhsdL0NAXGoiKHIeTu3A==
18751875

1876+
"@types/ini@^4.1.1":
1877+
version "4.1.1"
1878+
resolved "https://registry.yarnpkg.com/@types/ini/-/ini-4.1.1.tgz#6984664a8cc74c3348f4049d0bf2b1ab2d061ca3"
1879+
integrity sha512-MIyNUZipBTbyUNnhvuXJTY7B6qNI78meck9Jbv3wk0OgNwRyOOVEKDutAkOs1snB/tx0FafyR6/SN4Ps0hZPeg==
1880+
18761881
"@types/istanbul-lib-coverage@*", "@types/istanbul-lib-coverage@^2.0.0", "@types/istanbul-lib-coverage@^2.0.1":
18771882
version "2.0.6"
18781883
resolved "https://registry.yarnpkg.com/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.6.tgz#7739c232a1fee9b4d3ce8985f314c0c6d33549d7"
@@ -3651,13 +3656,6 @@ expand-template@^2.0.3:
36513656
resolved "https://registry.yarnpkg.com/expand-template/-/expand-template-2.0.3.tgz#6e14b3fcee0f3a6340ecb57d2e8918692052a47c"
36523657
integrity sha512-XYfuKMvj4O35f/pOXLObndIRvyQ+/+6AhODh+OKWj9S9498pHHn/IMszH+gt0fBCRWMNfk1ZSp5x3AifmnI2vg==
36533658

3654-
expand-tilde@^2.0.2:
3655-
version "2.0.2"
3656-
resolved "https://registry.yarnpkg.com/expand-tilde/-/expand-tilde-2.0.2.tgz#97e801aa052df02454de46b02bf621642cdc8502"
3657-
integrity sha512-A5EmesHW6rfnZ9ysHQjPdJRni0SRar0tjtG5MNtm9n5TUvsYU8oozprtRD4AqHxcZWWlVuAmQo2nWKfN9oyjTw==
3658-
dependencies:
3659-
homedir-polyfill "^1.0.1"
3660-
36613659
expect@^28.0.0, expect@^28.1.3:
36623660
version "28.1.3"
36633661
resolved "https://registry.yarnpkg.com/expect/-/expect-28.1.3.tgz#90a7c1a124f1824133dd4533cce2d2bdcb6603ec"
@@ -3669,13 +3667,6 @@ expect@^28.0.0, expect@^28.1.3:
36693667
jest-message-util "^28.1.3"
36703668
jest-util "^28.1.3"
36713669

3672-
extend-shallow@^2.0.1:
3673-
version "2.0.1"
3674-
resolved "https://registry.yarnpkg.com/extend-shallow/-/extend-shallow-2.0.1.tgz#51af7d614ad9a9f610ea1bafbb989d6b1c56890f"
3675-
integrity sha512-zCnTtlxNoAiDc3gqY2aYAWFx7XWWiasuF2K8Me5WbN8otHKTUKBwjPtNpRs/rbUZm7KxWAaNj7P1a/p52GbVug==
3676-
dependencies:
3677-
is-extendable "^0.1.0"
3678-
36793670
external-editor@^3.1.0:
36803671
version "3.1.0"
36813672
resolved "https://registry.yarnpkg.com/external-editor/-/external-editor-3.1.0.tgz#cb03f740befae03ea4d283caed2741a83f335495"
@@ -3845,11 +3836,6 @@ fs-constants@^1.0.0:
38453836
resolved "https://registry.yarnpkg.com/fs-constants/-/fs-constants-1.0.0.tgz#6be0de9be998ce16af8afc24497b9ee9b7ccd9ad"
38463837
integrity sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==
38473838

3848-
fs-exists-sync@^0.1.0:
3849-
version "0.1.0"
3850-
resolved "https://registry.yarnpkg.com/fs-exists-sync/-/fs-exists-sync-0.1.0.tgz#982d6893af918e72d08dec9e8673ff2b5a8d6add"
3851-
integrity sha512-cR/vflFyPZtrN6b38ZyWxpWdhlXrzZEBawlpBQMq7033xVY7/kg0GDMBK5jg8lDYQckdJ5x/YC88lM3C7VMsLg==
3852-
38533839
fs-extra@^4.0.0:
38543840
version "4.0.3"
38553841
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-4.0.3.tgz#0d852122e5bc5beb453fb028e9c0c9bf36340c94"
@@ -3993,15 +3979,6 @@ get-uri@^6.0.1:
39933979
data-uri-to-buffer "^6.0.2"
39943980
debug "^4.3.4"
39953981

3996-
git-config-path@^1.0.1:
3997-
version "1.0.1"
3998-
resolved "https://registry.yarnpkg.com/git-config-path/-/git-config-path-1.0.1.tgz#6d33f7ed63db0d0e118131503bab3aca47d54664"
3999-
integrity sha512-KcJ2dlrrP5DbBnYIZ2nlikALfRhKzNSX0stvv3ImJ+fvC4hXKoV+U+74SV0upg+jlQZbrtQzc0bu6/Zh+7aQbg==
4000-
dependencies:
4001-
extend-shallow "^2.0.1"
4002-
fs-exists-sync "^0.1.0"
4003-
homedir-polyfill "^1.0.0"
4004-
40053982
git-up@^8.0.0:
40063983
version "8.0.1"
40073984
resolved "https://registry.yarnpkg.com/git-up/-/git-up-8.0.1.tgz#2a82cfbc77b5eb04074ab1e48593911981654fc7"
@@ -4174,13 +4151,6 @@ highlight.js@^9.0.0:
41744151
resolved "https://registry.yarnpkg.com/highlight.js/-/highlight.js-9.18.5.tgz#d18a359867f378c138d6819edfc2a8acd5f29825"
41754152
integrity sha512-a5bFyofd/BHCX52/8i8uJkjr9DYwXIPnM/plwI6W7ezItLGqzt7X2G2nXuYSfsIJdkwwj/g9DG1LkcGJI/dDoA==
41764153

4177-
homedir-polyfill@^1.0.0, homedir-polyfill@^1.0.1:
4178-
version "1.0.3"
4179-
resolved "https://registry.yarnpkg.com/homedir-polyfill/-/homedir-polyfill-1.0.3.tgz#743298cef4e5af3e194161fbadcc2151d3a058e8"
4180-
integrity sha512-eSmmWE5bZTK2Nou4g0AI3zZ9rswp7GRKoKXS1BLUkvPviOqs4YTN1djQIqrXy9k5gEtdLPy86JjRwsNM9tnDcA==
4181-
dependencies:
4182-
parse-passwd "^1.0.0"
4183-
41844154
hosted-git-info@^2.1.4:
41854155
version "2.8.9"
41864156
resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.8.9.tgz#dffc0bf9a21c02209090f2aa69429e1414daf3f9"
@@ -4334,11 +4304,16 @@ [email protected]:
43344304
resolved "https://registry.yarnpkg.com/ini/-/ini-4.1.1.tgz#d95b3d843b1e906e56d6747d5447904ff50ce7a1"
43354305
integrity sha512-QQnnxNyfvmHFIsj7gkPcYymR8Jdw/o7mp5ZFihxn6h8Ci6fh3Dx4E1gPjpQEpIuPo9XVNY/ZUwh4BPMjGyL01g==
43364306

4337-
ini@^1.3.4, ini@^1.3.5, ini@~1.3.0:
4307+
ini@^1.3.4, ini@~1.3.0:
43384308
version "1.3.8"
43394309
resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.8.tgz#a29da425b48806f34767a4efce397269af28432c"
43404310
integrity sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==
43414311

4312+
ini@^5.0.0:
4313+
version "5.0.0"
4314+
resolved "https://registry.yarnpkg.com/ini/-/ini-5.0.0.tgz#a7a4615339843d9a8ccc2d85c9d81cf93ffbc638"
4315+
integrity sha512-+N0ngpO3e7cRUWOJAS7qw0IZIVc6XPrW4MlFBdD066F2L4k1L6ker3hLqSq7iXxU5tgS4WGkIUElWn5vogAEnw==
4316+
43424317
43434318
version "12.3.0"
43444319
resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-12.3.0.tgz#c5142f49362f1347aa49a18e652db460f14092e6"
@@ -4416,11 +4391,6 @@ is-docker@^3.0.0:
44164391
resolved "https://registry.yarnpkg.com/is-docker/-/is-docker-3.0.0.tgz#90093aa3106277d8a77a5910dbae71747e15a200"
44174392
integrity sha512-eljcgEDlEns/7AXFosB5K/2nCM4P7FQPkGc/DWLy5rmFEWvZayGrik1d9/QIY5nJ4f9YsVvBkA6kJpHn9rISdQ==
44184393

4419-
is-extendable@^0.1.0:
4420-
version "0.1.1"
4421-
resolved "https://registry.yarnpkg.com/is-extendable/-/is-extendable-0.1.1.tgz#62b110e289a471418e3ec36a617d472e301dfc89"
4422-
integrity sha512-5BMULNob1vgFX6EjQw5izWDxrecWK9AM72rugNr0TFldMOi0fj6Jk+zeKIt0xGj4cEfQIJth4w3OKWOJ4f+AFw==
4423-
44244394
is-extglob@^2.1.1:
44254395
version "2.1.1"
44264396
resolved "https://registry.yarnpkg.com/is-extglob/-/is-extglob-2.1.1.tgz#a88c02535791f02ed37c76a1b9ea9773c833f8c2"
@@ -5930,15 +5900,6 @@ parse-diff@^0.7.0:
59305900
resolved "https://registry.yarnpkg.com/parse-diff/-/parse-diff-0.7.1.tgz#9b7a2451c3725baf2c87c831ba192d40ee2237d4"
59315901
integrity sha512-1j3l8IKcy4yRK2W4o9EYvJLSzpAVwz4DXqCewYyx2vEwk2gcf3DBPqc8Fj4XV3K33OYJ08A8fWwyu/ykD/HUSg==
59325902

5933-
parse-git-config@^2.0.3:
5934-
version "2.0.3"
5935-
resolved "https://registry.yarnpkg.com/parse-git-config/-/parse-git-config-2.0.3.tgz#6fb840d4a956e28b971c97b33a5deb73a6d5b6bb"
5936-
integrity sha512-Js7ueMZOVSZ3tP8C7E3KZiHv6QQl7lnJ+OkbxoaFazzSa2KyEHqApfGbU3XboUgUnq4ZuUmskUpYKTNx01fm5A==
5937-
dependencies:
5938-
expand-tilde "^2.0.2"
5939-
git-config-path "^1.0.1"
5940-
ini "^1.3.5"
5941-
59425903
parse-github-url@^1.0.2:
59435904
version "1.0.3"
59445905
resolved "https://registry.yarnpkg.com/parse-github-url/-/parse-github-url-1.0.3.tgz#2ab55642c8685b63fbe2a196f5abe4ae9bd68abc"
@@ -5994,11 +5955,6 @@ parse-ms@^4.0.0:
59945955
resolved "https://registry.yarnpkg.com/parse-ms/-/parse-ms-4.0.0.tgz#c0c058edd47c2a590151a718990533fd62803df4"
59955956
integrity sha512-TXfryirbmq34y8QBwgqCVLi+8oA3oWx2eAnSn62ITyEhEYaWRlVZ2DvMM9eZbMs/RfxPu/PK/aBLyGj4IrqMHw==
59965957

5997-
parse-passwd@^1.0.0:
5998-
version "1.0.0"
5999-
resolved "https://registry.yarnpkg.com/parse-passwd/-/parse-passwd-1.0.0.tgz#6d5b934a456993b23d37f40a382d6f1666a8e5c6"
6000-
integrity sha512-1Y1A//QUXEZK7YKz+rD9WydcE1+EuPr6ZBgKecAB8tmoW6UFv0NREVJe1p+jRxtThkcbbKkfwIbWJe/IeE6m2Q==
6001-
60025958
parse-path@^7.0.0:
60035959
version "7.0.1"
60045960
resolved "https://registry.yarnpkg.com/parse-path/-/parse-path-7.0.1.tgz#ae548cd36315fd8881a3610eae99fa08123ee0e2"

0 commit comments

Comments
 (0)