Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 65 additions & 9 deletions packages/eas-cli/src/vcs/__tests__/local-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,32 @@ describe(Ignore, () => {
const ignore = await Ignore.createForCopyingAsync('/root');
expect(ignore.ignores('.git')).toBe(true);
});

it('applies ignore rules from .gitignore files in dot-directories', async () => {
vol.fromJSON(
{
'.eas/.gitignore': 'secrets.txt\n',
},
'/root'
);

const ignore = await Ignore.createForCopyingAsync('/root');
expect(ignore.ignores('.eas/secrets.txt')).toBe(true);
expect(ignore.ignores('.eas/other.txt')).toBe(false);
});

it('does not throw an error if there is a trailing backslash in the gitignore', async () => {
vol.fromJSON(
{
'.gitignore': 'dir\\',
},
'/root'
);

const ignore = await Ignore.createForCopyingAsync('/root');
expect(() => ignore.ignores('dir/test')).not.toThrowError();
});

describe('for checking', () => {
it('does not necessarily ignore .git', async () => {
vol.fromJSON({}, '/root');
Expand All @@ -100,15 +126,45 @@ describe(Ignore, () => {
});
});

it('does not throw an error if there is a trailing backslash in the gitignore', async () => {
vol.fromJSON(
{
'.gitignore': 'dir\\',
},
'/root'
);
describe('negation patterns', () => {
it('does not ignore a path negated by a directory pattern in the same .gitignore', async () => {
vol.fromJSON(
{
'.gitignore': '.eas/*\n!.eas/build/\n',
},
'/root'
);

const ignore = await Ignore.createForCopyingAsync('/root');
expect(() => ignore.ignores('dir/test')).not.toThrowError();
const ignore = await Ignore.createForCopyingAsync('/root');
expect(ignore.ignores('.eas/build/')).toBe(false);
expect(ignore.ignores('.eas/build/foo.txt')).toBe(false);
expect(ignore.ignores('.eas/other/')).toBe(true);
expect(ignore.ignores('.eas/other.txt')).toBe(true);
});

it('ignores a file inside a directory matched by a glob with no negation', async () => {
vol.fromJSON(
{
'.gitignore': '.eas/*\n',
},
'/root'
);

const ignore = await Ignore.createForCopyingAsync('/root');
expect(ignore.ignores('.eas/build/foo.txt')).toBe(true);
});

it('does not un-ignore a file whose name matches a directory negation pattern', async () => {
vol.fromJSON(
{
'.gitignore': 'build\n!build/\n',
},
'/root'
);

const ignore = await Ignore.createForCopyingAsync('/root');
expect(ignore.ignores('build')).toBe(true);
expect(ignore.ignores('build/')).toBe(false);
});
});
});
17 changes: 12 additions & 5 deletions packages/eas-cli/src/vcs/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ node_modules
cwd: this.rootDir,
ignore: ['node_modules'],
followSymbolicLinks: false,
dot: true,
})
)
// ensure that parent dir is before child directories
Expand All @@ -84,12 +85,15 @@ node_modules
}

public ignores(relativePath: string): boolean {
let ignored = false;
for (const [prefix, ignore] of this.ignoreMapping) {
if (relativePath.startsWith(prefix) && ignore.ignores(relativePath.slice(prefix.length))) {
return true;
}
if (!relativePath.startsWith(prefix)) continue;
const slicedPath = relativePath.slice(prefix.length);
const result = ignore.test(slicedPath);
if (result.ignored) ignored = true;
else if (result.unignored) ignored = false;
}
return false;
return ignored;
}
}

Expand All @@ -115,7 +119,10 @@ export async function makeShallowCopyAsync(_src: string, dst: string): Promise<v
return true;
}
const relativePath = path.relative(src, srcFilePath);
const shouldCopyTheItem = !ignore.ignores(relativePath);

// Append a trailing slash for directories so patterns like !dir/ match correctly.
const isDirectory = fsExtra.lstatSync(srcFilePath).isDirectory();
const shouldCopyTheItem = !ignore.ignores(isDirectory ? `${relativePath}/` : relativePath);

Log.debug(shouldCopyTheItem ? 'copying' : 'skipping', {
src,
Expand Down
Loading