From 7c0fa4f273a798fa74e07df946abaa11bfbd6712 Mon Sep 17 00:00:00 2001 From: Nicolas Vuillamy Date: Thu, 19 Aug 2021 18:08:52 +0200 Subject: [PATCH] feat: create "permissive git diff" parameter Manage a new argument --permissivediff to add the following parameters to git diff call [ '--ignore-all-space', '--ignore-blank-lines', '--ignore-cr-at-eol', '--word-diff-regex', ] It allows to avoid detecting as a difference the indentation/spaces stuff --- messages/delta.js | 2 ++ src/commands/sgd/source/delta.ts | 6 ++++++ src/utils/repoGitDiff.js | 12 ++++++++++++ 3 files changed, 20 insertions(+) diff --git a/messages/delta.js b/messages/delta.js index 6bb3a8f7..18029005 100644 --- a/messages/delta.js +++ b/messages/delta.js @@ -11,4 +11,6 @@ module.exports = { ignoreDestructiveFlag: 'ignore file to use', apiVersionFlag: 'salesforce API version', deltaFlag: 'generate delta files in [--output] folder', + permissivediffFlag: + 'allow spaces, blank lines and other indentation stuff to NOT be considered as diff', } diff --git a/src/commands/sgd/source/delta.ts b/src/commands/sgd/source/delta.ts index f20cd678..099e7f21 100644 --- a/src/commands/sgd/source/delta.ts +++ b/src/commands/sgd/source/delta.ts @@ -45,6 +45,11 @@ export default class SourceDeltaGenerate extends SfdxCommand { description: messages.getMessage('sourceFlag'), default: CliHelper.SOURCE_DEFAULT_VALUE, }), + permissivediff: flags.boolean({ + char: 'P', + description: messages.getMessage('permissivediffFlag'), + default: false, + }), output: flags.filepath({ char: 'o', description: messages.getMessage('outputFlag'), @@ -78,6 +83,7 @@ export default class SourceDeltaGenerate extends SfdxCommand { ignoreDestructive: this.flags['ignore-destructive'], apiVersion: this.flags['api-version'], repo: this.flags.repo, + permissivediff: this.flags.permissivediff, generateDelta: this.flags['generate-delta'], }) output.warnings = jobResult?.warnings?.map(warning => warning.message) diff --git a/src/utils/repoGitDiff.js b/src/utils/repoGitDiff.js index 3a62f168..6818f6a1 100644 --- a/src/utils/repoGitDiff.js +++ b/src/utils/repoGitDiff.js @@ -13,6 +13,18 @@ const lcSensitivity = { } module.exports = (config, metadata) => { + // If --permissivediff argument, allow spaces, blank lines and other indentation stuff to NOT be considered as diff + if (config.permissivediff === true) { + fullDiffParams.push( + ...[ + '--ignore-all-space', + '--ignore-blank-lines', + '--ignore-cr-at-eol', + '--word-diff-regex', + ] + ) + } + // Call git diff const { stdout: diff } = childProcess.spawnSync( 'git', [...fullDiffParams, config.from, config.to, config.source],