Skip to content

Commit 67c9631

Browse files
authored
Merge pull request #245 from OpenKnots/feature/pull-main-before-thread
Prompt to pull behind branches before starting threads
2 parents 47540ec + c111973 commit 67c9631

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

apps/web/src/components/BranchToolbar.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import type { ThreadId } from "@okcode/contracts";
22
import { ArrowDownIcon, FolderIcon, GitForkIcon, LoaderIcon } from "lucide-react";
3-
import { useCallback } from "react";
3+
import { useCallback, useEffect } from "react";
44
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
55

6-
import { gitPullMutationOptions, gitStatusQueryOptions, invalidateGitQueries } from "../lib/gitReactQuery";
6+
import { gitPullMutationOptions, gitQueryKeys, gitStatusQueryOptions, invalidateGitQueries } from "../lib/gitReactQuery";
77
import { newCommandId } from "../lib/utils";
88
import { readNativeApi } from "../nativeApi";
99
import { useComposerDraftStore } from "../composerDraftStore";
@@ -121,6 +121,13 @@ export default function BranchToolbar({
121121
const isBehindUpstream = behindCount > 0 && !hasServerThread;
122122
const pullMutation = useMutation(gitPullMutationOptions({ cwd: gitCwd, queryClient }));
123123

124+
// Force a fresh git-status fetch when a draft thread mounts so we catch
125+
// upstream changes immediately instead of waiting for the next poll cycle.
126+
useEffect(() => {
127+
if (hasServerThread || !gitCwd) return;
128+
void queryClient.invalidateQueries({ queryKey: gitQueryKeys.status(gitCwd) });
129+
}, [hasServerThread, gitCwd, queryClient]);
130+
124131
const handlePull = useCallback(() => {
125132
if (pullMutation.isPending) return;
126133
const promise = pullMutation.mutateAsync();

0 commit comments

Comments
 (0)