Skip to content

Commit 789987e

Browse files
committed
Refactor out common file reading code for git config
1 parent 74d9343 commit 789987e

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/coverage/coverage.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,12 @@ export function activateCoverage(context: ExtensionContext) {
138138
)?.uri.path;
139139

140140
const gitConfig = Uri.file(`${pathToWorkspace}/.git/config`);
141-
// Try https remote auth first
142-
let remote = await workspace.fs
141+
const configLines = workspace.fs
143142
.readFile(gitConfig)
144143
.then((buf) => buf.toString())
145-
.then((string) => string.split("\n"))
144+
.then((string) => string.split("\n"));
145+
// Try https remote auth first
146+
let remote = await configLines
146147
.then((lines) =>
147148
lines.find((line) => line.match(/https:\/\/.*\/.*\/.*.git$/))
148149
)
@@ -154,10 +155,7 @@ export function activateCoverage(context: ExtensionContext) {
154155
);
155156
if (!remote) {
156157
// if that doesn't work try looking for remotes using ssh auth
157-
remote = await workspace.fs
158-
.readFile(gitConfig)
159-
.then((buf) => buf.toString())
160-
.then((string) => string.split("\n"))
158+
remote = await configLines
161159
.then((lines) => lines.find((line) => line.match(/git@.*:.*\/.*.git$/)))
162160
.then((line) =>
163161
line?.replace(/.*:/, "").replace(".git", "").split("/")

0 commit comments

Comments
 (0)