Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow 'tag' type git pointer #283

Merged
merged 4 commits into from
Mar 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<details>
<summary>Table of Contents</summary>

- [TL;DR;](#tldr)
- [TL;DR](#tldr)
- [What is SFDX-Git-Delta?](#what-is-sfdx-git-delta)
- [Is SGD for you?](#is-sgd-for-you)
- [Getting Started](#getting-started)
Expand All @@ -33,6 +33,7 @@
- [How to use it?](#how-to-use-it)
- [`sfdx sgd:source:delta -f <string> [-t <string>] [-r <filepath>] [-i <filepath>] [-D <filepath>] [-s <filepath>] [-W] [-o <filepath>] [-a <number>] [-d] [-n <filepath>] [-N <filepath>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`](#sfdx-sgdsourcedelta--f-string--t-string--r-filepath--i-filepath--d-filepath--s-filepath--w--o-filepath--a-number--d--n-filepath--n-filepath---json---loglevel-tracedebuginfowarnerrorfataltracedebuginfowarnerrorfatal)
- [Windows users](#windows-users)
- [CI/CD specificity](#cicd-specificity)
- [Use cases](#use-cases)
- [Walkthrough](#walkthrough)
- [Execute sgd](#execute-sgd)
Expand Down Expand Up @@ -190,6 +191,18 @@ _See code: [src/commands/sgd/source/delta.ts](https://github.com/scolladon/sfdx-

If you run SGD on a Windows system, use double quotes [to prevent the terminal to interpret parameters](https://github.com/scolladon/sfdx-git-delta/issues/134)

### CI/CD specificity

In CI/CD pipelines, branches are not checked out locally when the repository is cloned so you must specify the remote prefix.
If you do not specify the remote in CI context, the git pointer check will raise an error as the branch is not created locally.
This applies to both `--from` and `--to` parameters as they both accept git pointers.

Exemple comparing `HEAD` with a `development` branch when the CI clone the repository with `origin` set as reference to the remote:

```sh
sfdx sgd:source:delta --to "HEAD" --from "origin/development" --output .
```

### Use cases

Any git sha pointer is supported: commit sha, branch, tag, git expression (HEAD, etc.).
Expand Down Expand Up @@ -267,7 +280,11 @@ Note: it is also possible to generate a **source** folder containing added/chang

### Deploy the delta metadata

The simplest option to deploy the delta changes is to use `force:source:deploy`:
The simplest option to deploy the delta changes is to use `force:source:deploy` command with `-x` parameter:

```sh
sfdx force:source:deploy -x package/package.xml --postdestructivechanges destructiveChanges/destructiveChanges.xml
```

```sh
sfdx force:source:deploy -x package/package.xml --postdestructivechanges destructiveChanges/destructiveChanges.xml
Expand Down Expand Up @@ -332,6 +349,12 @@ _Content of the output folder when using the --generate-delta option, with the s
> $ sfdx sgd:source:delta --from "HEAD^" --output changed-sources/ --generate-delta
> ```

Then it is possible to deploy the `change-sources` folder using `force:source:deploy` command with `-p` parameter:

```sh
sfdx force:source:deploy -p change-sources
```

### Exclude some metadata only from destructiveChanges.xml:

The `--ignore [-i]` parameter allows you to specify an [ignore file](https://git-scm.com/docs/gitignore) to filter the
Expand Down
45 changes: 43 additions & 2 deletions __tests__/unit/lib/utils/cliHelper.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
'use strict'
const child_process = require('child_process')
const fs = require('fs')
const { COMMIT_REF_TYPE } = require('../../../../src/utils/gitConstants')
const {
COMMIT_REF_TYPE,
TAG_REF_TYPE,
} = require('../../../../src/utils/gitConstants')
const RepoSetup = require('../../../../src/utils/repoSetup')
const CLIHelper = require('../../../../src/utils/cliHelper')
jest.mock('fs')
Expand Down Expand Up @@ -152,7 +155,7 @@ describe(`test if the application`, () => {
})

test('throws errors when "-t" is not a valid sha pointer', async () => {
child_process.__setOutput([[COMMIT_REF_TYPE], ['not a valid sha pointer']])
child_process.__setOutput([[TAG_REF_TYPE], ['not a valid sha pointer']])
const notHeadSHA = 'test'
let cliHelper = new CLIHelper({
...testConfig,
Expand All @@ -178,4 +181,42 @@ describe(`test if the application`, () => {
`--from is not a valid sha pointer: '${notHeadSHA}'`
)
})

test('throws errors when "-t" and "-f" are not a valid sha pointer', async () => {
child_process.__setOutput([
['not a valid sha pointer'],
['not a valid sha pointer'],
])
const notHeadSHA = 'test'
let cliHelper = new CLIHelper({
...testConfig,
to: notHeadSHA,
from: notHeadSHA,
generateDelta: false,
})
expect.assertions(2)
await expect(cliHelper.validateConfig()).rejects.toThrow(
`--to is not a valid sha pointer: '${notHeadSHA}'`
)
await expect(cliHelper.validateConfig()).rejects.toThrow(
`--from is not a valid sha pointer: '${notHeadSHA}'`
)
})

test('do not throw errors when "-t" and "-f" are valid sha pointer', async () => {
child_process.__setOutput([[TAG_REF_TYPE], [COMMIT_REF_TYPE]])
const notHeadSHA = 'test'
let cliHelper = new CLIHelper({
...testConfig,
from: notHeadSHA,
generateDelta: false,
})
expect.assertions(2)
await expect(cliHelper.validateConfig()).rejects.not.toThrow(
`--to is not a valid sha pointer: '${COMMIT_REF_TYPE}'`
)
await expect(cliHelper.validateConfig()).rejects.not.toThrow(
`--from is not a valid sha pointer: '${TAG_REF_TYPE}'`
)
})
})
4 changes: 2 additions & 2 deletions src/utils/cliHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const asyncFilter = require('./asyncFilter')
const RepoSetup = require('./repoSetup')
const { sanitizePath, getStreamContent } = require('./childProcessUtils')
const { COMMIT_REF_TYPE, GIT_FOLDER } = require('./gitConstants')
const { GIT_FOLDER, POINTER_REF_TYPES } = require('./gitConstants')
const { spawn } = require('child_process')
const { stat } = require('fs').promises
const { join } = require('path')
Expand Down Expand Up @@ -49,7 +49,7 @@ class CLIHelper {
cwd: this.config.repo,
})
)
if (refType?.replace(/\s/g, '') !== COMMIT_REF_TYPE) {
if (!POINTER_REF_TYPES.includes(refType?.replace(/\s/g, ''))) {
errors.push(
`--${field} is not a valid sha pointer: '${this.config[field]}'`
)
Expand Down
6 changes: 5 additions & 1 deletion src/utils/gitConstants.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
'use strict'
const COMMIT_REF_TYPE = 'commit'
const TAG_REF_TYPE = 'tag'
module.exports.ADDITION = 'A'
module.exports.DELETION = 'D'
module.exports.MODIFICATION = 'M'
module.exports.COMMIT_REF_TYPE = 'commit'
module.exports.COMMIT_REF_TYPE = COMMIT_REF_TYPE
module.exports.TAG_REF_TYPE = TAG_REF_TYPE
module.exports.POINTER_REF_TYPES = [COMMIT_REF_TYPE, TAG_REF_TYPE]
module.exports.GIT_DIFF_TYPE_REGEX = /^.\s+/u
module.exports.GIT_FOLDER = '.git'
module.exports.MINUS = '-'
Expand Down
36 changes: 18 additions & 18 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -833,9 +833,9 @@
tslib "^2.3.1"

"@oclif/core@^1.3.1", "@oclif/core@^1.3.6", "@oclif/core@^1.5.1", "@oclif/core@^1.5.2":
version "1.6.3"
resolved "https://registry.yarnpkg.com/@oclif/core/-/core-1.6.3.tgz#3d1dd4e033f5512ac35963a73878257142390838"
integrity sha512-a3DrPNlOYemwnzxuJ3tINjqpMVIYe56Mg+XaQo0nGsqGSk69wF5Q/hD8plsWrtwdkeIxwxhgl7T699EJypAUwg==
version "1.6.4"
resolved "https://registry.yarnpkg.com/@oclif/core/-/core-1.6.4.tgz#fd213265199a8ef93adb358e15a04d74927eb522"
integrity sha512-eUnh03MWxs3PHQUdZbo43ceLqmeOgGegsfimeqd6xfhcKwSv8dqarRyAoMCjg7P6Qm5qCjaNFZ6eS4ao349xvQ==
dependencies:
"@oclif/linewrap" "^1.0.0"
"@oclif/screen" "^3.0.2"
Expand Down Expand Up @@ -1011,9 +1011,9 @@
safe-json-stringify "~1"

"@salesforce/command@^5.0.1":
version "5.0.2"
resolved "https://registry.yarnpkg.com/@salesforce/command/-/command-5.0.2.tgz#6d756285162bd1a905faa740d916b9a8c3d6477c"
integrity sha512-7Rsn2kxuH+A1ix8h9JkwIxS87u0lOpn/Hwcudq1WASB7HVIauj3wf71xtlvRfIWuRRCWUGeYIYMi5l+aMViYGw==
version "5.0.3"
resolved "https://registry.yarnpkg.com/@salesforce/command/-/command-5.0.3.tgz#ca41ae3de0f692818a1e4066c50dfe74065ef371"
integrity sha512-eNoeWuSUrsU7DG0t3CU3DnHUVIis7FKxQZeYCVwtV7BZ//aN1rUA/uC4EaRYhiAY5g5kHPY2lY/9BNadVNcRKQ==
dependencies:
"@oclif/core" "^1.5.2"
"@oclif/plugin-help" "^5.1.11"
Expand Down Expand Up @@ -1048,9 +1048,9 @@
ts-retry-promise "^0.6.0"

"@salesforce/core@^3.7.9":
version "3.10.1"
resolved "https://registry.yarnpkg.com/@salesforce/core/-/core-3.10.1.tgz#adee381538969721f58fc35e50f1a5740d3b0c22"
integrity sha512-/1e9sKAEsm902VHsAq/tUCxQHVw0qKouF71Flt8/TKXhq/RZS5/IioDVjYRPM9SsM1hbNseXAuTJE+AApbu4ag==
version "3.11.0"
resolved "https://registry.yarnpkg.com/@salesforce/core/-/core-3.11.0.tgz#e1ec10189103a9133117af938156fb9f3eb2aef2"
integrity sha512-OqEkFfgfL2WvuzasjgrsGVa2SB00FCdfu09hPBK3URnR418+ztk283TDNOQ15AGW5oI8EWdEEKpOI+oAXmWS3A==
dependencies:
"@oclif/core" "^1.5.1"
"@salesforce/bunyan" "^2.0.0"
Expand Down Expand Up @@ -1079,9 +1079,9 @@
integrity sha512-hkH8g7/bQZvtOfKTb3AmTPo1KopUli31legtb84nF9Y6mKj27TRzWUvIRuaRRd86ma19C7lPA4ycUjydX4QCcQ==

"@salesforce/kit@^1.5.17", "@salesforce/kit@^1.5.34":
version "1.5.34"
resolved "https://registry.yarnpkg.com/@salesforce/kit/-/kit-1.5.34.tgz#7967c3f0ba8caccc0718077193d9cbebe1816871"
integrity sha512-vd3f9bwdx8GxAwJpfhzVQAnO82YxbaPLcYiRTS9qmo5mFnhOKsMvbjNQz/wtT4AFs2sC3yyCzvq5Vq6rAcMc7w==
version "1.5.36"
resolved "https://registry.yarnpkg.com/@salesforce/kit/-/kit-1.5.36.tgz#fa9950fb70520fc33352d5184cec5815463f6ff1"
integrity sha512-g1IgZID3q7Ehi4x9rIQNOROcsqHVatZgUr36SyXOhADUhqWhRmoUaQq0W0XlAMQr18rrOSct1nviJwHmlqy//A==
dependencies:
"@salesforce/ts-types" "^1.5.20"
shx "^0.3.3"
Expand Down Expand Up @@ -2027,9 +2027,9 @@ camelcase@^6.2.0:
integrity sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==

caniuse-lite@^1.0.30001317:
version "1.0.30001322"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001322.tgz#2e4c09d11e1e8f852767dab287069a8d0c29d623"
integrity sha512-neRmrmIrCGuMnxGSoh+x7zYtQFFgnSY2jaomjU56sCkTA6JINqQrxutF459JpWcWRajvoyn95sOXq4Pqrnyjew==
version "1.0.30001323"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001323.tgz#a451ff80dec7033016843f532efda18f02eec011"
integrity sha512-e4BF2RlCVELKx8+RmklSEIVub1TWrmdhvA5kEUueummz1XyySW0DVk+3x9HyhU9MuWTa2BhqLgEuEmUwASAdCA==

capital-case@^1.0.4:
version "1.0.4"
Expand Down Expand Up @@ -3033,9 +3033,9 @@ ejs@^3.1.6:
jake "^10.6.1"

electron-to-chromium@^1.4.84:
version "1.4.101"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.101.tgz#71f3a10065146d7445ba5d4c06ba2cc063b0817a"
integrity sha512-XJH+XmJjACx1S7ASl/b//KePcda5ocPnFH2jErztXcIS8LpP0SE6rX8ZxiY5/RaDPnaF1rj0fPaHfppzb0e2Aw==
version "1.4.103"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.103.tgz#abfe376a4d70fa1e1b4b353b95df5d6dfd05da3a"
integrity sha512-c/uKWR1Z/W30Wy/sx3dkZoj4BijbXX85QKWu9jJfjho3LBAXNEGAEW3oWiGb+dotA6C6BzCTxL2/aLes7jlUeg==

emittery@^0.8.1:
version "0.8.1"
Expand Down