Skip to content

Commit

Permalink
Merge pull request #99 from forcedotcom/sm/gitignore-some-more
Browse files Browse the repository at this point in the history
Sm/gitignore-some-more
  • Loading branch information
WillieRuemmele committed Jan 25, 2022
2 parents d92ee20 + 403295f commit 49ba997
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 11 deletions.
18 changes: 16 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ jobs:
description: Runs NUTs from other (external) repos by cloning them. Substitutes a dependency for the current pull request. For example, you're testing a PR to a library and want to test a plugin in another repo that uses the library.

parameters:
test_command:
type: string
description: 'command to execute (ex: yarn test:nuts)'
default: 'yarn test:nuts'
node_version:
description: version of node to run tests against
type: string
Expand Down Expand Up @@ -106,7 +110,7 @@ jobs:
- run:
name: Nuts
command: |
yarn test:nuts:tracking
<<parameters.test_command>>
workflows:
version: 2
Expand Down Expand Up @@ -155,12 +159,22 @@ workflows:
- release-management/test-package
- release-management/test-nut
sfdx_version: latest
size: large
size: medium
matrix:
parameters:
os: [linux, windows]
node_version: [lts]
external_project_git_url: ['https://github.com/salesforcecli/plugin-source']
test_command:
[
'yarn test:nuts:tracking:basics',
'yarn test:nuts:tracking:conflicts',
'yarn test:nuts:tracking:forceignore',
'yarn test:nuts:tracking:remote',
'yarn test:nuts:tracking:resetClear',
'yarn test:nuts:tracking:lwc',
'yarn mocha "test/nuts/trackingCommands/mpd-*.nut.ts" --slow 3000 --timeout 600000 --parallel',
]
- release-management/release-package:
github-release: true
requires:
Expand Down
10 changes: 2 additions & 8 deletions src/shared/localShadowRepo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export class ShadowRepo {
this.logger.debug('initializing git repo');
await this.gitInit();
}
await this.locateIgnoreFiles();
}

/**
Expand All @@ -88,7 +89,6 @@ export class ShadowRepo {
public async gitInit(): Promise<void> {
await fs.promises.mkdir(this.gitDir, { recursive: true });
await git.init({ fs, dir: this.projectPath, gitdir: this.gitDir, defaultBranch: 'main' });
await this.locateIgnoreFiles();
}

/**
Expand Down Expand Up @@ -265,17 +265,11 @@ export class ShadowRepo {
dir: this.projectPath,
gitdir: this.gitDir,
trees: [git.WORKDIR()],
// TODO: this can be marginally faster if we limit it to pkgDirs and toplevel project files
// eslint-disable-next-line @typescript-eslint/require-await
map: async (filepath: string) => filepath,
})) as string[]
)
.filter(
(filepath) =>
filepath.includes(gitIgnoreFileName) &&
// can be top-level like '.' (no sep) OR must be in one of the package dirs
(!filepath.includes(path.sep) || this.packageDirs.some((dir) => pathIsInFolder(filepath, dir.name)))
)
.filter((filepath) => filepath.includes(gitIgnoreFileName))
.map((ignoreFile) => path.join(this.projectPath, ignoreFile));
}

Expand Down
36 changes: 35 additions & 1 deletion test/nuts/local/nonTopLevelIgnore.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { fs } from '@salesforce/core';
import { expect } from 'chai';
import { ShadowRepo } from '../../../src/shared/localShadowRepo';

describe('handles non-top-level ignore', () => {
describe('handles non-top-level ignore inside project dir', () => {
let session: TestSession;
let repo: ShadowRepo;

Expand Down Expand Up @@ -43,3 +43,37 @@ describe('handles non-top-level ignore', () => {
await session?.clean();
});
});

describe('handles non-top-level ignore outside project dir', () => {
let session: TestSession;
let repo: ShadowRepo;

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

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

it('should not be influenced by gitignore', async () => {
expect(await repo.getChangedFilenames())
.to.be.an('array')
.with.length(2);
});

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

0 comments on commit 49ba997

Please sign in to comment.