Skip to content

Commit

Permalink
Merge pull request #40 from callawaycloud/whitespace-fix
Browse files Browse the repository at this point in the history
#39 fixing whitespace ignore flag
  • Loading branch information
ChuckJonas authored Jul 9, 2020
2 parents 07ed679 + fb2b3f9 commit 38f591a
Show file tree
Hide file tree
Showing 36 changed files with 83 additions and 20 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ EXAMPLES
$ sfdx git:package -s feature-b -d deploy/feature-b
```

_See code: [lib/commands/git/package.js](https://github.com/ChuckJonas/sfdx-git-diff-to-pkg/blob/v0.2.2/lib/commands/git/package.js)_
_See code: [lib/commands/git/package.js](https://github.com/callawaycloud/sfdx-git-packager/blob/v0.3.0/lib/commands/git/package.js)_

<!-- commandsstop -->

Expand All @@ -107,7 +107,9 @@ If you wish to prevent certain files from being included in a package, you can c

#### Integration Testing

`npm run integrationTest` runs integration test suite
`npm run test:integration` runs integration test suite

_Note: To run a specific test or suite you can use `npm run test:integration -- --grep "your test name"`_

#### Setting Up Integration Tests

Expand All @@ -119,9 +121,10 @@ We've got a git repo in `test/integration/project` that represents a project. In
1. go to the test project `cd test/integration/project`
1. create a branch off of `master`, make the mods you want to test, and commit
1. generate the expected output `npm run gen`
1. check the contents of `test/integration/output` matches what you'd expect for your change (make sure to check there are no other unexpected changes!)
1. check the contents of `test/integration/output` matches what you'd expect for your change (make sure to check there are no other unexpected changes. DO NOT blind commit changes to other outputs!)
1. add a new test to `test/integration/integration.test.ts`
1. pack the test repo back up `npm run tgp`
1. commit changes

**Updating the base state (master)**

Expand Down
17 changes: 17 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# Changelog

## 0.3.0

### Fixed

- bug with ignore whitespace flag on non-modified changes

### Added

- Ability to pass flags into integration tests
- Test for ignore whitespace flag

## 0.3.0

### Added

- support for `ContentAsset`

## 0.2.1

### Fixed
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "sfdx-git-packager",
"description": "Generates a package.xml for difference between two branches",
"version": "0.3.0",
"version": "0.3.1",
"author": "Charlie Jonas @ChuckJonas",
"bugs": "https://github.com/callawaycloud/sfdx-git-packager/issues",
"dependencies": {
Expand Down Expand Up @@ -70,9 +70,8 @@
"posttest": "tslint -p test -t stylish",
"prepack": "rm -rf lib && tsc -b && oclif-dev manifest && oclif-dev readme",
"test": "nyc --extension .ts mocha --timeout 99999 --forbid-only \"test/{*.test.ts,!(integration)/**/*.test.ts}\"",
"test:integration": "npm run integrationTest",
"test:integration": "nyc --extension .ts mocha --timeout 99999 --forbid-only \"test/integration/**/*.test.ts\"",
"test:generate:output": "npm run gen",
"integrationTest": "nyc --extension .ts mocha --timeout 99999 --forbid-only \"test/integration/**/*.test.ts\"",
"version": "oclif-dev readme && git add README.md",
"tgp": "mv test/integration/project/.git test/integration/project/.notgit",
"tgu": "mv test/integration/project/.notgit test/integration/project/.git",
Expand Down
20 changes: 11 additions & 9 deletions src/commands/git/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,6 @@ export default class Package extends SfdxCommand {
continue;
}

if (this.flags.ignorewhitespace) {
const a = await spawnPromise('git', ['show', `${this.flags.targetref}:${path}`]);
const b = await spawnPromise('git', ['show', `${this.flags.sourceref}:${path}`]);

if (!hasNonWhitespaceChanges(a, b)) {
continue;
}
}

// check that path is part of the sfdx projectDirectories...
// There's most certainty a better way to do this
const inProjectSource = this.sourcePaths.reduce((inSource, sPath) => {
Expand All @@ -241,6 +232,17 @@ export default class Package extends SfdxCommand {
if (status === 'D') {
removed.push(path);
} else {
if (status === 'M') {
if (this.flags.ignorewhitespace) {
const a = await spawnPromise('git', ['show', `${this.flags.targetref}:${path}`]);
const b = await spawnPromise('git', ['show', `${this.flags.sourceref}:${path}`]);

if (!hasNonWhitespaceChanges(a, b)) {
continue;
}
}
}

changed.push(path);
}

Expand Down
14 changes: 10 additions & 4 deletions test/integration/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ import { compareSync } from 'dir-compare';
import { resolve } from 'path';
import { myExec, projectPath, setGitENV } from './util';

async function runTest(testName: string) {
async function runTest(testName: string, params?: string[]) {
const sourceRef = testName;
const expectedOutputDir = testName;
try {
const program = resolve(__dirname, '..', '..', 'bin', 'run');
const res = await myExec(
`${program} git:package -d deploy --purge -s ${sourceRef} -t master`,
`${program} git:package -d deploy --purge -s ${sourceRef} -t master ${params ? params.join(' ') : ''}`,
projectPath);

assert.equal(null, res.err);
const compareRes = compareSync('test/integration/project/deploy', `test/integration/output/${expectedOutputDir}`, { compareContent: true });
const mismatched = compareRes.diffSet.filter(diff => diff.state !== 'equal').map(diff => diff.name1 || diff.name2);
assert.strictEqual(mismatched.length, 0, `The following files were different: \n${mismatched.join('\n')}`);
assert.strictEqual(mismatched.length, 0, `${mismatched.length} file(s) were different: \n${mismatched.join('\n')}`);
assert.strictEqual(true, compareRes.equal > 0);
} catch (e) {
assert.fail(e);
Expand Down Expand Up @@ -95,7 +95,7 @@ describe('git:package integration test', async () => {
});
});

describe('content assets', async() => {
describe('content assets', async () => {
it('detects new content assets', async () => {
await runTest('add_content_asset');
});
Expand All @@ -108,4 +108,10 @@ describe('git:package integration test', async () => {
await runTest('del_content_asset');
});
});

describe('ignore whitespace flag', async () => {
it('ignores whitespace on modified files', async () => {
await runTest('ignore_whitespace', ['-w']);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public with sharing class NewClass {
public NewClass() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>48.0</apiVersion>
<status>Active</status>
</ApexClass>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<name>CustomField</name>
<members>Foo__c.Is_Foo__c</members>
</types>
<version>45.0</version>
</Package>
8 changes: 8 additions & 0 deletions test/integration/output/ignore_whitespace/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<name>ApexClass</name>
<members>NewClass</members>
</types>
<version>45.0</version>
</Package>
Binary file not shown.
2 changes: 1 addition & 1 deletion test/integration/project/.notgit/COMMIT_EDITMSG
Original file line number Diff line number Diff line change
@@ -1 +1 @@
fix: delete content asset
deleting metadata
Binary file modified test/integration/project/.notgit/index
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
0000000000000000000000000000000000000000 e96fd19fce8cf550d402834e38e7f992c4ee5c97 Charlie Jonas <[email protected]> 1594313746 -0600 branch: Created from HEAD
e96fd19fce8cf550d402834e38e7f992c4ee5c97 76fb95e41d56c152dea236ae2f0f1b64cac3cc16 Charlie Jonas <[email protected]> 1594313788 -0600 commit: whitespace only change
76fb95e41d56c152dea236ae2f0f1b64cac3cc16 105a0a34b55a9baf773228ebd5399d09c6b45bb8 Charlie Jonas <[email protected]> 1594313810 -0600 commit: adding metadata
105a0a34b55a9baf773228ebd5399d09c6b45bb8 210e4d66600637e11563246917d692d4bf6e55aa Charlie Jonas <[email protected]> 1594313850 -0600 commit: deleting metadata
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
x��]j�0���S�R����PB o��z���Ul���G�+�q��O�.�G�U!:�1��(��0摬�2�q�Vh�I�/�5�i�0E�.);O�.یa�"H��6��3�eQxԍ���x.����R�$u;�Җ��S�z�c���p�����K7�'�����8qc��dXC
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
x��Mj�0���)� ���%(��]o1�ƵA��-r�:�
�<x��{/�e�;>�&-�cB�ZS2X�ѝ��芋'��Q���A#1�u��c�q�1AR!c��}r�RP|��mp�x���O[y����ߙk�;?rmG�mݏ�����������B��GT'=Owy�N��E:��ƫXE
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
xM��
�0=�+B�fS)*���/P��4j�MB7�~����n����-/�F����ɍ�c�D!��.������z�Em�n���=��T�W��@��G��6�Sj���e�0�0�/Ә�}���(���c5(c~�il����E��6��:]
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
210e4d66600637e11563246917d692d4bf6e55aa

0 comments on commit 38f591a

Please sign in to comment.