Skip to content

Commit

Permalink
Never ignore .gadget/ (#1667)
Browse files Browse the repository at this point in the history
  • Loading branch information
scott-rc authored Sep 21, 2024
1 parent 4aa48d1 commit 38210c3
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .changeset/never-ignore-gadget.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
ggt: patch
---

# Never ignore `.gadget/` directory

This change ensures that the `.gadget/` directory is never ignored even if it is listed in the `.ignore` file. The `.gadget/` directory is managed by ggt and ignoring it causes issues like infinite sync loops.
45 changes: 45 additions & 0 deletions spec/services/filesync/filesync.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1654,6 +1654,51 @@ describe("FileSync.sync", () => {
await expectLocalAndGadgetHashesMatch();
});

it("fetches .gadget/ files even if they are ignored", async () => {
const { filesync, expectDirs, expectLocalAndGadgetHashesMatch } = await makeSyncScenario({
filesVersion1Files: {
".gadget/client.js": "// client",
},
localFiles: {
".ignore": ".gadget/",
},
gadgetFiles: {
".gadget/client.js": "// client",
},
});

await filesync.merge(testCtx);

await expectDirs().resolves.toMatchInlineSnapshot(`
{
"filesVersionDirs": {
"1": {
".gadget/": "",
".gadget/client.js": "// client",
},
"2": {
".gadget/": "",
".gadget/client.js": "// client",
".ignore": ".gadget/",
},
},
"gadgetDir": {
".gadget/": "",
".gadget/client.js": "// client",
".ignore": ".gadget/",
},
"localDir": {
".gadget/": "",
".gadget/client.js": "// client",
".gadget/sync.json": "{"application":"test","environment":"development","environments":{"development":{"filesVersion":"2"}}}",
".ignore": ".gadget/",
},
}
`);

await expectLocalAndGadgetHashesMatch();
});

it("merges files when .gadget/sync.json doesn't exist and --allow-unknown-directory is passed", async () => {
const { filesync, expectDirs, expectLocalAndGadgetHashesMatch } = await makeSyncScenario({
args: makeArgs(
Expand Down
10 changes: 10 additions & 0 deletions src/services/filesync/directory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ import { Transform } from "node:stream";
import { pipeline } from "node:stream/promises";
import normalizePath from "normalize-path";

/**
* Paths that are never ignored, regardless of the contents of the `.ignore` file.
*/
export const NEVER_IGNORE_PATHS = [".gadget/"] as const;

/**
* Paths that are always ignored, regardless of the contents of the `.ignore` file.
*/
Expand Down Expand Up @@ -160,6 +165,11 @@ export class Directory {
return true;
}

if (NEVER_IGNORE_PATHS.some((neverIgnored) => filepath.startsWith(neverIgnored))) {
// special case for never ignored paths
return false;
}

return this._ignorer.ignores(filepath);
}

Expand Down

0 comments on commit 38210c3

Please sign in to comment.