GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — core: fix unicode filename handling in snapshot diff by disabling quo… · bpd1069/opencode@32e6bca

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/opencode
    • src/snapshot
      • index.ts
    • test/snapshot
      • snapshot.test.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/opencode/src/snapshot/index.ts‎

Copy file name to clipboardExpand all lines: packages/opencode/src/snapshot/index.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export namespace Snapshot {
8585
const git = gitdir()
8686
await $`git --git-dir ${git} --work-tree ${Instance.worktree} add .`.quiet().cwd(Instance.directory).nothrow()
8787
const result =
88-
await $`git -c core.autocrlf=false --git-dir ${git} --work-tree ${Instance.worktree} diff --no-ext-diff --name-only ${hash} -- .`
88+
await $`git -c core.autocrlf=false -c core.quotepath=false --git-dir ${git} --work-tree ${Instance.worktree} diff --no-ext-diff --name-only ${hash} -- .`
8989
.quiet()
9090
.cwd(Instance.directory)
9191
.nothrow()
Collapse file

‎packages/opencode/test/snapshot/snapshot.test.ts‎

Copy file name to clipboardExpand all lines: packages/opencode/test/snapshot/snapshot.test.ts
+64-9Lines changed: 64 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -266,23 +266,78 @@ test("unicode filenames", async () => {
266266
expect(before).toBeTruthy()
267267

268268
const unicodeFiles = [
269-
`${tmp.path}/文件.txt`,
270-
`${tmp.path}/🚀rocket.txt`,
271-
`${tmp.path}/café.txt`,
272-
`${tmp.path}/файл.txt`,
269+
{ path: `${tmp.path}/文件.txt`, content: "chinese content" },
270+
{ path: `${tmp.path}/🚀rocket.txt`, content: "emoji content" },
271+
{ path: `${tmp.path}/café.txt`, content: "accented content" },
272+
{ path: `${tmp.path}/файл.txt`, content: "cyrillic content" },
273273
]
274274

275275
for (const file of unicodeFiles) {
276-
await Bun.write(file, "unicode content")
276+
await Bun.write(file.path, file.content)
277277
}
278278

279279
const patch = await Snapshot.patch(before!)
280-
// Note: git escapes unicode characters by default, so we just check that files are detected
281-
// The actual filenames will be escaped like "caf\303\251.txt" but functionality works
282280
expect(patch.files.length).toBe(4)
283281

284-
// Skip revert test due to git filename escaping issues
285-
// The functionality works but git uses escaped filenames internally
282+
for (const file of unicodeFiles) {
283+
expect(patch.files).toContain(file.path)
284+
}
285+
286+
await Snapshot.revert([patch])
287+
288+
for (const file of unicodeFiles) {
289+
expect(await Bun.file(file.path).exists()).toBe(false)
290+
}
291+
},
292+
})
293+
})
294+
295+
test("unicode filenames modification and restore", async () => {
296+
await using tmp = await bootstrap()
297+
await Instance.provide({
298+
directory: tmp.path,
299+
fn: async () => {
300+
const chineseFile = `${tmp.path}/文件.txt`
301+
const cyrillicFile = `${tmp.path}/файл.txt`
302+
303+
await Bun.write(chineseFile, "original chinese")
304+
await Bun.write(cyrillicFile, "original cyrillic")
305+
306+
const before = await Snapshot.track()
307+
expect(before).toBeTruthy()
308+
309+
await Bun.write(chineseFile, "modified chinese")
310+
await Bun.write(cyrillicFile, "modified cyrillic")
311+
312+
const patch = await Snapshot.patch(before!)
313+
expect(patch.files).toContain(chineseFile)
314+
expect(patch.files).toContain(cyrillicFile)
315+
316+
await Snapshot.revert([patch])
317+
318+
expect(await Bun.file(chineseFile).text()).toBe("original chinese")
319+
expect(await Bun.file(cyrillicFile).text()).toBe("original cyrillic")
320+
},
321+
})
322+
})
323+
324+
test("unicode filenames in subdirectories", async () => {
325+
await using tmp = await bootstrap()
326+
await Instance.provide({
327+
directory: tmp.path,
328+
fn: async () => {
329+
const before = await Snapshot.track()
330+
expect(before).toBeTruthy()
331+
332+
await $`mkdir -p "${tmp.path}/目录/подкаталог"`.quiet()
333+
const deepFile = `${tmp.path}/目录/подкаталог/文件.txt`
334+
await Bun.write(deepFile, "deep unicode content")
335+
336+
const patch = await Snapshot.patch(before!)
337+
expect(patch.files).toContain(deepFile)
338+
339+
await Snapshot.revert([patch])
340+
expect(await Bun.file(deepFile).exists()).toBe(false)
286341
},
287342
})
288343
})

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.