core: fix unicode filename handling in snapshot diff by disabling quote escaping
This ensures unicode and special characters in filenames are displayed correctly when generating diff patches, allowing proper file detection and revert operations
This commit is contained in:
@@ -85,7 +85,7 @@ export namespace Snapshot {
|
|||||||
const git = gitdir()
|
const git = gitdir()
|
||||||
await $`git --git-dir ${git} --work-tree ${Instance.worktree} add .`.quiet().cwd(Instance.directory).nothrow()
|
await $`git --git-dir ${git} --work-tree ${Instance.worktree} add .`.quiet().cwd(Instance.directory).nothrow()
|
||||||
const result =
|
const result =
|
||||||
await $`git -c core.autocrlf=false --git-dir ${git} --work-tree ${Instance.worktree} diff --no-ext-diff --name-only ${hash} -- .`
|
await $`git -c core.autocrlf=false -c core.quotepath=false --git-dir ${git} --work-tree ${Instance.worktree} diff --no-ext-diff --name-only ${hash} -- .`
|
||||||
.quiet()
|
.quiet()
|
||||||
.cwd(Instance.directory)
|
.cwd(Instance.directory)
|
||||||
.nothrow()
|
.nothrow()
|
||||||
|
|||||||
@@ -266,23 +266,78 @@ test("unicode filenames", async () => {
|
|||||||
expect(before).toBeTruthy()
|
expect(before).toBeTruthy()
|
||||||
|
|
||||||
const unicodeFiles = [
|
const unicodeFiles = [
|
||||||
`${tmp.path}/文件.txt`,
|
{ path: `${tmp.path}/文件.txt`, content: "chinese content" },
|
||||||
`${tmp.path}/🚀rocket.txt`,
|
{ path: `${tmp.path}/🚀rocket.txt`, content: "emoji content" },
|
||||||
`${tmp.path}/café.txt`,
|
{ path: `${tmp.path}/café.txt`, content: "accented content" },
|
||||||
`${tmp.path}/файл.txt`,
|
{ path: `${tmp.path}/файл.txt`, content: "cyrillic content" },
|
||||||
]
|
]
|
||||||
|
|
||||||
for (const file of unicodeFiles) {
|
for (const file of unicodeFiles) {
|
||||||
await Bun.write(file, "unicode content")
|
await Bun.write(file.path, file.content)
|
||||||
}
|
}
|
||||||
|
|
||||||
const patch = await Snapshot.patch(before!)
|
const patch = await Snapshot.patch(before!)
|
||||||
// Note: git escapes unicode characters by default, so we just check that files are detected
|
|
||||||
// The actual filenames will be escaped like "caf\303\251.txt" but functionality works
|
|
||||||
expect(patch.files.length).toBe(4)
|
expect(patch.files.length).toBe(4)
|
||||||
|
|
||||||
// Skip revert test due to git filename escaping issues
|
for (const file of unicodeFiles) {
|
||||||
// The functionality works but git uses escaped filenames internally
|
expect(patch.files).toContain(file.path)
|
||||||
|
}
|
||||||
|
|
||||||
|
await Snapshot.revert([patch])
|
||||||
|
|
||||||
|
for (const file of unicodeFiles) {
|
||||||
|
expect(await Bun.file(file.path).exists()).toBe(false)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
test("unicode filenames modification and restore", async () => {
|
||||||
|
await using tmp = await bootstrap()
|
||||||
|
await Instance.provide({
|
||||||
|
directory: tmp.path,
|
||||||
|
fn: async () => {
|
||||||
|
const chineseFile = `${tmp.path}/文件.txt`
|
||||||
|
const cyrillicFile = `${tmp.path}/файл.txt`
|
||||||
|
|
||||||
|
await Bun.write(chineseFile, "original chinese")
|
||||||
|
await Bun.write(cyrillicFile, "original cyrillic")
|
||||||
|
|
||||||
|
const before = await Snapshot.track()
|
||||||
|
expect(before).toBeTruthy()
|
||||||
|
|
||||||
|
await Bun.write(chineseFile, "modified chinese")
|
||||||
|
await Bun.write(cyrillicFile, "modified cyrillic")
|
||||||
|
|
||||||
|
const patch = await Snapshot.patch(before!)
|
||||||
|
expect(patch.files).toContain(chineseFile)
|
||||||
|
expect(patch.files).toContain(cyrillicFile)
|
||||||
|
|
||||||
|
await Snapshot.revert([patch])
|
||||||
|
|
||||||
|
expect(await Bun.file(chineseFile).text()).toBe("original chinese")
|
||||||
|
expect(await Bun.file(cyrillicFile).text()).toBe("original cyrillic")
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
test("unicode filenames in subdirectories", async () => {
|
||||||
|
await using tmp = await bootstrap()
|
||||||
|
await Instance.provide({
|
||||||
|
directory: tmp.path,
|
||||||
|
fn: async () => {
|
||||||
|
const before = await Snapshot.track()
|
||||||
|
expect(before).toBeTruthy()
|
||||||
|
|
||||||
|
await $`mkdir -p "${tmp.path}/目录/подкаталог"`.quiet()
|
||||||
|
const deepFile = `${tmp.path}/目录/подкаталог/文件.txt`
|
||||||
|
await Bun.write(deepFile, "deep unicode content")
|
||||||
|
|
||||||
|
const patch = await Snapshot.patch(before!)
|
||||||
|
expect(patch.files).toContain(deepFile)
|
||||||
|
|
||||||
|
await Snapshot.revert([patch])
|
||||||
|
expect(await Bun.file(deepFile).exists()).toBe(false)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user