Skip to content

Commit

Permalink
#20
Browse files Browse the repository at this point in the history
  • Loading branch information
ChuckJonas committed Nov 15, 2019
1 parent 03e8d25 commit 3f995ee
Show file tree
Hide file tree
Showing 16 changed files with 92 additions and 43 deletions.
17 changes: 7 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

Generates a metadata package (`package.xml` & source files) for differences between two branches/commits.

![Generating vs working tree](https://user-images.githubusercontent.com/5217568/65200914-e587ed80-da45-11e9-917d-a63a3c91b29f.gif)
_Example Generating vs "working tree" & master_

## Install

Run `sfdx plugins:install sfdx-git-packager`
Expand Down Expand Up @@ -55,9 +52,9 @@ OPTIONS
-f, --force Continue even if source is behind
target
-s, --sourceref=sourceref The git ref (branch or commit) which
we are deploying from. If left
blank, will use working copy
-s, --sourceref=sourceref [default: head] The git ref (branch
or commit) which we are deploying
from. If left blank, will use head
-t, --targetref=targetref [default: master] The git ref
(branch or commit) which we are
Expand All @@ -78,12 +75,12 @@ OPTIONS
exists (without prompt)
EXAMPLES
$ sfdx git:package -s my-awesome-feature -t master -d deployments/my-awesome-feature
$ sfdx git:package -d deployments/my-working-copy
$ sfdx git:package -s head -d deployments/my-working-copy
$ sfdx git:package -s my-awesome-feature -t master -d deploy/my-feature
$ sfdx git:package -d deploy/my-feature
$ 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.0.5/lib/commands/git/package.js)_
_See code: [lib/commands/git/package.js](https://github.com/ChuckJonas/sfdx-git-diff-to-pkg/blob/v0.1.0/lib/commands/git/package.js)_
<!-- commandsstop -->

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

## 0.1.0

### Changed
- if left blank, `--sourceref|-s` now default to head. Can no longer target vs working copy.
- deletions are now put into `destructiveChangesPost.xml` instead of `destructiveChanges.xml`
### Fixed
- Fixed bug where package was not added for destructive only changes
2 changes: 1 addition & 1 deletion messages/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"commandDescription": "Generates a Metadata Package using the differences between two git refs (branch or commit)",
"outputdirDescription": "The directory to output the generated package and metadata to",
"toBranchDescription": "The git ref (branch or commit) which we are deploying into. Defaults to master",
"fromBranchDescription": "The git ref (branch or commit) which we are deploying from. If left blank, will use working copy",
"fromBranchDescription": "The git ref (branch or commit) which we are deploying from. If left blank, will use head",
"force": "Continue even if source is behind target",
"purgeDescription": "Delete output dir if it already exists (without prompt)",
"ignoreWhitespace": "Don't package changes that are whitespace only",
Expand Down
1 change: 1 addition & 0 deletions oclif.manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":"0.1.0","commands":{"git:package":{"id":"git:package","description":"Generates a Metadata Package using the differences between two git refs (branch or commit)","usage":"<%= command.id %> -d <string> [-s <string>] [-t <string>] [-w] [--purge] [--nodelete] [-f] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]","pluginName":"sfdx-git-packager","pluginType":"core","aliases":[],"examples":["$ sfdx git:package -s my-awesome-feature -t master -d deploy/my-feature","$ sfdx git:package -d deploy/my-feature","$ sfdx git:package -s feature-b -d deploy/feature-b"],"flags":{"json":{"name":"json","type":"boolean","description":"format output as json","allowNo":false},"loglevel":{"name":"loglevel","type":"option","description":"logging level for this command invocation","required":false,"helpValue":"(trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL)","options":["trace","debug","info","warn","error","fatal","TRACE","DEBUG","INFO","WARN","ERROR","FATAL"],"default":"warn"},"sourceref":{"name":"sourceref","type":"option","char":"s","description":"The git ref (branch or commit) which we are deploying from. If left blank, will use head","default":"head"},"targetref":{"name":"targetref","type":"option","char":"t","description":"The git ref (branch or commit) which we are deploying into. Defaults to master","default":"master"},"outputdir":{"name":"outputdir","type":"option","char":"d","description":"The directory to output the generated package and metadata to","required":true},"ignorewhitespace":{"name":"ignorewhitespace","type":"boolean","char":"w","description":"Don't package changes that are whitespace only","allowNo":false},"purge":{"name":"purge","type":"boolean","description":"Delete output dir if it already exists (without prompt)","allowNo":false},"nodelete":{"name":"nodelete","type":"boolean","description":"Don't generate destructiveChanges.xml for deletions","allowNo":false},"force":{"name":"force","type":"boolean","char":"f","description":"Continue even if source is behind target","allowNo":false}},"args":[{"name":"file"}]}}}
2 changes: 1 addition & 1 deletion 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.0.5",
"version": "0.1.0",
"author": "Charlie Jonas @ChuckJonas",
"bugs": "https://github.com/ChuckJonas/sfdx-git-diff-to-pkg/issues",
"dependencies": {
Expand Down
41 changes: 16 additions & 25 deletions src/commands/git/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ export default class Package extends SfdxCommand {
public static description = messages.getMessage('commandDescription');

public static examples = [
'$ sfdx git:package -s my-awesome-feature -t master -d deployments/my-awesome-feature',
'$ sfdx git:package -d deployments/my-working-copy',
'$ sfdx git:package -s head -d deployments/my-working-copy'
'$ sfdx git:package -s my-awesome-feature -t master -d deploy/my-feature',
'$ sfdx git:package -d deploy/my-feature',
'$ sfdx git:package -s feature-b -d deploy/feature-b'
];

// not sure what this does...
Expand All @@ -37,7 +37,7 @@ export default class Package extends SfdxCommand {

protected static flagsConfig = {
// flag with a value (-n, --name=VALUE)
sourceref: flags.string({ char: 's', description: messages.getMessage('fromBranchDescription') }),
sourceref: flags.string({ char: 's', description: messages.getMessage('fromBranchDescription'), default: 'head' }),
targetref: flags.string({ char: 't', description: messages.getMessage('toBranchDescription'), default: 'master' }),
outputdir: flags.string({ char: 'd', description: messages.getMessage('outputdirDescription'), required: true }),
ignorewhitespace: flags.boolean({ char: 'w', description: messages.getMessage('ignoreWhitespace') }),
Expand Down Expand Up @@ -66,18 +66,14 @@ export default class Package extends SfdxCommand {

const toBranch = this.flags.targetref;
const fromBranch = this.flags.sourceref;
const diffArgs = ['--no-pager', 'diff', '--name-status', '--no-renames', toBranch];

if (fromBranch) {
diffArgs.push(fromBranch);
}
const diffArgs = ['--no-pager', 'diff', '--name-status', '--no-renames', toBranch, fromBranch];

try {
const diffRefs = `${toBranch}...` + (fromBranch ? fromBranch : '');
const diffRefs = `${toBranch}...${fromBranch}`;
const aheadBehind = await spawnPromise('git', ['rev-list', '--left-right', '--count', diffRefs], { shell: true });
const behind = Number(aheadBehind.split(/(\s+)/)[0]);
if (behind > 0) {
const behindMessage = `${fromBranch ? fromBranch : '"working tree"'} is ${behind} commit(s) behind ${toBranch}! You probably want to rebase ${toBranch} into ${fromBranch} before deploying!`;
const behindMessage = `${fromBranch} is ${behind} commit(s) behind ${toBranch}! You probably want to merge ${toBranch} into ${fromBranch} before building a package!`;
if (!this.flags.force) {
this.ux.warn(behindMessage + '\nUse -f to generate package anyways.');
this.ux.error();
Expand Down Expand Up @@ -147,7 +143,13 @@ export default class Package extends SfdxCommand {
await spawnPromise('sfdx', ['force:source:convert', '-d', outDir], { shell: true, cwd: tmpProject });
}
if (hasDeletions) {
await fsPromise.copyFile(`${tempDeleteProjConverted}/package.xml`, `${outDir}/destructiveChanges.xml`);
await fsPromise.copyFile(`${tempDeleteProjConverted}/package.xml`, `${outDir}/destructiveChangesPost.xml`);
if (!hasChanges) {
await fsPromise.writeFile(
`${outDir}/package.xml`,
'<?xml version="1.0" encoding="UTF-8"?><Package xmlns="http://soap.sforce.com/2006/04/metadata"></Package>'
);
}
}
} catch (e) {
this.ux.error(e);
Expand Down Expand Up @@ -194,14 +196,8 @@ export default class Package extends SfdxCommand {

const newPath = join(tempDir, mdPath);
await fs.mkdirp(dirname(newPath));

if (targetRef) {
await copyFileFromRef(mdPath, targetRef, newPath);
} else {
await fsPromise.copyFile(mdPath, newPath);
}
await copyFileFromRef(mdPath, targetRef, newPath);
}

}

return tempDir;
Expand All @@ -224,12 +220,7 @@ export default class Package extends SfdxCommand {

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

if (!hasNonWhitespaceChanges(a, b)) {
continue;
Expand Down
1 change: 1 addition & 0 deletions test/integration/output/del_class/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><Package xmlns="http://soap.sforce.com/2006/04/metadata"></Package>
1 change: 1 addition & 0 deletions test/integration/output/del_field/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><Package xmlns="http://soap.sforce.com/2006/04/metadata"></Package>
1 change: 1 addition & 0 deletions test/integration/output/del_object/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><Package xmlns="http://soap.sforce.com/2006/04/metadata"></Package>
1 change: 1 addition & 0 deletions test/integration/output/del_static_resource/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><Package xmlns="http://soap.sforce.com/2006/04/metadata"></Package>
Binary file not shown.
59 changes: 53 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,12 @@ bl@^3.0.0:
dependencies:
readable-stream "^3.0.1"

brace-expansion@^1.1.7:
bluebird@3.4.1:
version "3.4.1"
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.4.1.tgz#b731ddf48e2dd3bedac2e75e1215a11bcb91fa07"
integrity sha1-tzHd9I4t077awudeEhWhG8uR+gc=

brace-expansion@^1.0.0, brace-expansion@^1.1.7:
version "1.1.11"
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd"
integrity sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==
Expand Down Expand Up @@ -622,6 +627,11 @@ buffer-equal-constant-time@1.0.1:
resolved "https://registry.yarnpkg.com/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz#f8e71132f7ffe6e01a5c9697a4c6f3e48d5cc819"
integrity sha1-+OcRMvf/5uAaXJaXpMbz5I1cyBk=

buffer-equal@1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/buffer-equal/-/buffer-equal-1.0.0.tgz#59616b498304d556abd466966b22eeda3eca5fbe"
integrity sha1-WWFrSYME1Var1GaWayLu2j7KX74=

buffer-from@^1.0.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.1.tgz#32713bc028f75c02fdb710d7c7bcec1f2c6070ef"
Expand Down Expand Up @@ -839,6 +849,11 @@ color-name@1.1.3:
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.3.tgz#a7d0558bd89c42f795dd42328f740831ca53bc25"
integrity sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=

colors@1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/colors/-/colors-1.0.3.tgz#0433f44d809680fdeb60ed260f1b0c262e82a40b"
integrity sha1-BDP0TYCWgP3rYO0mDxsMJi6CpAs=

combined-stream@^1.0.6, combined-stream@~1.0.6:
version "1.0.8"
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f"
Expand All @@ -851,6 +866,13 @@ commander@2.15.1:
resolved "https://registry.yarnpkg.com/commander/-/commander-2.15.1.tgz#df46e867d0fc2aec66a34662b406a9ccafff5b0f"
integrity sha512-VlfT9F3V0v+jr4yxPc5gg9s62/fIVWsd2Bk2iD435um1NlGMYdVCq+MjcXnhYq2icNOizHr1kK+5TI6H0Hy0ag==

commander@2.9.0:
version "2.9.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.9.0.tgz#9c99094176e12240cb22d6c5146098400fe0f7d4"
integrity sha1-nJkJQXbhIkDLItbFFGCYQA/g99Q=
dependencies:
graceful-readlink ">= 1.0.0"

commander@^2.12.1, commander@^2.9.0, commander@~2.20.0:
version "2.20.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.0.tgz#d58bb2b5c1ee8f87b0d340027e9e94e222c5a422"
Expand Down Expand Up @@ -1050,6 +1072,17 @@ diff@^4.0.1:
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.1.tgz#0c667cb467ebbb5cea7f14f135cc2dba7780a8ff"
integrity sha512-s2+XdvhPCOF01LRQBC8hf4vhbVmI2CGS5aZnxLJlT5FtdhPCDFq80q++zK2KlrVorVDdL5BOGZ/VfLrVtYNF+Q==

dir-compare@^1.7.3:
version "1.8.0"
resolved "https://registry.yarnpkg.com/dir-compare/-/dir-compare-1.8.0.tgz#5dbc06682c0492519c733f76f43452414d8167d0"
integrity sha512-Ork/J37pKE6M+Fvl98OB+iAuZ5CG7d2d8DIMmiCDEZVAbEWn2lp+ghSbc1lgkgVX91p8jMQs2DeTMJvpMeU9+A==
dependencies:
bluebird "3.4.1"
buffer-equal "1.0.0"
colors "1.0.3"
commander "2.9.0"
minimatch "3.0.2"

dir-glob@2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/dir-glob/-/dir-glob-2.0.0.tgz#0b205d2b6aef98238ca286598a8204d29d0a0034"
Expand Down Expand Up @@ -1476,11 +1509,6 @@ glob-parent@^5.0.0:
dependencies:
is-glob "^4.0.1"

glob-regex@^0.3.2:
version "0.3.2"
resolved "https://registry.yarnpkg.com/glob-regex/-/glob-regex-0.3.2.tgz#27348f2f60648ec32a4a53137090b9fb934f3425"
integrity sha512-m5blUd3/OqDTWwzBBtWBPrGlAzatRywHameHeekAZyZrskYouOGdNB8T/q6JucucvJXtOuyHIn0/Yia7iDasDw==

glob-to-regexp@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/glob-to-regexp/-/glob-to-regexp-0.3.0.tgz#8c5a1494d2066c570cc3bfe4496175acc4d502ab"
Expand Down Expand Up @@ -1558,6 +1586,11 @@ graceful-fs@^4.1.11, graceful-fs@^4.1.15, graceful-fs@^4.1.2, graceful-fs@^4.1.6
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.2.tgz#6f0952605d0140c1cfdb138ed005775b92d67b02"
integrity sha512-IItsdsea19BoLC7ELy13q1iJFNmd7ofZH5+X/pJr90/nRoPEX0DJo1dHDbgtYWOhJhcCgMDTOw84RZ72q6lB+Q==

"graceful-readlink@>= 1.0.0":
version "1.0.1"
resolved "https://registry.yarnpkg.com/graceful-readlink/-/graceful-readlink-1.0.1.tgz#4cafad76bc62f02fa039b2f94e9a3dd3a391a725"
integrity sha1-TK+tdrxi8C+gObL5Tpo906ORpyU=

growl@1.10.5:
version "1.10.5"
resolved "https://registry.yarnpkg.com/growl/-/growl-1.10.5.tgz#f2735dc2283674fa67478b10181059355c369e5e"
Expand Down Expand Up @@ -2350,6 +2383,13 @@ mime-types@^2.1.12, mime-types@~2.1.19:
dependencies:
brace-expansion "^1.1.7"

minimatch@3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.2.tgz#0f398a7300ea441e9c348c83d98ab8c9dbf9c40a"
integrity sha1-DzmKcwDqRB6cNIyD2Yq4ydv5xAo=
dependencies:
brace-expansion "^1.0.0"

minimist@0.0.8:
version "0.0.8"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d"
Expand Down Expand Up @@ -2978,6 +3018,13 @@ rimraf@^2.6.2, rimraf@^2.6.3:
dependencies:
glob "^7.1.3"

rimraf@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-3.0.0.tgz#614176d4b3010b75e5c390eb0ee96f6dc0cebb9b"
integrity sha512-NDGVxTsjqfunkds7CqsOiEnxln4Bo7Nddl3XhS4pXg5OzwkLqJ971ZVAAnB+DDLnF76N+VnDEiBHaVV8I06SUg==
dependencies:
glob "^7.1.3"

rimraf@~2.4.0:
version "2.4.5"
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.4.5.tgz#ee710ce5d93a8fdb856fb5ea8ff0e2d75934b2da"
Expand Down

0 comments on commit 3f995ee

Please sign in to comment.