|
|
@@ -749,6 +749,52 @@ test("revert preserves file that existed in snapshot when deleted then recreated
|
|
|
})
|
|
|
})
|
|
|
|
|
|
+test("diffFull sets status based on git change type", async () => {
|
|
|
+ await using tmp = await bootstrap()
|
|
|
+ await Instance.provide({
|
|
|
+ directory: tmp.path,
|
|
|
+ fn: async () => {
|
|
|
+ await Bun.write(`${tmp.path}/grow.txt`, "one\n")
|
|
|
+ await Bun.write(`${tmp.path}/trim.txt`, "line1\nline2\n")
|
|
|
+ await Bun.write(`${tmp.path}/delete.txt`, "gone")
|
|
|
+
|
|
|
+ const before = await Snapshot.track()
|
|
|
+ expect(before).toBeTruthy()
|
|
|
+
|
|
|
+ await Bun.write(`${tmp.path}/grow.txt`, "one\ntwo\n")
|
|
|
+ await Bun.write(`${tmp.path}/trim.txt`, "line1\n")
|
|
|
+ await $`rm ${tmp.path}/delete.txt`.quiet()
|
|
|
+ await Bun.write(`${tmp.path}/added.txt`, "new")
|
|
|
+
|
|
|
+ const after = await Snapshot.track()
|
|
|
+ expect(after).toBeTruthy()
|
|
|
+
|
|
|
+ const diffs = await Snapshot.diffFull(before!, after!)
|
|
|
+ expect(diffs.length).toBe(4)
|
|
|
+
|
|
|
+ const added = diffs.find((d) => d.file === "added.txt")
|
|
|
+ expect(added).toBeDefined()
|
|
|
+ expect(added!.status).toBe("added")
|
|
|
+
|
|
|
+ const deleted = diffs.find((d) => d.file === "delete.txt")
|
|
|
+ expect(deleted).toBeDefined()
|
|
|
+ expect(deleted!.status).toBe("deleted")
|
|
|
+
|
|
|
+ const grow = diffs.find((d) => d.file === "grow.txt")
|
|
|
+ expect(grow).toBeDefined()
|
|
|
+ expect(grow!.status).toBe("modified")
|
|
|
+ expect(grow!.additions).toBeGreaterThan(0)
|
|
|
+ expect(grow!.deletions).toBe(0)
|
|
|
+
|
|
|
+ const trim = diffs.find((d) => d.file === "trim.txt")
|
|
|
+ expect(trim).toBeDefined()
|
|
|
+ expect(trim!.status).toBe("modified")
|
|
|
+ expect(trim!.additions).toBe(0)
|
|
|
+ expect(trim!.deletions).toBeGreaterThan(0)
|
|
|
+ },
|
|
|
+ })
|
|
|
+})
|
|
|
+
|
|
|
test("diffFull with new file additions", async () => {
|
|
|
await using tmp = await bootstrap()
|
|
|
await Instance.provide({
|