diff --git a/packages/workspace/src/core/file-utils.spec.ts b/packages/workspace/src/core/file-utils.spec.ts index aa6e734d7a..89585f6029 100644 --- a/packages/workspace/src/core/file-utils.spec.ts +++ b/packages/workspace/src/core/file-utils.spec.ts @@ -1,6 +1,8 @@ import { calculateFileChanges, WholeFileChange } from './file-utils'; import { DiffType, JsonChange, jsonDiff } from '../utils/json-diff'; +const ignore = require('ignore'); + describe('calculateFileChanges', () => { it('should return a whole file change by default', () => { const changes = calculateFileChanges( @@ -63,4 +65,18 @@ describe('calculateFileChanges', () => { } }); }); + + it('should ignore *.md changes', () => { + const ig = ignore(); + ig.add('*.md'); + const changes = calculateFileChanges( + ['proj/readme.md'], + undefined, + (path, revision) => { + return revision === 'sha1' ? '' : 'const a = 0;'; + }, + ig + ); + expect(changes.length).toEqual(0); + }); }); diff --git a/packages/workspace/src/core/file-utils.ts b/packages/workspace/src/core/file-utils.ts index dfa21d7190..d5bd364ab5 100644 --- a/packages/workspace/src/core/file-utils.ts +++ b/packages/workspace/src/core/file-utils.ts @@ -41,8 +41,12 @@ export function calculateFileChanges( readFileAtRevision: ( f: string, r: void | string - ) => string = defaultReadFileAtRevision + ) => string = defaultReadFileAtRevision, + ignore = getIgnoredGlobs() ): FileChange[] { + if (ignore) { + files = files.filter(f => !ignore.ignores(f)); + } return files.map(f => { const ext = extname(f); const _mtime = mtime(`${appRootPath}/${f}`);