Skip to content

Commit

Permalink
feat: add env var to skip moved file detection
Browse files Browse the repository at this point in the history
  • Loading branch information
iowillhoit committed May 6, 2024
1 parent fe52fe5 commit 73a70fd
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/shared/localShadowRepo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ export class ShadowRepo {
});

// Check for moved files and update local git status accordingly
await this.detectMovedFiles();
if (env.getBoolean('SF_DISABLE_MOVED_FILE_DETECTION') !== true) {
await this.detectMovedFiles();
}
} catch (e) {
redirectToCliRepoError(e);
}
Expand Down
45 changes: 45 additions & 0 deletions test/unit/localDetectMovedFiles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,51 @@ describe('local detect moved files', () => {
}
});

it('skips moved file detection if env var is set', async () => {
let projectDir!: string;
try {
projectDir = fs.mkdtempSync(path.join(os.tmpdir(), 'localShadowRepoTest'));
fs.mkdirSync(path.join(projectDir, 'force-app', 'new'), { recursive: true });
fs.writeFileSync(path.join(projectDir, 'force-app', 'CustomLabels.labels-meta.xml'), '<xml></xml>');

const shadowRepo: ShadowRepo = await ShadowRepo.getInstance({
orgId: '00D456789012345',
projectPath: projectDir,
packageDirs: [
{
name: 'dummy',
fullPath: path.join(projectDir, 'force-app'),
path: path.join(projectDir, 'force-app'),
},
],
});

const gitAdd = sinon.spy(git, 'add');

// Manually commit this first file
const labelsFile = path.join('force-app', 'CustomLabels.labels-meta.xml');
const sha = await shadowRepo.commitChanges({ deployedFiles: [labelsFile] });
expect(sha).to.not.be.empty;
expect(gitAdd.calledOnce).to.be.true;

// Move the file and refresh the status
fs.renameSync(
path.join(projectDir, labelsFile),
path.join(projectDir, 'force-app', 'new', 'CustomLabels.labels-meta.xml')
);

process.env.SF_DISABLE_MOVED_FILE_DETECTION = 'true';
await shadowRepo.getStatus(true);

// Moved file should NOT have been detected and committed
expect(gitAdd.calledTwice).to.be.false;
expect(await shadowRepo.getChangedRows()).to.have.lengthOf(2);
} finally {
delete process.env.SF_DISABLE_MOVED_FILE_DETECTION;
if (projectDir) await fs.promises.rm(projectDir, { recursive: true });
}
});

it('ignores moved files if multiple matches are found', async () => {
let projectDir!: string;

Expand Down

0 comments on commit 73a70fd

Please sign in to comment.