|
1 | 1 | import { Cache, Data, Duration, Effect, Exit, FileSystem, Layer, Path } from "effect"; |
2 | 2 |
|
3 | 3 | import { GitCommandError } from "../Errors.ts"; |
| 4 | +import { parseGitHubWebUrlFromRemoteUrl } from "../githubRemote.ts"; |
4 | 5 | import { GitService } from "../Services/GitService.ts"; |
5 | 6 | import { GitCore, type GitCoreShape } from "../Services/GitCore.ts"; |
6 | 7 |
|
@@ -1071,7 +1072,7 @@ export const makeGitCore = Effect.gen(function* () { |
1071 | 1072 | if (localBranchResult.code !== 0) { |
1072 | 1073 | const stderr = localBranchResult.stderr.trim(); |
1073 | 1074 | if (stderr.toLowerCase().includes("not a git repository")) { |
1074 | | - return { branches: [], isRepo: false, hasOriginRemote: false }; |
| 1075 | + return { branches: [], isRepo: false, hasOriginRemote: false, originWebUrl: null }; |
1075 | 1076 | } |
1076 | 1077 | return yield* createGitCommandError( |
1077 | 1078 | "GitCore.listBranches", |
@@ -1113,33 +1114,42 @@ export const makeGitCore = Effect.gen(function* () { |
1113 | 1114 | ), |
1114 | 1115 | ); |
1115 | 1116 |
|
1116 | | - const [defaultRef, worktreeList, remoteBranchResult, remoteNamesResult, branchLastCommit] = |
1117 | | - yield* Effect.all( |
1118 | | - [ |
1119 | | - executeGit( |
1120 | | - "GitCore.listBranches.defaultRef", |
1121 | | - input.cwd, |
1122 | | - ["symbolic-ref", "refs/remotes/origin/HEAD"], |
1123 | | - { |
1124 | | - timeoutMs: 5_000, |
1125 | | - allowNonZeroExit: true, |
1126 | | - }, |
1127 | | - ), |
1128 | | - executeGit( |
1129 | | - "GitCore.listBranches.worktreeList", |
1130 | | - input.cwd, |
1131 | | - ["worktree", "list", "--porcelain"], |
1132 | | - { |
1133 | | - timeoutMs: 5_000, |
1134 | | - allowNonZeroExit: true, |
1135 | | - }, |
1136 | | - ), |
1137 | | - remoteBranchResultEffect, |
1138 | | - remoteNamesResultEffect, |
1139 | | - branchRecencyPromise, |
1140 | | - ], |
1141 | | - { concurrency: "unbounded" }, |
1142 | | - ); |
| 1117 | + const [ |
| 1118 | + defaultRef, |
| 1119 | + worktreeList, |
| 1120 | + remoteBranchResult, |
| 1121 | + remoteNamesResult, |
| 1122 | + originRemoteUrl, |
| 1123 | + branchLastCommit, |
| 1124 | + ] = yield* Effect.all( |
| 1125 | + [ |
| 1126 | + executeGit( |
| 1127 | + "GitCore.listBranches.defaultRef", |
| 1128 | + input.cwd, |
| 1129 | + ["symbolic-ref", "refs/remotes/origin/HEAD"], |
| 1130 | + { |
| 1131 | + timeoutMs: 5_000, |
| 1132 | + allowNonZeroExit: true, |
| 1133 | + }, |
| 1134 | + ), |
| 1135 | + executeGit( |
| 1136 | + "GitCore.listBranches.worktreeList", |
| 1137 | + input.cwd, |
| 1138 | + ["worktree", "list", "--porcelain"], |
| 1139 | + { |
| 1140 | + timeoutMs: 5_000, |
| 1141 | + allowNonZeroExit: true, |
| 1142 | + }, |
| 1143 | + ), |
| 1144 | + remoteBranchResultEffect, |
| 1145 | + remoteNamesResultEffect, |
| 1146 | + readConfigValue(input.cwd, "remote.origin.url").pipe( |
| 1147 | + Effect.catch(() => Effect.succeed(null)), |
| 1148 | + ), |
| 1149 | + branchRecencyPromise, |
| 1150 | + ], |
| 1151 | + { concurrency: "unbounded" }, |
| 1152 | + ); |
1143 | 1153 |
|
1144 | 1154 | const remoteNames = |
1145 | 1155 | remoteNamesResult.code === 0 ? parseRemoteNames(remoteNamesResult.stdout) : []; |
@@ -1237,7 +1247,12 @@ export const makeGitCore = Effect.gen(function* () { |
1237 | 1247 |
|
1238 | 1248 | const branches = [...localBranches, ...remoteBranches]; |
1239 | 1249 |
|
1240 | | - return { branches, isRepo: true, hasOriginRemote: remoteNames.includes("origin") }; |
| 1250 | + return { |
| 1251 | + branches, |
| 1252 | + isRepo: true, |
| 1253 | + hasOriginRemote: remoteNames.includes("origin"), |
| 1254 | + originWebUrl: parseGitHubWebUrlFromRemoteUrl(originRemoteUrl), |
| 1255 | + }; |
1241 | 1256 | }); |
1242 | 1257 |
|
1243 | 1258 | const createWorktree: GitCoreShape["createWorktree"] = (input) => |
|
0 commit comments