Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion packages/app/src/pages/session.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,15 @@ export default function Page() {
? (details.properties as Record<string, unknown>)
: undefined
const file = typeof props?.file === "string" ? props.file : undefined
if (!file || file.startsWith(".git/")) return
if (!file) return
// .git is watched separately; rewrites of index (stage/commit) and HEAD
// (branch switch) change the VCS state the review panel renders, so refresh
// for those and skip the rest of .git
const segments = file.split(/[\\/]/)
if (segments.includes(".git")) {
const name = segments[segments.length - 1]
if (name !== "index" && name !== "HEAD") return
}
refreshVcs()
})
onCleanup(stopVcs)
Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/filesystem/watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,11 @@ const layer = Layer.effect(
const resolved = (yield* git.repo.discover(location.directory))?.gitDirectory
const vcs = resolved ? yield* fs.realPath(resolved).pipe(Effect.catch(() => Effect.succeed(resolved))) : undefined
if (vcs && !config.includes(".git") && !config.includes(vcs) && (!resolved || !config.includes(resolved))) {
// watch HEAD (branch switches) and index (staging/commits) so clients can
// refresh VCS state after out-of-band git commands; everything else under
// .git is noise
const ignore = (yield* fs.readDirectoryEntries(vcs).pipe(Effect.catch(() => Effect.succeed([])))).flatMap(
(entry) => (entry.name === "HEAD" ? [] : [entry.name]),
(entry) => (entry.name === "HEAD" || entry.name === "index" ? [] : [entry.name]),
)
yield* Effect.forkScoped(subscribe(vcs, ignore))
}
Expand Down
29 changes: 22 additions & 7 deletions packages/core/test/filesystem/watcher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,19 +197,34 @@ describeWatcher("Watcher", () => {
}).pipe(Effect.provide(AppNodeBuilder.build(LayerNode.group([FSUtil.node, EventV2.node])))),
)

it.live("ignores .git/index changes", () =>
it.live("publishes .git/index events", () =>
withTmp(
(directory) =>
Effect.gen(function* () {
const fs = yield* FSUtil.Service
const index = path.join(directory, ".git", "index")
yield* ready(directory)
yield* noUpdate(
(event) => event.file === index,
fs
.writeFileString(path.join(directory, "tracked.txt"), "a")
.pipe(Effect.andThen(Effect.promise(() => $`git add .`.cwd(directory).quiet())), Effect.asVoid),
)
expect(
yield* nextUpdate(
(event) => event.file === index,
fs
.writeFileString(path.join(directory, "tracked.txt"), "a")
.pipe(Effect.andThen(Effect.promise(() => $`git add .`.cwd(directory).quiet())), Effect.asVoid),
),
).toMatchObject({ file: index })
}),
{ git: true },
),
)

it.live("ignores other .git changes", () =>
withTmp(
(directory) =>
Effect.gen(function* () {
const fs = yield* FSUtil.Service
const msg = path.join(directory, ".git", "COMMIT_EDITMSG")
yield* ready(directory)
yield* noUpdate((event) => event.file === msg, fs.writeFileString(msg, "test"))
}),
{ git: true },
),
Expand Down
Loading