GeezerVison is showing github.com — fix(git): the commit button shows the right action and waits for the … · pingdotgg/t3code@82580b5
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/threads/ThreadGitControls.tsx +27-2Lines changed: 27 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import { useAtomValue } from "@effect/atom-react"; | 1 | 2 | import * as Dialog from "../../components/ui/Dialog"; | 2 | 3 | import { useOpenPullRequest } from "../../native/useOpenPullRequest"; | 3 | 4 | import type { AppBarMenu } from "../../components/ui/AppBar.types"; | @@ -10,6 +11,7 @@ import { | 10 | 11 | type VcsStatusResult, | 11 | 12 | } from "@t3tools/contracts"; | 12 | 13 | import { | | 14 | + CANCEL_QUEUED_QUICK_ACTION, | 13 | 15 | type GitActionRequestInput, | 14 | 16 | requiresDefaultBranchConfirmation, | 15 | 17 | resolveQuickAction, | @@ -18,6 +20,8 @@ import { useNavigation } from "@react-navigation/native"; | 18 | 20 | import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients"; | 19 | 21 |
| 20 | 22 | import { useEnvironmentScope } from "../../state/session"; | | 23 | +import { gitActionQueue } from "../../state/vcs"; | | 24 | +import { confirmCommitDuringRun } from "./git/confirmCommitDuringRun"; | 21 | 25 | import { PullRequestGlyph } from "../pull-requests/pullRequestGlyphs"; | 22 | 26 | import { | 23 | 27 | basename, | @@ -119,7 +123,14 @@ function useThreadGitControlModel(props: ThreadGitMenuProps) { | 119 | 123 | const hasPrimaryRemote = gitStatus?.hasPrimaryRemote ?? false; | 120 | 124 | const isDefaultRef = gitStatus?.isDefaultRef ?? false; | 121 | 125 |
| | 126 | + const threadRef = { | | 127 | + environmentId: EnvironmentId.make(String(environmentId)), | | 128 | + threadId: ThreadId.make(String(threadId)), | | 129 | + }; | | 130 | + const queuedGitAction = useAtomValue(gitActionQueue.queuedActionAtom(threadRef)); | | 131 | + | 122 | 132 | const quickAction = (() => { | | 133 | + if (queuedGitAction !== null) return CANCEL_QUEUED_QUICK_ACTION; | 123 | 134 | if (!isRepo) { | 124 | 135 | return { | 125 | 136 | label: "Git unavailable", | @@ -169,14 +180,24 @@ function useThreadGitControlModel(props: ThreadGitMenuProps) { | 169 | 180 |
| 170 | 181 | const runActionWithPrompt = async (input: GitActionRequestInput) => { | 171 | 182 | if (!canWriteSourceControl) return; | | 183 | + const branchName = gitStatus?.refName; | | 184 | + const request = { ...input, ...(branchName ? { expectedRefName: branchName } : {}) }; | | 185 | + const decision = await confirmCommitDuringRun({ | | 186 | + thread: threadRef, | | 187 | + action: input.action, | | 188 | + hasChanges: gitStatus?.hasWorkingTreeChanges === true, | | 189 | + queuedRun: requiresDefaultBranchConfirmation(input.action, isDefaultRef) | | 190 | + ? null | | 191 | + : () => void onRunAction(request), | | 192 | + }); | | 193 | + if (decision !== "proceed") return; | 172 | 194 | const confirmableAction = | 173 | 195 | input.action === "push" || | 174 | 196 | input.action === "create_pr" || | 175 | 197 | input.action === "commit_push" || | 176 | 198 | input.action === "commit_push_pr" | 177 | 199 | ? input.action | 178 | 200 | : null; | 179 | | - const branchName = gitStatus?.refName; | 180 | 201 | if ( | 181 | 202 | branchName && | 182 | 203 | confirmableAction && | @@ -200,11 +221,15 @@ function useThreadGitControlModel(props: ThreadGitMenuProps) { | 200 | 221 | return; | 201 | 222 | } | 202 | 223 |
| 203 | | - await onRunAction(input); | | 224 | + await onRunAction(request); | 204 | 225 | }; | 205 | 226 |
| 206 | 227 | const runQuickAction = async () => { | 207 | 228 | if (quickAction.disabled) return; | | 229 | + if (quickAction.kind === "cancel_queued") { | | 230 | + gitActionQueue.cancel(threadRef); | | 231 | + return; | | 232 | + } | 208 | 233 | if (quickAction.kind === "open_pr") { | 209 | 234 | await openExistingPr(); | 210 | 235 | return; | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/threads/git/GitCommitSheet.tsx +18-3Lines changed: 18 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -12,6 +12,7 @@ import { AppText as Text, AppTextInput as TextInput } from "../../../components/ | 12 | 12 | import { cn } from "../../../lib/cn"; | 13 | 13 | import { useEnvironmentQuery } from "../../../state/query"; | 14 | 14 | import { useThreadSelection } from "../../../state/use-thread-selection"; | | 15 | +import { confirmCommitDuringRun } from "./confirmCommitDuringRun"; | 15 | 16 | import { useSelectedThreadGitActions } from "../../../state/use-selected-thread-git-actions"; | 16 | 17 | import { useSelectedThreadGitState } from "../../../state/use-selected-thread-git-state"; | 17 | 18 | import { useSelectedThreadWorktree } from "../../../state/use-selected-thread-worktree"; | @@ -57,13 +58,27 @@ export function GitCommitSheet(_props: GitCommitSheetProps) { | 57 | 58 | const runCommitAction = async (featureBranch: boolean) => { | 58 | 59 | if (!canWriteSourceControl || (featureBranch && !canChangeThreadBranch)) return; | 59 | 60 | const commitMessage = dialogCommitMessage.trim(); | 60 | | - navigation.goBack(); | 61 | | - await gitActions.onRunSelectedThreadGitAction({ | 62 | | - action: "commit", | | 61 | + const refName = gitStatus.data?.refName; | | 62 | + const request = { | | 63 | + action: "commit" as const, | 63 | 64 | featureBranch, | | 65 | + ...(refName ? { expectedRefName: refName } : {}), | 64 | 66 | ...(commitMessage ? { commitMessage } : {}), | 65 | 67 | ...(!allSelected ? { filePaths: selectedFiles.map((file) => file.path) } : {}), | | 68 | + }; | | 69 | + const decision = await confirmCommitDuringRun({ | | 70 | + thread: | | 71 | + selectedThread === null | | 72 | + ? null | | 73 | + : { environmentId: selectedThread.environmentId, threadId: selectedThread.id }, | | 74 | + action: "commit", | | 75 | + hasChanges: true, | | 76 | + queuedRun: () => void gitActions.onRunSelectedThreadGitAction(request), | 66 | 77 | }); | | 78 | + if (decision === "cancelled") return; | | 79 | + navigation.goBack(); | | 80 | + if (decision === "queued") return; | | 81 | + await gitActions.onRunSelectedThreadGitAction(request); | 67 | 82 | }; | 68 | 83 |
| 69 | 84 | const android = Platform.OS === "android"; | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/threads/git/GitConfirmSheet.tsx +7-1Lines changed: 7 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -70,6 +70,7 @@ export function GitConfirmSheet(props: GitConfirmSheetProps) { | 70 | 70 | navigation.dispatch(StackActions.replace("Thread", { environmentId, threadId })); | 71 | 71 | await gitActions.onRunSelectedThreadGitAction({ | 72 | 72 | action: confirmAction, | | 73 | + ...(branchName ? { expectedRefName: branchName } : {}), | 73 | 74 | ...(params.commitMessage ? { commitMessage: params.commitMessage } : {}), | 74 | 75 | ...(params.filePaths ? { filePaths: params.filePaths.split(",") } : {}), | 75 | 76 | }); | @@ -83,6 +84,7 @@ export function GitConfirmSheet(props: GitConfirmSheetProps) { | 83 | 84 | await gitActions.onRunSelectedThreadGitAction({ | 84 | 85 | action: confirmAction, | 85 | 86 | featureBranch: true, | | 87 | + ...(branchName ? { expectedRefName: branchName } : {}), | 86 | 88 | ...(params.commitMessage ? { commitMessage: params.commitMessage } : {}), | 87 | 89 | ...(params.filePaths ? { filePaths: params.filePaths.split(",") } : {}), | 88 | 90 | }); | @@ -101,8 +103,12 @@ export function GitConfirmSheet(props: GitConfirmSheetProps) { | 101 | 103 | ); | 102 | 104 | const created = await gitActions.onCreateSelectedThreadBranch(newBranchName); | 103 | 105 | if (created === null) return; | 104 | | - await gitActions.onRunSelectedThreadGitAction({ action: confirmAction }); | | 106 | + await gitActions.onRunSelectedThreadGitAction({ | | 107 | + action: confirmAction, | | 108 | + expectedRefName: newBranchName, | | 109 | + }); | 105 | 110 | }, [ | | 111 | + branchName, | 106 | 112 | canChangeThreadBranch, | 107 | 113 | confirmAction, | 108 | 114 | gitActions, | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/threads/git/GitOverviewSheet.tsx +23-4Lines changed: 23 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -32,6 +32,7 @@ import { useSelectedThreadGitActions } from "../../../state/use-selected-thread- | 32 | 32 | import { useSelectedThreadGitState } from "../../../state/use-selected-thread-git-state"; | 33 | 33 | import { useSelectedThreadWorktree } from "../../../state/use-selected-thread-worktree"; | 34 | 34 | import { vcsEnvironment } from "../../../state/vcs"; | | 35 | +import { confirmCommitDuringRun } from "./confirmCommitDuringRun"; | 35 | 36 | import { menuItemIconName, statusSummary } from "./gitSheetComponents"; | 36 | 37 | import { | 37 | 38 | LinkedPullRequestRow, | @@ -137,16 +138,35 @@ function GitOverviewSheetContent(props: GitOverviewSheetProps) { | 137 | 138 | } | 138 | 139 | }; | 139 | 140 |
| | 141 | + const closeSheet = () => { | | 142 | + if (!isInspector) navigation.goBack(); | | 143 | + else closeInspectorSheet?.(); | | 144 | + }; | | 145 | + | 140 | 146 | const runActionWithPrompt = async (input: GitActionRequestInput) => { | 141 | 147 | if (!canWriteSourceControl) return; | | 148 | + const branchName = gitStatus.data?.refName; | | 149 | + const request = { ...input, ...(branchName ? { expectedRefName: branchName } : {}) }; | | 150 | + const decision = await confirmCommitDuringRun({ | | 151 | + thread: { environmentId, threadId }, | | 152 | + action: input.action, | | 153 | + hasChanges: gitStatus.data?.hasWorkingTreeChanges === true, | | 154 | + queuedRun: requiresDefaultBranchConfirmation(input.action, isDefaultRef) | | 155 | + ? null | | 156 | + : () => void gitActions.onRunSelectedThreadGitAction(request), | | 157 | + }); | | 158 | + if (decision === "cancelled") return; | | 159 | + if (decision === "queued") { | | 160 | + closeSheet(); | | 161 | + return; | | 162 | + } | 142 | 163 | const confirmableAction = | 143 | 164 | input.action === "push" || | 144 | 165 | input.action === "create_pr" || | 145 | 166 | input.action === "commit_push" || | 146 | 167 | input.action === "commit_push_pr" | 147 | 168 | ? input.action | 148 | 169 | : null; | 149 | | - const branchName = gitStatus.data?.refName; | 150 | 170 | if ( | 151 | 171 | branchName && | 152 | 172 | confirmableAction && | @@ -168,9 +188,8 @@ function GitOverviewSheetContent(props: GitOverviewSheetProps) { | 168 | 188 | } | 169 | 189 |
| 170 | 190 | // Close a sheet so the thread shows the action's progress. | 171 | | - if (!isInspector) navigation.goBack(); | 172 | | - else closeInspectorSheet?.(); | 173 | | - await gitActions.onRunSelectedThreadGitAction(input); | | 191 | + closeSheet(); | | 192 | + await gitActions.onRunSelectedThreadGitAction(request); | 174 | 193 | }; | 175 | 194 |
| 176 | 195 | const onPressMenuItem = async (item: (typeof menuItems)[number]) => { | |
Collapse file Copy file name to clipboard +53Lines changed: 53 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import { threadRuntimeIsActive } from "@t3tools/client-runtime/state/shell"; | | 2 | +import { | | 3 | + ACTIVE_RUN_COMMIT_COPY, | | 4 | + QUEUED_COMMIT_DROPPED_COPY, | | 5 | + requiresActiveRunConfirmation, | | 6 | +} from "@t3tools/client-runtime/state/vcs"; | | 7 | +import type { GitStackedAction, ScopedThreadRef } from "@t3tools/contracts"; | | 8 | + | | 9 | +import * as Dialog from "../../../components/ui/Dialog"; | | 10 | +import { appAtomRegistry } from "../../../state/atom-registry"; | | 11 | +import { environmentThreadShells } from "../../../state/threads"; | | 12 | +import { gitActionQueue } from "../../../state/vcs"; | | 13 | + | | 14 | +export function confirmCommitDuringRun(input: { | | 15 | + readonly thread: ScopedThreadRef | null; | | 16 | + readonly action: GitStackedAction; | | 17 | + readonly hasChanges: boolean; | | 18 | + readonly queuedRun: (() => void) | null; | | 19 | +}): Promise<"proceed" | "queued" | "cancelled"> { | | 20 | + const { thread, queuedRun } = input; | | 21 | + // A native menu keeps the closure from when it opened, and a run can start while it is open. | | 22 | + const shell = | | 23 | + thread === null ? null : appAtomRegistry.get(environmentThreadShells.threadShellAtom(thread)); | | 24 | + const isThreadRunning = threadRuntimeIsActive(shell?.runtime); | | 25 | + if (!requiresActiveRunConfirmation(input.action, isThreadRunning, input.hasChanges)) { | | 26 | + return Promise.resolve("proceed"); | | 27 | + } | | 28 | + return new Promise((resolve) => { | | 29 | + Dialog.alert(ACTIVE_RUN_COMMIT_COPY.title, ACTIVE_RUN_COMMIT_COPY.description, [ | | 30 | + ...(thread !== null && queuedRun !== null | | 31 | + ? [ | | 32 | + { | | 33 | + text: ACTIVE_RUN_COMMIT_COPY.queueLabel, | | 34 | + onPress: () => { | | 35 | + gitActionQueue.enqueue(thread, { | | 36 | + action: input.action, | | 37 | + run: queuedRun, | | 38 | + onDropped: () => | | 39 | + Dialog.alert( | | 40 | + QUEUED_COMMIT_DROPPED_COPY.title, | | 41 | + QUEUED_COMMIT_DROPPED_COPY.description, | | 42 | + ), | | 43 | + }); | | 44 | + resolve("queued"); | | 45 | + }, | | 46 | + }, | | 47 | + ] | | 48 | + : []), | | 49 | + { text: ACTIVE_RUN_COMMIT_COPY.continueLabel, onPress: () => resolve("proceed") }, | | 50 | + { text: "Cancel", style: "cancel", onPress: () => resolve("cancelled") }, | | 51 | + ]); | | 52 | + }); | | 53 | +} |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/state/use-selected-thread-git-actions.ts +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -368,6 +368,7 @@ export function useSelectedThreadGitActions() { | 368 | 368 | actionId, | 369 | 369 | action: input.action, | 370 | 370 | ...(input.commitMessage ? { commitMessage: input.commitMessage } : {}), | | 371 | + ...(input.expectedRefName ? { expectedRefName: input.expectedRefName } : {}), | 371 | 372 | ...(input.featureBranch ? { featureBranch: input.featureBranch } : {}), | 372 | 373 | ...(input.filePaths?.length ? { filePaths: [...input.filePaths] } : {}), | 373 | 374 | threadId: thread.id, | |
Collapse file Copy file name to clipboard +7Lines changed: 7 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import { | | 2 | + createGitActionQueue, | 2 | 3 | createVcsActionManager, | 3 | 4 | createVcsEnvironmentAtoms, | 4 | 5 | } from "@t3tools/client-runtime/state/vcs"; | 5 | 6 |
| 6 | 7 | import { connectionAtomRuntime } from "../connection/runtime"; | | 8 | +import { appAtomRegistry } from "./atom-registry"; | | 9 | +import { environmentThreadShells } from "./threads"; | 7 | 10 |
| 8 | 11 | export const vcsEnvironment = createVcsEnvironmentAtoms(connectionAtomRuntime); | 9 | 12 | export const vcsActionManager = createVcsActionManager(connectionAtomRuntime); | | 13 | +export const gitActionQueue = createGitActionQueue({ | | 14 | + registry: appAtomRegistry, | | 15 | + threadShellAtom: environmentThreadShells.threadShellAtom, | | 16 | +}); |
|