|
|
@@ -511,6 +511,49 @@ test("circular symlinks", async () => {
|
|
|
})
|
|
|
})
|
|
|
|
|
|
+test("source project gitignore is respected - ignored files are not snapshotted", async () => {
|
|
|
+ await using tmp = await tmpdir({
|
|
|
+ git: true,
|
|
|
+ init: async (dir) => {
|
|
|
+ // Create gitignore BEFORE any tracking
|
|
|
+ await Filesystem.write(`${dir}/.gitignore`, "*.ignored\nbuild/\nnode_modules/\n")
|
|
|
+ await Filesystem.write(`${dir}/tracked.txt`, "tracked content")
|
|
|
+ await Filesystem.write(`${dir}/ignored.ignored`, "ignored content")
|
|
|
+ await $`mkdir -p ${dir}/build`.quiet()
|
|
|
+ await Filesystem.write(`${dir}/build/output.js`, "build output")
|
|
|
+ await Filesystem.write(`${dir}/normal.js`, "normal js")
|
|
|
+ await $`git add .`.cwd(dir).quiet()
|
|
|
+ await $`git commit -m init`.cwd(dir).quiet()
|
|
|
+ },
|
|
|
+ })
|
|
|
+
|
|
|
+ await Instance.provide({
|
|
|
+ directory: tmp.path,
|
|
|
+ fn: async () => {
|
|
|
+ const before = await Snapshot.track()
|
|
|
+ expect(before).toBeTruthy()
|
|
|
+
|
|
|
+ // Modify tracked files and create new ones - some ignored, some not
|
|
|
+ await Filesystem.write(`${tmp.path}/tracked.txt`, "modified tracked")
|
|
|
+ await Filesystem.write(`${tmp.path}/new.ignored`, "new ignored")
|
|
|
+ await Filesystem.write(`${tmp.path}/new-tracked.txt`, "new tracked")
|
|
|
+ await Filesystem.write(`${tmp.path}/build/new-build.js`, "new build file")
|
|
|
+
|
|
|
+ const patch = await Snapshot.patch(before!)
|
|
|
+
|
|
|
+ // Modified and new tracked files should be in snapshot
|
|
|
+ expect(patch.files).toContain(fwd(tmp.path, "new-tracked.txt"))
|
|
|
+ expect(patch.files).toContain(fwd(tmp.path, "tracked.txt"))
|
|
|
+
|
|
|
+ // Ignored files should NOT be in snapshot
|
|
|
+ expect(patch.files).not.toContain(fwd(tmp.path, "new.ignored"))
|
|
|
+ expect(patch.files).not.toContain(fwd(tmp.path, "ignored.ignored"))
|
|
|
+ expect(patch.files).not.toContain(fwd(tmp.path, "build/output.js"))
|
|
|
+ expect(patch.files).not.toContain(fwd(tmp.path, "build/new-build.js"))
|
|
|
+ },
|
|
|
+ })
|
|
|
+})
|
|
|
+
|
|
|
test("gitignore changes", async () => {
|
|
|
await using tmp = await bootstrap()
|
|
|
await Instance.provide({
|
|
|
@@ -535,6 +578,40 @@ test("gitignore changes", async () => {
|
|
|
})
|
|
|
})
|
|
|
|
|
|
+test("files tracked in snapshot but now gitignored are filtered out", async () => {
|
|
|
+ await using tmp = await bootstrap()
|
|
|
+ await Instance.provide({
|
|
|
+ directory: tmp.path,
|
|
|
+ fn: async () => {
|
|
|
+ // First, create a file and snapshot it
|
|
|
+ await Filesystem.write(`${tmp.path}/later-ignored.txt`, "initial content")
|
|
|
+ const before = await Snapshot.track()
|
|
|
+ expect(before).toBeTruthy()
|
|
|
+
|
|
|
+ // Modify the file (so it appears in diff-files)
|
|
|
+ await Filesystem.write(`${tmp.path}/later-ignored.txt`, "modified content")
|
|
|
+
|
|
|
+ // Now add gitignore that would exclude this file
|
|
|
+ await Filesystem.write(`${tmp.path}/.gitignore`, "later-ignored.txt\n")
|
|
|
+
|
|
|
+ // Also create another tracked file
|
|
|
+ await Filesystem.write(`${tmp.path}/still-tracked.txt`, "new tracked file")
|
|
|
+
|
|
|
+ const patch = await Snapshot.patch(before!)
|
|
|
+
|
|
|
+ // The file that is now gitignored should NOT appear, even though it was
|
|
|
+ // previously tracked and modified
|
|
|
+ expect(patch.files).not.toContain(fwd(tmp.path, "later-ignored.txt"))
|
|
|
+
|
|
|
+ // The gitignore file itself should appear
|
|
|
+ expect(patch.files).toContain(fwd(tmp.path, ".gitignore"))
|
|
|
+
|
|
|
+ // Other tracked files should appear
|
|
|
+ expect(patch.files).toContain(fwd(tmp.path, "still-tracked.txt"))
|
|
|
+ },
|
|
|
+ })
|
|
|
+})
|
|
|
+
|
|
|
test("git info exclude changes", async () => {
|
|
|
await using tmp = await bootstrap()
|
|
|
await Instance.provide({
|