Skip to content

Commit

Permalink
fix: support pkgDir with ./foo
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Mar 23, 2022
1 parent 68456a2 commit 3b46454
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/shared/localShadowRepo.ts
Expand Up @@ -116,10 +116,13 @@ export class ShadowRepo {
if (!this.status || noCache) {
// only ask about OS once but use twice
const isWindows = os.type() === 'Windows_NT';
const filepaths = isWindows
? // iso-git uses posix paths, but packageDirs has already normalized them so we need to convert if windows
this.packageDirs.map((dir) => dir.path.split(path.sep).join(path.posix.sep))
: this.packageDirs.map((dir) => dir.path);
// iso-git uses relative, posix paths
// but packageDirs has already resolved / normalized them
// so we need to make them project-relative again and convert if windows
const filepaths = this.packageDirs
.map((dir) => path.relative(this.projectPath, dir.fullPath))
.map((p) => (isWindows ? p.split(path.sep).join(path.posix.sep) : p));

// status hasn't been initalized yet
this.status = await git.statusMatrix({
fs,
Expand Down
49 changes: 49 additions & 0 deletions test/nuts/local/relativePkgDirs.nut.ts
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2020, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import * as path from 'path';
import { TestSession } from '@salesforce/cli-plugins-testkit';
import { fs } from '@salesforce/core';
import { expect } from 'chai';
import { ShadowRepo } from '../../../src/shared/localShadowRepo';

describe('verifies behavior of relative pkgDirs', () => {
let session: TestSession;
let repo: ShadowRepo;

before(async () => {
session = await TestSession.create({
project: {
sourceDir: path.join('test', 'nuts', 'repros', 'extra-classes'),
},
authStrategy: 'NONE',
});
});

it('initialize the local tracking', async () => {
repo = await ShadowRepo.getInstance({
orgId: 'fakeOrgId3',
projectPath: session.project.dir,
packageDirs: [
{ path: './force-app', name: 'force-app', fullPath: path.join(session.project.dir, './force-app') },
],
});
// verify the local tracking files/directories
expect(fs.existsSync(repo.gitDir));
});

it('should not include files from force-app-extra', async () => {
const changedFilenames = await repo.getChangedFilenames();
expect(changedFilenames).to.be.an('array').with.length.greaterThan(0);
changedFilenames.map((f) => {
expect(f).to.not.contain('force-app-extra');
});
});

after(async () => {
await session?.clean();
});
});

0 comments on commit 3b46454

Please sign in to comment.