| author | |
| committer | |
| log | 1c290767f22f9d8c7d3fa378d9450c8f48184679 |
| tree | 66ac9b64f8517962269dcd70d471700fc8315499 |
| parent | 9becb3f40af504244f85823bb19f18bfe507ca49 |
| signature | Signed by PGP key B5690EEEBB952194 |
* fix(web): avoid push and PR defaults without origin
* fmt
* object here too
---------
Co-authored-by: Julius Marminge <julius0216@outlook.com>9 files changed, 229 insertions(+), 124 deletions(-)
apps/server/src/git/Layers/GitCore.test.ts+3| ... | ... | @@ -260,6 +260,7 @@ it.layer(TestLayer)("git integration", (it) => { |
| 260 | 260 | yield* initRepoWithCommit(tmp); |
| 261 | 261 | const result = yield* listGitBranches({ cwd: tmp }); |
| 262 | 262 | expect(result.isRepo).toBe(true); |
| 263 | expect(result.hasOriginRemote).toBe(false); | |
| 263 | 264 | expect(result.branches.length).toBeGreaterThanOrEqual(1); |
| 264 | 265 | }), |
| 265 | 266 | ); |
| ... | ... | @@ -273,6 +274,7 @@ it.layer(TestLayer)("git integration", (it) => { |
| 273 | 274 | const tmp = yield* makeTmpDir(); |
| 274 | 275 | const result = yield* listGitBranches({ cwd: tmp }); |
| 275 | 276 | expect(result.isRepo).toBe(false); |
| 277 | expect(result.hasOriginRemote).toBe(false); | |
| 276 | 278 | expect(result.branches).toEqual([]); |
| 277 | 279 | }), |
| 278 | 280 | ); |
| ... | ... | @@ -431,6 +433,7 @@ it.layer(TestLayer)("git integration", (it) => { |
| 431 | 433 | const result = yield* listGitBranches({ cwd: tmp }); |
| 432 | 434 | const firstRemoteIndex = result.branches.findIndex((branch) => branch.isRemote); |
| 433 | 435 | |
| 436 | expect(result.hasOriginRemote).toBe(true); | |
| 434 | 437 | expect(firstRemoteIndex).toBeGreaterThan(0); |
| 435 | 438 | expect(result.branches.slice(0, firstRemoteIndex).every((branch) => !branch.isRemote)).toBe( |
| 436 | 439 | true, |
apps/server/src/git/Layers/GitCore.ts+2-2| ... | ... | @@ -931,7 +931,7 @@ const makeGitCore = Effect.gen(function* () { |
| 931 | 931 | if (localBranchResult.code !== 0) { |
| 932 | 932 | const stderr = localBranchResult.stderr.trim(); |
| 933 | 933 | if (stderr.toLowerCase().includes("not a git repository")) { |
| 934 | return { branches: [], isRepo: false }; | |
| 934 | return { branches: [], isRepo: false, hasOriginRemote: false }; | |
| 935 | 935 | } |
| 936 | 936 | return yield* createGitCommandError( |
| 937 | 937 | "GitCore.listBranches", |
| ... | ... | @@ -1097,7 +1097,7 @@ const makeGitCore = Effect.gen(function* () { |
| 1097 | 1097 | |
| 1098 | 1098 | const branches = [...localBranches, ...remoteBranches]; |
| 1099 | 1099 | |
| 1100 | return { branches, isRepo: true }; | |
| 1100 | return { branches, isRepo: true, hasOriginRemote: remoteNames.includes("origin") }; | |
| 1101 | 1101 | }); |
| 1102 | 1102 | |
| 1103 | 1103 | const createWorktree: GitCoreShape["createWorktree"] = (input) => |
apps/server/src/wsServer.test.ts+2-1| ... | ... | @@ -1577,6 +1577,7 @@ describe("WebSocket Server", () => { |
| 1577 | 1577 | Effect.succeed({ |
| 1578 | 1578 | branches: [], |
| 1579 | 1579 | isRepo: false, |
| 1580 | hasOriginRemote: false, | |
| 1580 | 1581 | }), |
| 1581 | 1582 | ); |
| 1582 | 1583 | const initRepo = vi.fn(() => Effect.void); |
| ... | ... | @@ -1608,7 +1609,7 @@ describe("WebSocket Server", () => { |
| 1608 | 1609 | |
| 1609 | 1610 | const listResponse = await sendRequest(ws, WS_METHODS.gitListBranches, { cwd: "/repo/path" }); |
| 1610 | 1611 | expect(listResponse.error).toBeUndefined(); |
| 1611 | expect(listResponse.result).toEqual({ branches: [], isRepo: false }); | |
| 1612 | expect(listResponse.result).toEqual({ branches: [], isRepo: false, hasOriginRemote: false }); | |
| 1612 | 1613 | expect(listBranches).toHaveBeenCalledWith({ cwd: "/repo/path" }); |
| 1613 | 1614 | |
| 1614 | 1615 | const initResponse = await sendRequest(ws, WS_METHODS.gitInit, { cwd: "/repo/path" }); |
apps/web/public/mockServiceWorker.js+93-106| ... | ... | @@ -7,114 +7,111 @@ |
| 7 | 7 | * - Please do NOT modify this file. |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | const PACKAGE_VERSION = '2.12.10' | |
| 11 | const INTEGRITY_CHECKSUM = '4db4a41e972cec1b64cc569c66952d82' | |
| 12 | const IS_MOCKED_RESPONSE = Symbol('isMockedResponse') | |
| 13 | const activeClientIds = new Set() | |
| 10 | const PACKAGE_VERSION = "2.12.10"; | |
| 11 | const INTEGRITY_CHECKSUM = "4db4a41e972cec1b64cc569c66952d82"; | |
| 12 | const IS_MOCKED_RESPONSE = Symbol("isMockedResponse"); | |
| 13 | const activeClientIds = new Set(); | |
| 14 | 14 | |
| 15 | addEventListener('install', function () { | |
| 16 | self.skipWaiting() | |
| 17 | }) | |
| 15 | addEventListener("install", function () { | |
| 16 | self.skipWaiting(); | |
| 17 | }); | |
| 18 | 18 | |
| 19 | addEventListener('activate', function (event) { | |
| 20 | event.waitUntil(self.clients.claim()) | |
| 21 | }) | |
| 19 | addEventListener("activate", function (event) { | |
| 20 | event.waitUntil(self.clients.claim()); | |
| 21 | }); | |
| 22 | 22 | |
| 23 | addEventListener('message', async function (event) { | |
| 24 | const clientId = Reflect.get(event.source || {}, 'id') | |
| 23 | addEventListener("message", async function (event) { | |
| 24 | const clientId = Reflect.get(event.source || {}, "id"); | |
| 25 | 25 | |
| 26 | 26 | if (!clientId || !self.clients) { |
| 27 | return | |
| 27 | return; | |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | const client = await self.clients.get(clientId) | |
| 30 | const client = await self.clients.get(clientId); | |
| 31 | 31 | |
| 32 | 32 | if (!client) { |
| 33 | return | |
| 33 | return; | |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | const allClients = await self.clients.matchAll({ |
| 37 | type: 'window', | |
| 38 | }) | |
| 37 | type: "window", | |
| 38 | }); | |
| 39 | 39 | |
| 40 | 40 | switch (event.data) { |
| 41 | case 'KEEPALIVE_REQUEST': { | |
| 41 | case "KEEPALIVE_REQUEST": { | |
| 42 | 42 | sendToClient(client, { |
| 43 | type: 'KEEPALIVE_RESPONSE', | |
| 44 | }) | |
| 45 | break | |
| 43 | type: "KEEPALIVE_RESPONSE", | |
| 44 | }); | |
| 45 | break; | |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | case 'INTEGRITY_CHECK_REQUEST': { | |
| 48 | case "INTEGRITY_CHECK_REQUEST": { | |
| 49 | 49 | sendToClient(client, { |
| 50 | type: 'INTEGRITY_CHECK_RESPONSE', | |
| 50 | type: "INTEGRITY_CHECK_RESPONSE", | |
| 51 | 51 | payload: { |
| 52 | 52 | packageVersion: PACKAGE_VERSION, |
| 53 | 53 | checksum: INTEGRITY_CHECKSUM, |
| 54 | 54 | }, |
| 55 | }) | |
| 56 | break | |
| 55 | }); | |
| 56 | break; | |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | case 'MOCK_ACTIVATE': { | |
| 60 | activeClientIds.add(clientId) | |
| 59 | case "MOCK_ACTIVATE": { | |
| 60 | activeClientIds.add(clientId); | |
| 61 | 61 | |
| 62 | 62 | sendToClient(client, { |
| 63 | type: 'MOCKING_ENABLED', | |
| 63 | type: "MOCKING_ENABLED", | |
| 64 | 64 | payload: { |
| 65 | 65 | client: { |
| 66 | 66 | id: client.id, |
| 67 | 67 | frameType: client.frameType, |
| 68 | 68 | }, |
| 69 | 69 | }, |
| 70 | }) | |
| 71 | break | |
| 70 | }); | |
| 71 | break; | |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | case 'CLIENT_CLOSED': { | |
| 75 | activeClientIds.delete(clientId) | |
| 74 | case "CLIENT_CLOSED": { | |
| 75 | activeClientIds.delete(clientId); | |
| 76 | 76 | |
| 77 | 77 | const remainingClients = allClients.filter((client) => { |
| 78 | return client.id !== clientId | |
| 79 | }) | |
| 78 | return client.id !== clientId; | |
| 79 | }); | |
| 80 | 80 | |
| 81 | 81 | // Unregister itself when there are no more clients |
| 82 | 82 | if (remainingClients.length === 0) { |
| 83 | self.registration.unregister() | |
| 83 | self.registration.unregister(); | |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | break | |
| 86 | break; | |
| 87 | 87 | } |
| 88 | 88 | } |
| 89 | }) | |
| 89 | }); | |
| 90 | 90 | |
| 91 | addEventListener('fetch', function (event) { | |
| 92 | const requestInterceptedAt = Date.now() | |
| 91 | addEventListener("fetch", function (event) { | |
| 92 | const requestInterceptedAt = Date.now(); | |
| 93 | 93 | |
| 94 | 94 | // Bypass navigation requests. |
| 95 | if (event.request.mode === 'navigate') { | |
| 96 | return | |
| 95 | if (event.request.mode === "navigate") { | |
| 96 | return; | |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | // Opening the DevTools triggers the "only-if-cached" request |
| 100 | 100 | // that cannot be handled by the worker. Bypass such requests. |
| 101 | if ( | |
| 102 | event.request.cache === 'only-if-cached' && | |
| 103 | event.request.mode !== 'same-origin' | |
| 104 | ) { | |
| 105 | return | |
| 101 | if (event.request.cache === "only-if-cached" && event.request.mode !== "same-origin") { | |
| 102 | return; | |
| 106 | 103 | } |
| 107 | 104 | |
| 108 | 105 | // Bypass all requests when there are no active clients. |
| 109 | 106 | // Prevents the self-unregistered worked from handling requests |
| 110 | 107 | // after it's been terminated (still remains active until the next reload). |
| 111 | 108 | if (activeClientIds.size === 0) { |
| 112 | return | |
| 109 | return; | |
| 113 | 110 | } |
| 114 | 111 | |
| 115 | const requestId = crypto.randomUUID() | |
| 116 | event.respondWith(handleRequest(event, requestId, requestInterceptedAt)) | |
| 117 | }) | |
| 112 | const requestId = crypto.randomUUID(); | |
| 113 | event.respondWith(handleRequest(event, requestId, requestInterceptedAt)); | |
| 114 | }); | |
| 118 | 115 | |
| 119 | 116 | /** |
| 120 | 117 | * @param {FetchEvent} event |
| ... | ... | @@ -122,28 +119,23 @@ addEventListener('fetch', function (event) { |
| 122 | 119 | * @param {number} requestInterceptedAt |
| 123 | 120 | */ |
| 124 | 121 | async function handleRequest(event, requestId, requestInterceptedAt) { |
| 125 | const client = await resolveMainClient(event) | |
| 126 | const requestCloneForEvents = event.request.clone() | |
| 127 | const response = await getResponse( | |
| 128 | event, | |
| 129 | client, | |
| 130 | requestId, | |
| 131 | requestInterceptedAt, | |
| 132 | ) | |
| 122 | const client = await resolveMainClient(event); | |
| 123 | const requestCloneForEvents = event.request.clone(); | |
| 124 | const response = await getResponse(event, client, requestId, requestInterceptedAt); | |
| 133 | 125 | |
| 134 | 126 | // Send back the response clone for the "response:*" life-cycle events. |
| 135 | 127 | // Ensure MSW is active and ready to handle the message, otherwise |
| 136 | 128 | // this message will pend indefinitely. |
| 137 | 129 | if (client && activeClientIds.has(client.id)) { |
| 138 | const serializedRequest = await serializeRequest(requestCloneForEvents) | |
| 130 | const serializedRequest = await serializeRequest(requestCloneForEvents); | |
| 139 | 131 | |
| 140 | 132 | // Clone the response so both the client and the library could consume it. |
| 141 | const responseClone = response.clone() | |
| 133 | const responseClone = response.clone(); | |
| 142 | 134 | |
| 143 | 135 | sendToClient( |
| 144 | 136 | client, |
| 145 | 137 | { |
| 146 | type: 'RESPONSE', | |
| 138 | type: "RESPONSE", | |
| 147 | 139 | payload: { |
| 148 | 140 | isMockedResponse: IS_MOCKED_RESPONSE in response, |
| 149 | 141 | request: { |
| ... | ... | @@ -160,10 +152,10 @@ async function handleRequest(event, requestId, requestInterceptedAt) { |
| 160 | 152 | }, |
| 161 | 153 | }, |
| 162 | 154 | responseClone.body ? [serializedRequest.body, responseClone.body] : [], |
| 163 | ) | |
| 155 | ); | |
| 164 | 156 | } |
| 165 | 157 | |
| 166 | return response | |
| 158 | return response; | |
| 167 | 159 | } |
| 168 | 160 | |
| 169 | 161 | /** |
| ... | ... | @@ -175,30 +167,30 @@ async function handleRequest(event, requestId, requestInterceptedAt) { |
| 175 | 167 | * @returns {Promise<Client | undefined>} |
| 176 | 168 | */ |
| 177 | 169 | async function resolveMainClient(event) { |
| 178 | const client = await self.clients.get(event.clientId) | |
| 170 | const client = await self.clients.get(event.clientId); | |
| 179 | 171 | |
| 180 | 172 | if (activeClientIds.has(event.clientId)) { |
| 181 | return client | |
| 173 | return client; | |
| 182 | 174 | } |
| 183 | 175 | |
| 184 | if (client?.frameType === 'top-level') { | |
| 185 | return client | |
| 176 | if (client?.frameType === "top-level") { | |
| 177 | return client; | |
| 186 | 178 | } |
| 187 | 179 | |
| 188 | 180 | const allClients = await self.clients.matchAll({ |
| 189 | type: 'window', | |
| 190 | }) | |
| 181 | type: "window", | |
| 182 | }); | |
| 191 | 183 | |
| 192 | 184 | return allClients |
| 193 | 185 | .filter((client) => { |
| 194 | 186 | // Get only those clients that are currently visible. |
| 195 | return client.visibilityState === 'visible' | |
| 187 | return client.visibilityState === "visible"; | |
| 196 | 188 | }) |
| 197 | 189 | .find((client) => { |
| 198 | 190 | // Find the client ID that's recorded in the |
| 199 | 191 | // set of clients that have registered the worker. |
| 200 | return activeClientIds.has(client.id) | |
| 201 | }) | |
| 192 | return activeClientIds.has(client.id); | |
| 193 | }); | |
| 202 | 194 | } |
| 203 | 195 | |
| 204 | 196 | /** |
| ... | ... | @@ -211,36 +203,34 @@ async function resolveMainClient(event) { |
| 211 | 203 | async function getResponse(event, client, requestId, requestInterceptedAt) { |
| 212 | 204 | // Clone the request because it might've been already used |
| 213 | 205 | // (i.e. its body has been read and sent to the client). |
| 214 | const requestClone = event.request.clone() | |
| 206 | const requestClone = event.request.clone(); | |
| 215 | 207 | |
| 216 | 208 | function passthrough() { |
| 217 | 209 | // Cast the request headers to a new Headers instance |
| 218 | 210 | // so the headers can be manipulated with. |
| 219 | const headers = new Headers(requestClone.headers) | |
| 211 | const headers = new Headers(requestClone.headers); | |
| 220 | 212 | |
| 221 | 213 | // Remove the "accept" header value that marked this request as passthrough. |
| 222 | 214 | // This prevents request alteration and also keeps it compliant with the |
| 223 | 215 | // user-defined CORS policies. |
| 224 | const acceptHeader = headers.get('accept') | |
| 216 | const acceptHeader = headers.get("accept"); | |
| 225 | 217 | if (acceptHeader) { |
| 226 | const values = acceptHeader.split(',').map((value) => value.trim()) | |
| 227 | const filteredValues = values.filter( | |
| 228 | (value) => value !== 'msw/passthrough', | |
| 229 | ) | |
| 218 | const values = acceptHeader.split(",").map((value) => value.trim()); | |
| 219 | const filteredValues = values.filter((value) => value !== "msw/passthrough"); | |
| 230 | 220 | |
| 231 | 221 | if (filteredValues.length > 0) { |
| 232 | headers.set('accept', filteredValues.join(', ')) | |
| 222 | headers.set("accept", filteredValues.join(", ")); | |
| 233 | 223 | } else { |
| 234 | headers.delete('accept') | |
| 224 | headers.delete("accept"); | |
| 235 | 225 | } |
| 236 | 226 | } |
| 237 | 227 | |
| 238 | return fetch(requestClone, { headers }) | |
| 228 | return fetch(requestClone, { headers }); | |
| 239 | 229 | } |
| 240 | 230 | |
| 241 | 231 | // Bypass mocking when the client is not active. |
| 242 | 232 | if (!client) { |
| 243 | return passthrough() | |
| 233 | return passthrough(); | |
| 244 | 234 | } |
| 245 | 235 | |
| 246 | 236 | // Bypass initial page load requests (i.e. static assets). |
| ... | ... | @@ -248,15 +238,15 @@ async function getResponse(event, client, requestId, requestInterceptedAt) { |
| 248 | 238 | // means that MSW hasn't dispatched the "MOCK_ACTIVATE" event yet |
| 249 | 239 | // and is not ready to handle requests. |
| 250 | 240 | if (!activeClientIds.has(client.id)) { |
| 251 | return passthrough() | |
| 241 | return passthrough(); | |
| 252 | 242 | } |
| 253 | 243 | |
| 254 | 244 | // Notify the client that a request has been intercepted. |
| 255 | const serializedRequest = await serializeRequest(event.request) | |
| 245 | const serializedRequest = await serializeRequest(event.request); | |
| 256 | 246 | const clientMessage = await sendToClient( |
| 257 | 247 | client, |
| 258 | 248 | { |
| 259 | type: 'REQUEST', | |
| 249 | type: "REQUEST", | |
| 260 | 250 | payload: { |
| 261 | 251 | id: requestId, |
| 262 | 252 | interceptedAt: requestInterceptedAt, |
| ... | ... | @@ -264,19 +254,19 @@ async function getResponse(event, client, requestId, requestInterceptedAt) { |
| 264 | 254 | }, |
| 265 | 255 | }, |
| 266 | 256 | [serializedRequest.body], |
| 267 | ) | |
| 257 | ); | |
| 268 | 258 | |
| 269 | 259 | switch (clientMessage.type) { |
| 270 | case 'MOCK_RESPONSE': { | |
| 271 | return respondWithMock(clientMessage.data) | |
| 260 | case "MOCK_RESPONSE": { | |
| 261 | return respondWithMock(clientMessage.data); | |
| 272 | 262 | } |
| 273 | 263 | |
| 274 | case 'PASSTHROUGH': { | |
| 275 | return passthrough() | |
| 264 | case "PASSTHROUGH": { | |
| 265 | return passthrough(); | |
| 276 | 266 | } |
| 277 | 267 | } |
| 278 | 268 | |
| 279 | return passthrough() | |
| 269 | return passthrough(); | |
| 280 | 270 | } |
| 281 | 271 | |
| 282 | 272 | /** |
| ... | ... | @@ -287,21 +277,18 @@ async function getResponse(event, client, requestId, requestInterceptedAt) { |
| 287 | 277 | */ |
| 288 | 278 | function sendToClient(client, message, transferrables = []) { |
| 289 | 279 | return new Promise((resolve, reject) => { |
| 290 | const channel = new MessageChannel() | |
| 280 | const channel = new MessageChannel(); | |
| 291 | 281 | |
| 292 | 282 | channel.port1.onmessage = (event) => { |
| 293 | 283 | if (event.data && event.data.error) { |
| 294 | return reject(event.data.error) | |
| 284 | return reject(event.data.error); | |
| 295 | 285 | } |
| 296 | 286 | |
| 297 | resolve(event.data) | |
| 298 | } | |
| 287 | resolve(event.data); | |
| 288 | }; | |
| 299 | 289 | |
| 300 | client.postMessage(message, [ | |
| 301 | channel.port2, | |
| 302 | ...transferrables.filter(Boolean), | |
| 303 | ]) | |
| 304 | }) | |
| 290 | client.postMessage(message, [channel.port2, ...transferrables.filter(Boolean)]); | |
| 291 | }); | |
| 305 | 292 | } |
| 306 | 293 | |
| 307 | 294 | /** |
| ... | ... | @@ -314,17 +301,17 @@ function respondWithMock(response) { |
| 314 | 301 | // instance will have status code set to 0. Since it's not possible to create |
| 315 | 302 | // a Response instance with status code 0, handle that use-case separately. |
| 316 | 303 | if (response.status === 0) { |
| 317 | return Response.error() | |
| 304 | return Response.error(); | |
| 318 | 305 | } |
| 319 | 306 | |
| 320 | const mockedResponse = new Response(response.body, response) | |
| 307 | const mockedResponse = new Response(response.body, response); | |
| 321 | 308 | |
| 322 | 309 | Reflect.defineProperty(mockedResponse, IS_MOCKED_RESPONSE, { |
| 323 | 310 | value: true, |
| 324 | 311 | enumerable: true, |
| 325 | }) | |
| 312 | }); | |
| 326 | 313 | |
| 327 | return mockedResponse | |
| 314 | return mockedResponse; | |
| 328 | 315 | } |
| 329 | 316 | |
| 330 | 317 | /** |
| ... | ... | @@ -345,5 +332,5 @@ async function serializeRequest(request) { |
| 345 | 332 | referrerPolicy: request.referrerPolicy, |
| 346 | 333 | body: await request.arrayBuffer(), |
| 347 | 334 | keepalive: request.keepalive, |
| 348 | } | |
| 335 | }; | |
| 349 | 336 | } |
apps/web/src/components/ChatView.browser.tsx+1| ... | ... | @@ -321,6 +321,7 @@ function resolveWsRpc(tag: string): unknown { |
| 321 | 321 | if (tag === WS_METHODS.gitListBranches) { |
| 322 | 322 | return { |
| 323 | 323 | isRepo: true, |
| 324 | hasOriginRemote: true, | |
| 324 | 325 | branches: [ |
| 325 | 326 | { |
| 326 | 327 | name: "main", |
apps/web/src/components/GitActionsControl.logic.test.ts+68| ... | ... | @@ -348,6 +348,21 @@ describe("when: working tree has local changes", () => { |
| 348 | 348 | }); |
| 349 | 349 | }); |
| 350 | 350 | |
| 351 | it("resolveQuickAction falls back to commit when no origin remote exists", () => { | |
| 352 | const quick = resolveQuickAction( | |
| 353 | status({ hasWorkingTreeChanges: true, hasUpstream: false }), | |
| 354 | false, | |
| 355 | false, | |
| 356 | false, | |
| 357 | ); | |
| 358 | assert.deepInclude(quick, { | |
| 359 | kind: "run_action", | |
| 360 | action: "commit", | |
| 361 | label: "Commit", | |
| 362 | disabled: false, | |
| 363 | }); | |
| 364 | }); | |
| 365 | ||
| 351 | 366 | it("resolveQuickAction returns commit and push when open PR exists", () => { |
| 352 | 367 | const quick = resolveQuickAction( |
| 353 | 368 | status({ |
| ... | ... | @@ -623,6 +638,25 @@ describe("when: branch has no upstream configured", () => { |
| 623 | 638 | }); |
| 624 | 639 | }); |
| 625 | 640 | |
| 641 | it("resolveQuickAction disables push-and-pr flows when no origin remote exists", () => { | |
| 642 | const quick = resolveQuickAction( | |
| 643 | status({ | |
| 644 | hasUpstream: false, | |
| 645 | aheadCount: 2, | |
| 646 | pr: null, | |
| 647 | }), | |
| 648 | false, | |
| 649 | false, | |
| 650 | false, | |
| 651 | ); | |
| 652 | assert.deepEqual(quick, { | |
| 653 | kind: "show_hint", | |
| 654 | label: "Push", | |
| 655 | hint: 'Add an "origin" remote before pushing or creating a PR.', | |
| 656 | disabled: true, | |
| 657 | }); | |
| 658 | }); | |
| 659 | ||
| 626 | 660 | it("buildMenuItems enables create PR when no upstream and commits are ahead", () => { |
| 627 | 661 | const items = buildMenuItems(status({ hasUpstream: false, pr: null, aheadCount: 2 }), false); |
| 628 | 662 | assert.deepEqual(items, [ |
| ... | ... | @@ -653,6 +687,40 @@ describe("when: branch has no upstream configured", () => { |
| 653 | 687 | ]); |
| 654 | 688 | }); |
| 655 | 689 | |
| 690 | it("buildMenuItems disables push and create PR when no origin remote exists", () => { | |
| 691 | const items = buildMenuItems( | |
| 692 | status({ hasUpstream: false, pr: null, aheadCount: 2 }), | |
| 693 | false, | |
| 694 | false, | |
| 695 | ); | |
| 696 | assert.deepEqual(items, [ | |
| 697 | { | |
| 698 | id: "commit", | |
| 699 | label: "Commit", | |
| 700 | disabled: true, | |
| 701 | icon: "commit", | |
| 702 | kind: "open_dialog", | |
| 703 | dialogAction: "commit", | |
| 704 | }, | |
| 705 | { | |
| 706 | id: "push", | |
| 707 | label: "Push", | |
| 708 | disabled: true, | |
| 709 | icon: "push", | |
| 710 | kind: "open_dialog", | |
| 711 | dialogAction: "push", | |
| 712 | }, | |
| 713 | { | |
| 714 | id: "pr", | |
| 715 | label: "Create PR", | |
| 716 | disabled: true, | |
| 717 | icon: "pr", | |
| 718 | kind: "open_dialog", | |
| 719 | dialogAction: "create_pr", | |
| 720 | }, | |
| 721 | ]); | |
| 722 | }); | |
| 723 | ||
| 656 | 724 | it("resolveQuickAction is disabled on default branch when no upstream exists and no commits are ahead", () => { |
| 657 | 725 | const quick = resolveQuickAction( |
| 658 | 726 | status({ |
apps/web/src/components/GitActionsControl.logic.ts+31-2| ... | ... | @@ -113,6 +113,7 @@ export function summarizeGitResult(result: GitRunStackedActionResult): { |
| 113 | 113 | export function buildMenuItems( |
| 114 | 114 | gitStatus: GitStatusResult | null, |
| 115 | 115 | isBusy: boolean, |
| 116 | hasOriginRemote = true, | |
| 116 | 117 | ): GitActionMenuItem[] { |
| 117 | 118 | if (!gitStatus) return []; |
| 118 | 119 | |
| ... | ... | @@ -120,10 +121,23 @@ export function buildMenuItems( |
| 120 | 121 | const hasChanges = gitStatus.hasWorkingTreeChanges; |
| 121 | 122 | const hasOpenPr = gitStatus.pr?.state === "open"; |
| 122 | 123 | const isBehind = gitStatus.behindCount > 0; |
| 124 | const canPushWithoutUpstream = hasOriginRemote && !gitStatus.hasUpstream; | |
| 123 | 125 | const canCommit = !isBusy && hasChanges; |
| 124 | const canPush = !isBusy && hasBranch && !hasChanges && !isBehind && gitStatus.aheadCount > 0; | |
| 126 | const canPush = | |
| 127 | !isBusy && | |
| 128 | hasBranch && | |
| 129 | !hasChanges && | |
| 130 | !isBehind && | |
| 131 | gitStatus.aheadCount > 0 && | |
| 132 | (gitStatus.hasUpstream || canPushWithoutUpstream); | |
| 125 | 133 | const canCreatePr = |
| 126 | !isBusy && hasBranch && !hasChanges && !hasOpenPr && gitStatus.aheadCount > 0 && !isBehind; | |
| 134 | !isBusy && | |
| 135 | hasBranch && | |
| 136 | !hasChanges && | |
| 137 | !hasOpenPr && | |
| 138 | gitStatus.aheadCount > 0 && | |
| 139 | !isBehind && | |
| 140 | (gitStatus.hasUpstream || canPushWithoutUpstream); | |
| 127 | 141 | const canOpenPr = !isBusy && hasOpenPr; |
| 128 | 142 | |
| 129 | 143 | return [ |
| ... | ... | @@ -166,6 +180,7 @@ export function resolveQuickAction( |
| 166 | 180 | gitStatus: GitStatusResult | null, |
| 167 | 181 | isBusy: boolean, |
| 168 | 182 | isDefaultBranch = false, |
| 183 | hasOriginRemote = true, | |
| 169 | 184 | ): GitQuickAction { |
| 170 | 185 | if (isBusy) { |
| 171 | 186 | return { label: "Commit", disabled: true, kind: "show_hint", hint: "Git action in progress." }; |
| ... | ... | @@ -197,6 +212,9 @@ export function resolveQuickAction( |
| 197 | 212 | } |
| 198 | 213 | |
| 199 | 214 | if (hasChanges) { |
| 215 | if (!gitStatus.hasUpstream && !hasOriginRemote) { | |
| 216 | return { label: "Commit", disabled: false, kind: "run_action", action: "commit" }; | |
| 217 | } | |
| 200 | 218 | if (hasOpenPr || isDefaultBranch) { |
| 201 | 219 | return { label: "Commit & push", disabled: false, kind: "run_action", action: "commit_push" }; |
| 202 | 220 | } |
| ... | ... | @@ -209,6 +227,17 @@ export function resolveQuickAction( |
| 209 | 227 | } |
| 210 | 228 | |
| 211 | 229 | if (!gitStatus.hasUpstream) { |
| 230 | if (!hasOriginRemote) { | |
| 231 | if (hasOpenPr && !isAhead) { | |
| 232 | return { label: "View PR", disabled: false, kind: "open_pr" }; | |
| 233 | } | |
| 234 | return { | |
| 235 | label: "Push", | |
| 236 | disabled: true, | |
| 237 | kind: "show_hint", | |
| 238 | hint: 'Add an "origin" remote before pushing or creating a PR.', | |
| 239 | }; | |
| 240 | } | |
| 212 | 241 | if (!isAhead) { |
| 213 | 242 | if (hasOpenPr) { |
| 214 | 243 | return { label: "View PR", disabled: false, kind: "open_pr" }; |
apps/web/src/components/GitActionsControl.tsx+28-13| ... | ... | @@ -59,11 +59,17 @@ interface PendingDefaultBranchAction { |
| 59 | 59 | |
| 60 | 60 | type GitActionToastId = ReturnType<typeof toastManager.add>; |
| 61 | 61 | |
| 62 | function getMenuActionDisabledReason( | |
| 63 | item: GitActionMenuItem, | |
| 64 | gitStatus: GitStatusResult | null, | |
| 65 | isBusy: boolean, | |
| 66 | ): string | null { | |
| 62 | function getMenuActionDisabledReason({ | |
| 63 | item, | |
| 64 | gitStatus, | |
| 65 | isBusy, | |
| 66 | hasOriginRemote, | |
| 67 | }: { | |
| 68 | item: GitActionMenuItem; | |
| 69 | gitStatus: GitStatusResult | null; | |
| 70 | isBusy: boolean; | |
| 71 | hasOriginRemote: boolean; | |
| 72 | }): string | null { | |
| 67 | 73 | if (!item.disabled) return null; |
| 68 | 74 | if (isBusy) return "Git action in progress."; |
| 69 | 75 | if (!gitStatus) return "Git status is unavailable."; |
| ... | ... | @@ -91,6 +97,9 @@ function getMenuActionDisabledReason( |
| 91 | 97 | if (isBehind) { |
| 92 | 98 | return "Branch is behind upstream. Pull/rebase before pushing."; |
| 93 | 99 | } |
| 100 | if (!gitStatus.hasUpstream && !hasOriginRemote) { | |
| 101 | return 'Add an "origin" remote before pushing.'; | |
| 102 | } | |
| 94 | 103 | if (!isAhead) { |
| 95 | 104 | return "No local commits to push."; |
| 96 | 105 | } |
| ... | ... | @@ -106,6 +115,9 @@ function getMenuActionDisabledReason( |
| 106 | 115 | if (hasChanges) { |
| 107 | 116 | return "Commit local changes before creating a PR."; |
| 108 | 117 | } |
| 118 | if (!gitStatus.hasUpstream && !hasOriginRemote) { | |
| 119 | return 'Add an "origin" remote before creating a PR.'; | |
| 120 | } | |
| 109 | 121 | if (!isAhead) { |
| 110 | 122 | return "No local commits to include in a PR."; |
| 111 | 123 | } |
| ... | ... | @@ -154,6 +166,7 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions |
| 154 | 166 | const { data: branchList = null } = useQuery(gitBranchesQueryOptions(gitCwd)); |
| 155 | 167 | // Default to true while loading so we don't flash init controls. |
| 156 | 168 | const isRepo = branchList?.isRepo ?? true; |
| 169 | const hasOriginRemote = branchList?.hasOriginRemote ?? false; | |
| 157 | 170 | const currentBranch = branchList?.branches.find((branch) => branch.current)?.name ?? null; |
| 158 | 171 | const isGitStatusOutOfSync = |
| 159 | 172 | !!gitStatus?.branch && !!currentBranch && gitStatus.branch !== currentBranch; |
| ... | ... | @@ -184,12 +197,13 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions |
| 184 | 197 | }, [branchList?.branches, gitStatusForActions?.branch]); |
| 185 | 198 | |
| 186 | 199 | const gitActionMenuItems = useMemo( |
| 187 | () => buildMenuItems(gitStatusForActions, isGitActionRunning), | |
| 188 | [gitStatusForActions, isGitActionRunning], | |
| 200 | () => buildMenuItems(gitStatusForActions, isGitActionRunning, hasOriginRemote), | |
| 201 | [gitStatusForActions, hasOriginRemote, isGitActionRunning], | |
| 189 | 202 | ); |
| 190 | 203 | const quickAction = useMemo( |
| 191 | () => resolveQuickAction(gitStatusForActions, isGitActionRunning, isDefaultBranch), | |
| 192 | [gitStatusForActions, isDefaultBranch, isGitActionRunning], | |
| 204 | () => | |
| 205 | resolveQuickAction(gitStatusForActions, isGitActionRunning, isDefaultBranch, hasOriginRemote), | |
| 206 | [gitStatusForActions, hasOriginRemote, isDefaultBranch, isGitActionRunning], | |
| 193 | 207 | ); |
| 194 | 208 | const quickActionDisabledReason = quickAction.disabled |
| 195 | 209 | ? (quickAction.hint ?? "This action is currently unavailable.") |
| ... | ... | @@ -645,11 +659,12 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions |
| 645 | 659 | </MenuTrigger> |
| 646 | 660 | <MenuPopup align="end" className="w-full"> |
| 647 | 661 | {gitActionMenuItems.map((item) => { |
| 648 | const disabledReason = getMenuActionDisabledReason( | |
| 662 | const disabledReason = getMenuActionDisabledReason({ | |
| 649 | 663 | item, |
| 650 | gitStatusForActions, | |
| 651 | isGitActionRunning, | |
| 652 | ); | |
| 664 | gitStatus: gitStatusForActions, | |
| 665 | isBusy: isGitActionRunning, | |
| 666 | hasOriginRemote, | |
| 667 | }); | |
| 653 | 668 | if (item.disabled && disabledReason) { |
| 654 | 669 | return ( |
| 655 | 670 | <Popover key={`${item.id}-${item.label}`}> |
packages/contracts/src/git.ts+1| ... | ... | @@ -149,6 +149,7 @@ export type GitStatusResult = typeof GitStatusResult.Type; |
| 149 | 149 | export const GitListBranchesResult = Schema.Struct({ |
| 150 | 150 | branches: Schema.Array(GitBranch), |
| 151 | 151 | isRepo: Schema.Boolean, |
| 152 | hasOriginRemote: Schema.Boolean, | |
| 152 | 153 | }); |
| 153 | 154 | export type GitListBranchesResult = typeof GitListBranchesResult.Type; |
| 154 | 155 |