@apexdevtools/git-ops 1.2.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/lib/src/{FilesChanged/BranchChanges.d.ts → changes.d.ts} +9 -0
- package/lib/src/{FilesChanged/BranchChanges.js → changes.js} +38 -7
- package/lib/src/{Git/Git.d.ts → git.d.ts} +3 -3
- package/lib/src/{Git/Git.js → git.js} +11 -7
- package/lib/src/index.d.ts +3 -5
- package/lib/src/index.js +13 -12
- package/lib/src/{OrgTracking/Tracking.d.ts → tracking.d.ts} +6 -2
- package/lib/src/{OrgTracking/Tracking.js → tracking.js} +2 -2
- package/lib/test/{BranchChanges/BranchChanges.spec.js → changes.spec.js} +83 -40
- package/lib/test/{Git/Git.spec.js → git.spec.js} +59 -63
- package/lib/test/{FsUtils/RepoManager.d.ts → helpers/repo.d.ts} +4 -4
- package/lib/test/{FsUtils/RepoManager.js → helpers/repo.js} +18 -20
- package/lib/test/{OrgTracking/Tracking.spec.js → tracking.spec.js} +2 -2
- package/package.json +26 -78
- package/lib/src/api/IGit.d.ts +0 -6
- package/lib/src/api/IGit.js +0 -5
- package/lib/src/logger/Logger.d.ts +0 -5
- package/lib/src/logger/Logger.js +0 -5
- /package/lib/test/{BranchChanges/BranchChanges.spec.d.ts → changes.spec.d.ts} +0 -0
- /package/lib/test/{Git/Git.spec.d.ts → git.spec.d.ts} +0 -0
- /package/lib/test/{OrgTracking/Tracking.spec.d.ts → tracking.spec.d.ts} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -30,3 +30,12 @@ export declare function getDiffRange(dir: string, fromRef: string, toRef: string
|
|
|
30
30
|
* @returns set of absolute paths of un committed files
|
|
31
31
|
*/
|
|
32
32
|
export declare function getLocalChanges(dir: string): Promise<Set<string>>;
|
|
33
|
+
/**
|
|
34
|
+
* Get the locally changed class files, based on source tracking repo. Note that it does
|
|
35
|
+
* not respect the `.forceignore` yet.
|
|
36
|
+
*
|
|
37
|
+
* @param projectDir SF project dir path
|
|
38
|
+
* @param orgId SF org ID, used to select tracking repo
|
|
39
|
+
* @returns paths of class files that may need deploying
|
|
40
|
+
*/
|
|
41
|
+
export declare function getDeployableClasses(projectDir: string, orgId: string): Promise<Set<string>>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
* Copyright (c)
|
|
3
|
+
* Copyright (c) 2024 Certinia Inc. All rights reserved.
|
|
4
4
|
*/
|
|
5
5
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
6
6
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
@@ -15,9 +15,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
15
15
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
16
16
|
};
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.getLocalChanges = exports.getDiffRange = exports.getDefaultBranchDiffByRef = exports.getDefaultBranchDiff = void 0;
|
|
18
|
+
exports.getDeployableClasses = exports.getLocalChanges = exports.getDiffRange = exports.getDefaultBranchDiffByRef = exports.getDefaultBranchDiff = void 0;
|
|
19
19
|
const path_1 = __importDefault(require("path"));
|
|
20
|
-
const
|
|
20
|
+
const git_1 = require("./git");
|
|
21
21
|
/**
|
|
22
22
|
* Works out a set of changed files by performing getDefaultBranchDiffByRef(repoRootDir, 'HEAD')
|
|
23
23
|
* @param dir: string of the directory thr operation should be performed on
|
|
@@ -41,7 +41,7 @@ exports.getDefaultBranchDiff = getDefaultBranchDiff;
|
|
|
41
41
|
*/
|
|
42
42
|
function getDefaultBranchDiffByRef(dir, refTo) {
|
|
43
43
|
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
-
const git = new
|
|
44
|
+
const git = new git_1.Git(dir);
|
|
45
45
|
return git
|
|
46
46
|
.getDefaultBranchName()
|
|
47
47
|
.then(branch => getDiffRange(dir, branch, refTo))
|
|
@@ -60,7 +60,7 @@ exports.getDefaultBranchDiffByRef = getDefaultBranchDiffByRef;
|
|
|
60
60
|
*/
|
|
61
61
|
function getDiffRange(dir, fromRef, toRef) {
|
|
62
62
|
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
-
const git = new
|
|
63
|
+
const git = new git_1.Git(dir);
|
|
64
64
|
const root = yield git.gitRoot();
|
|
65
65
|
return getDiffChanges(git, fromRef, toRef)
|
|
66
66
|
.then(changes => resolvePaths(changes, root))
|
|
@@ -78,7 +78,7 @@ exports.getDiffRange = getDiffRange;
|
|
|
78
78
|
*/
|
|
79
79
|
function getLocalChanges(dir) {
|
|
80
80
|
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
-
const git = new
|
|
81
|
+
const git = new git_1.Git(dir);
|
|
82
82
|
const root = yield git.gitRoot();
|
|
83
83
|
return git
|
|
84
84
|
.getLocalChangedAndCreated()
|
|
@@ -89,8 +89,36 @@ function getLocalChanges(dir) {
|
|
|
89
89
|
});
|
|
90
90
|
}
|
|
91
91
|
exports.getLocalChanges = getLocalChanges;
|
|
92
|
+
/**
|
|
93
|
+
* Get the locally changed class files, based on source tracking repo. Note that it does
|
|
94
|
+
* not respect the `.forceignore` yet.
|
|
95
|
+
*
|
|
96
|
+
* @param projectDir SF project dir path
|
|
97
|
+
* @param orgId SF org ID, used to select tracking repo
|
|
98
|
+
* @returns paths of class files that may need deploying
|
|
99
|
+
*/
|
|
100
|
+
function getDeployableClasses(projectDir, orgId) {
|
|
101
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
102
|
+
const git = new git_1.Git(projectDir);
|
|
103
|
+
const trackingDir = getTrackingGitDir(projectDir, orgId);
|
|
104
|
+
const stats = [
|
|
105
|
+
git_1.FileStatus.Modified,
|
|
106
|
+
git_1.FileStatus.Added,
|
|
107
|
+
git_1.FileStatus.Renamed,
|
|
108
|
+
git_1.FileStatus.Copied,
|
|
109
|
+
git_1.FileStatus.Untracked,
|
|
110
|
+
];
|
|
111
|
+
return git
|
|
112
|
+
.getFilteredStatus(f => f.path.endsWith('.cls') && stats.includes(f.working_dir), trackingDir)
|
|
113
|
+
.then(changes => resolvePaths(changes, projectDir))
|
|
114
|
+
.catch(er => {
|
|
115
|
+
throw new LocalChangeException(er);
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
exports.getDeployableClasses = getDeployableClasses;
|
|
92
120
|
function resolvePaths(paths, root) {
|
|
93
|
-
const fullPaths = [...paths].map(p => path_1.default.resolve(
|
|
121
|
+
const fullPaths = [...paths].map(p => path_1.default.resolve(root, p));
|
|
94
122
|
return new Set(fullPaths);
|
|
95
123
|
}
|
|
96
124
|
function getDiffChanges(git, ref1, ref2) {
|
|
@@ -104,6 +132,9 @@ function getDiffChanges(git, ref1, ref2) {
|
|
|
104
132
|
return allChanges;
|
|
105
133
|
});
|
|
106
134
|
}
|
|
135
|
+
function getTrackingGitDir(projectDir, orgId) {
|
|
136
|
+
return path_1.default.resolve(projectDir, '.sf', 'orgs', orgId, 'localSourceTracking');
|
|
137
|
+
}
|
|
107
138
|
class GitException extends Error {
|
|
108
139
|
constructor(msg, err) {
|
|
109
140
|
if (err instanceof Error) {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { SimpleGit } from 'simple-git';
|
|
2
|
-
import { IGit } from '../api/IGit';
|
|
1
|
+
import { FileStatusResult, SimpleGit } from 'simple-git';
|
|
3
2
|
export declare enum FileStatus {
|
|
4
3
|
Unmodified = " ",
|
|
5
4
|
Modified = "M",
|
|
@@ -12,7 +11,7 @@ export declare enum FileStatus {
|
|
|
12
11
|
Untracked = "?",
|
|
13
12
|
Ignore = "!"
|
|
14
13
|
}
|
|
15
|
-
export declare class Git
|
|
14
|
+
export declare class Git {
|
|
16
15
|
private static MIN_GIT_VERSION_MAJOR;
|
|
17
16
|
private static MIN_GIT_VERSION_MINOR;
|
|
18
17
|
private gitInstance;
|
|
@@ -24,4 +23,5 @@ export declare class Git implements IGit {
|
|
|
24
23
|
getDefaultBranchName(): Promise<string>;
|
|
25
24
|
diffRange(fromRef: string, toRef: string): Promise<Set<string>>;
|
|
26
25
|
getLocalChangedAndCreated(): Promise<Set<string>>;
|
|
26
|
+
getFilteredStatus(filterFn: (result: FileStatusResult) => boolean, gitDir?: string | undefined): Promise<Set<string>>;
|
|
27
27
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
* Copyright (c)
|
|
3
|
+
* Copyright (c) 2024 Certinia Inc. All rights reserved.
|
|
4
4
|
*/
|
|
5
5
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
6
6
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
@@ -93,14 +93,18 @@ class Git {
|
|
|
93
93
|
getLocalChangedAndCreated() {
|
|
94
94
|
return __awaiter(this, void 0, void 0, function* () {
|
|
95
95
|
const excludeStatus = [FileStatus.Deleted, FileStatus.Ignore];
|
|
96
|
+
return this.getFilteredStatus(f => !excludeStatus.includes(f.index) &&
|
|
97
|
+
!excludeStatus.includes(f.working_dir));
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
getFilteredStatus(filterFn, gitDir) {
|
|
101
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
96
102
|
return this.git
|
|
97
|
-
.then(git =>
|
|
103
|
+
.then(git => {
|
|
104
|
+
return gitDir ? git.env('GIT_DIR', gitDir).status() : git.status();
|
|
105
|
+
})
|
|
98
106
|
.then(status => {
|
|
99
|
-
|
|
100
|
-
.filter(f => !excludeStatus.includes(f.index) &&
|
|
101
|
-
!excludeStatus.includes(f.working_dir))
|
|
102
|
-
.map(f => f.path);
|
|
103
|
-
return new Set(...[changedFiles]);
|
|
107
|
+
return new Set(...[status.files.filter(filterFn).map(f => f.path)]);
|
|
104
108
|
});
|
|
105
109
|
});
|
|
106
110
|
}
|
package/lib/src/index.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
export { getDefaultBranchDiff, getDefaultBranchDiffByRef, getDiffRange, getLocalChanges, } from './
|
|
2
|
-
export { OrgTracking, OrgTrackingOptions, FileState, SyncStatusRow, SyncStatus, } from './
|
|
3
|
-
export {
|
|
4
|
-
export { IGit } from './api/IGit';
|
|
5
|
-
export { Git } from './Git/Git';
|
|
1
|
+
export { getDefaultBranchDiff, getDefaultBranchDiffByRef, getDiffRange, getLocalChanges, getDeployableClasses, } from './changes';
|
|
2
|
+
export { OrgTracking, OrgTrackingOptions, OrgTrackingLogger, FileState, SyncStatusRow, SyncStatus, } from './tracking';
|
|
3
|
+
export { Git } from './git';
|
package/lib/src/index.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
* Copyright (c)
|
|
3
|
+
* Copyright (c) 2024 Certinia Inc. All rights reserved.
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Git = exports.FileState = exports.OrgTracking = exports.getLocalChanges = exports.getDiffRange = exports.getDefaultBranchDiffByRef = exports.getDefaultBranchDiff = void 0;
|
|
7
|
-
var
|
|
8
|
-
Object.defineProperty(exports, "getDefaultBranchDiff", { enumerable: true, get: function () { return
|
|
9
|
-
Object.defineProperty(exports, "getDefaultBranchDiffByRef", { enumerable: true, get: function () { return
|
|
10
|
-
Object.defineProperty(exports, "getDiffRange", { enumerable: true, get: function () { return
|
|
11
|
-
Object.defineProperty(exports, "getLocalChanges", { enumerable: true, get: function () { return
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
Object.defineProperty(exports, "
|
|
15
|
-
|
|
16
|
-
|
|
6
|
+
exports.Git = exports.FileState = exports.OrgTracking = exports.getDeployableClasses = exports.getLocalChanges = exports.getDiffRange = exports.getDefaultBranchDiffByRef = exports.getDefaultBranchDiff = void 0;
|
|
7
|
+
var changes_1 = require("./changes");
|
|
8
|
+
Object.defineProperty(exports, "getDefaultBranchDiff", { enumerable: true, get: function () { return changes_1.getDefaultBranchDiff; } });
|
|
9
|
+
Object.defineProperty(exports, "getDefaultBranchDiffByRef", { enumerable: true, get: function () { return changes_1.getDefaultBranchDiffByRef; } });
|
|
10
|
+
Object.defineProperty(exports, "getDiffRange", { enumerable: true, get: function () { return changes_1.getDiffRange; } });
|
|
11
|
+
Object.defineProperty(exports, "getLocalChanges", { enumerable: true, get: function () { return changes_1.getLocalChanges; } });
|
|
12
|
+
Object.defineProperty(exports, "getDeployableClasses", { enumerable: true, get: function () { return changes_1.getDeployableClasses; } });
|
|
13
|
+
var tracking_1 = require("./tracking");
|
|
14
|
+
Object.defineProperty(exports, "OrgTracking", { enumerable: true, get: function () { return tracking_1.OrgTracking; } });
|
|
15
|
+
Object.defineProperty(exports, "FileState", { enumerable: true, get: function () { return tracking_1.FileState; } });
|
|
16
|
+
var git_1 = require("./git");
|
|
17
|
+
Object.defineProperty(exports, "Git", { enumerable: true, get: function () { return git_1.Git; } });
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Connection } from '@salesforce/core';
|
|
2
|
-
import { Logger } from '../logger/Logger';
|
|
3
2
|
export declare enum FileState {
|
|
4
3
|
Added = "add",
|
|
5
4
|
Modified = "modify",
|
|
@@ -22,7 +21,12 @@ export interface SyncStatus {
|
|
|
22
21
|
export interface OrgTrackingOptions {
|
|
23
22
|
connection: Connection;
|
|
24
23
|
projectDir: string;
|
|
25
|
-
logger:
|
|
24
|
+
logger: OrgTrackingLogger;
|
|
25
|
+
}
|
|
26
|
+
export interface OrgTrackingLogger {
|
|
27
|
+
logError(error: any): void;
|
|
28
|
+
logMessage(message: any): void;
|
|
29
|
+
logDeployProgress(status: string): void;
|
|
26
30
|
}
|
|
27
31
|
export declare class OrgTracking {
|
|
28
32
|
private options;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
* Copyright (c)
|
|
3
|
+
* Copyright (c) 2024 Certinia Inc. All rights reserved.
|
|
4
4
|
*/
|
|
5
5
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
6
6
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
@@ -83,7 +83,7 @@ class OrgTracking {
|
|
|
83
83
|
});
|
|
84
84
|
this.logger.logDeployProgress('Starting deploy');
|
|
85
85
|
deploy.onUpdate(response => {
|
|
86
|
-
const { status, numberComponentsDeployed, numberComponentsTotal
|
|
86
|
+
const { status, numberComponentsDeployed, numberComponentsTotal } = response;
|
|
87
87
|
const progress = `${numberComponentsDeployed}/${numberComponentsTotal}`;
|
|
88
88
|
const message = `Status: ${status} Progress: ${progress}`;
|
|
89
89
|
this.logger.logDeployProgress(message);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
* Copyright (c)
|
|
3
|
+
* Copyright (c) 2024 Certinia Inc. All rights reserved.
|
|
4
4
|
*/
|
|
5
5
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
6
6
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
@@ -11,37 +11,34 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
12
12
|
});
|
|
13
13
|
};
|
|
14
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
15
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
16
|
-
};
|
|
17
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
const
|
|
19
|
-
const BranchChanges_1 = require("../../src/FilesChanged/BranchChanges");
|
|
20
|
-
const path_1 = __importDefault(require("path"));
|
|
21
|
-
jest.mock('path');
|
|
15
|
+
const src_1 = require("../src");
|
|
22
16
|
const mockGitImpl = {
|
|
23
17
|
getDefaultBranchName: jest.fn(),
|
|
24
18
|
getLocalChangedAndCreated: jest.fn(),
|
|
25
19
|
diffRange: jest.fn(),
|
|
26
20
|
gitRoot: jest.fn(),
|
|
21
|
+
getFilteredStatus: jest.fn(),
|
|
27
22
|
};
|
|
28
|
-
jest.mock('
|
|
23
|
+
jest.mock('../src/git', () => {
|
|
24
|
+
const { FileStatus } = jest.requireActual('../src/git');
|
|
29
25
|
return {
|
|
30
26
|
Git: jest.fn().mockImplementation(() => mockGitImpl),
|
|
27
|
+
FileStatus,
|
|
31
28
|
};
|
|
32
29
|
});
|
|
33
|
-
const mockedGit = jest.mocked(Git_1.Git, { shallow: true });
|
|
34
30
|
describe('Branch changes', () => {
|
|
35
|
-
const mockRootDir = '
|
|
36
|
-
|
|
37
|
-
mockGitImpl.gitRoot.mockResolvedValue(
|
|
38
|
-
jest
|
|
39
|
-
.spyOn(path_1.default, 'resolve')
|
|
40
|
-
.mockImplementation(dir => `${mockRootDir}/${dir}`);
|
|
41
|
-
jest.spyOn(path_1.default, 'join').mockImplementation((a, b) => `${a}/${b}`);
|
|
31
|
+
const mockRootDir = '/reporoot';
|
|
32
|
+
beforeEach(() => {
|
|
33
|
+
mockGitImpl.gitRoot.mockResolvedValue(mockRootDir);
|
|
42
34
|
});
|
|
43
35
|
afterEach(() => {
|
|
44
36
|
jest.clearAllMocks();
|
|
37
|
+
mockGitImpl.getDefaultBranchName.mockReset();
|
|
38
|
+
mockGitImpl.getLocalChangedAndCreated.mockReset();
|
|
39
|
+
mockGitImpl.diffRange.mockReset();
|
|
40
|
+
mockGitImpl.gitRoot.mockReset();
|
|
41
|
+
mockGitImpl.getFilteredStatus.mockReset();
|
|
45
42
|
});
|
|
46
43
|
describe('getDefaultBranchDiffByRef', () => {
|
|
47
44
|
it('returns the correct set of files when git ops resolve', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -50,23 +47,22 @@ describe('Branch changes', () => {
|
|
|
50
47
|
mockGitImpl.diffRange.mockResolvedValue(new Set(['File.txt', 'AnotherClass.txt']));
|
|
51
48
|
mockGitImpl.getLocalChangedAndCreated.mockResolvedValue(new Set(['SomeFile.txt']));
|
|
52
49
|
//When
|
|
53
|
-
const res = yield (0,
|
|
50
|
+
const res = yield (0, src_1.getDefaultBranchDiffByRef)('./some/path/to/dir', 'abc12fcd');
|
|
54
51
|
//Then
|
|
55
|
-
expect(mockedGit).toHaveBeenCalledWith('./some/path/to/dir');
|
|
56
52
|
expect(mockGitImpl.getDefaultBranchName).toBeCalledTimes(1);
|
|
57
53
|
expect(mockGitImpl.getLocalChangedAndCreated).toBeCalledTimes(1);
|
|
58
54
|
expect(mockGitImpl.diffRange).toHaveBeenCalledWith('default/branch/name', 'abc12fcd');
|
|
59
55
|
expect(res).toEqual(new Set([
|
|
60
|
-
`${mockRootDir}/
|
|
61
|
-
`${mockRootDir}/
|
|
62
|
-
`${mockRootDir}/
|
|
56
|
+
`${mockRootDir}/File.txt`,
|
|
57
|
+
`${mockRootDir}/AnotherClass.txt`,
|
|
58
|
+
`${mockRootDir}/SomeFile.txt`,
|
|
63
59
|
]));
|
|
64
60
|
}));
|
|
65
61
|
it('rejects and throws error when "getDefaultBranchName" fails', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
66
62
|
//Given
|
|
67
63
|
mockGitImpl.getDefaultBranchName.mockRejectedValue(Error('no head ref error'));
|
|
68
64
|
//When/Then
|
|
69
|
-
yield expect((0,
|
|
65
|
+
yield expect((0, src_1.getDefaultBranchDiffByRef)('./some/path/to/dir', 'abc12fcd')).rejects.toEqual(Error("Local branch operation failed. Cause: 'no head ref error'"));
|
|
70
66
|
}));
|
|
71
67
|
it('rejects and throws error when "getLocalChangedAndCreated" fails', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
72
68
|
//Given
|
|
@@ -74,7 +70,7 @@ describe('Branch changes', () => {
|
|
|
74
70
|
mockGitImpl.diffRange.mockResolvedValue(new Set(['File.txt', 'AnotherClass.txt']));
|
|
75
71
|
mockGitImpl.getLocalChangedAndCreated.mockRejectedValue(Error('op failed'));
|
|
76
72
|
//When/Then
|
|
77
|
-
yield expect((0,
|
|
73
|
+
yield expect((0, src_1.getDefaultBranchDiffByRef)('./some/path/to/dir', 'abc12fcd')).rejects.toEqual(Error("Local branch operation failed. Cause: 'Getting diff operation failed. Cause: 'op failed''"));
|
|
78
74
|
}));
|
|
79
75
|
});
|
|
80
76
|
describe('getDefaultBranchDiff', () => {
|
|
@@ -84,16 +80,15 @@ describe('Branch changes', () => {
|
|
|
84
80
|
mockGitImpl.diffRange.mockResolvedValue(new Set(['File.txt', 'AnotherClass.txt']));
|
|
85
81
|
mockGitImpl.getLocalChangedAndCreated.mockResolvedValue(new Set(['SomeFile.txt']));
|
|
86
82
|
//When
|
|
87
|
-
const res = yield (0,
|
|
83
|
+
const res = yield (0, src_1.getDefaultBranchDiff)('./some/path/to/dir');
|
|
88
84
|
//Then
|
|
89
|
-
expect(mockedGit).toHaveBeenCalledWith('./some/path/to/dir');
|
|
90
85
|
expect(mockGitImpl.getDefaultBranchName).toBeCalledTimes(1);
|
|
91
86
|
expect(mockGitImpl.getLocalChangedAndCreated).toBeCalledTimes(1);
|
|
92
87
|
expect(mockGitImpl.diffRange).toHaveBeenCalledWith('default/branch/name', 'HEAD');
|
|
93
88
|
expect(res).toEqual(new Set([
|
|
94
|
-
`${mockRootDir}/
|
|
95
|
-
`${mockRootDir}/
|
|
96
|
-
`${mockRootDir}/
|
|
89
|
+
`${mockRootDir}/File.txt`,
|
|
90
|
+
`${mockRootDir}/AnotherClass.txt`,
|
|
91
|
+
`${mockRootDir}/SomeFile.txt`,
|
|
97
92
|
]));
|
|
98
93
|
}));
|
|
99
94
|
it('rejects and throws error when "getLocalChangedAndCreated" fails', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -102,7 +97,7 @@ describe('Branch changes', () => {
|
|
|
102
97
|
mockGitImpl.diffRange.mockResolvedValue(new Set(['File.txt', 'AnotherClass.txt']));
|
|
103
98
|
mockGitImpl.getLocalChangedAndCreated.mockRejectedValue(Error('op failed'));
|
|
104
99
|
//When/Then
|
|
105
|
-
yield expect((0,
|
|
100
|
+
yield expect((0, src_1.getDefaultBranchDiff)('./some/path/to/dir')).rejects.toEqual(Error("Local branch operation failed. Cause: 'Getting diff operation failed. Cause: 'op failed''"));
|
|
106
101
|
}));
|
|
107
102
|
});
|
|
108
103
|
describe('getDiffRange', () => {
|
|
@@ -111,15 +106,14 @@ describe('Branch changes', () => {
|
|
|
111
106
|
mockGitImpl.diffRange.mockResolvedValue(new Set(['File.txt', 'AnotherClass.txt']));
|
|
112
107
|
mockGitImpl.getLocalChangedAndCreated.mockResolvedValue(new Set(['SomeFile.txt']));
|
|
113
108
|
//When
|
|
114
|
-
const res = yield (0,
|
|
109
|
+
const res = yield (0, src_1.getDiffRange)('./some/path/to/dir', 'ref1', 'ref2');
|
|
115
110
|
//Then
|
|
116
|
-
expect(mockedGit).toHaveBeenCalledWith('./some/path/to/dir');
|
|
117
111
|
expect(mockGitImpl.getLocalChangedAndCreated).toBeCalledTimes(1);
|
|
118
112
|
expect(mockGitImpl.diffRange).toHaveBeenCalledWith('ref1', 'ref2');
|
|
119
113
|
expect(res).toEqual(new Set([
|
|
120
|
-
`${mockRootDir}/
|
|
121
|
-
`${mockRootDir}/
|
|
122
|
-
`${mockRootDir}/
|
|
114
|
+
`${mockRootDir}/File.txt`,
|
|
115
|
+
`${mockRootDir}/AnotherClass.txt`,
|
|
116
|
+
`${mockRootDir}/SomeFile.txt`,
|
|
123
117
|
]));
|
|
124
118
|
}));
|
|
125
119
|
it('rejects and throws error when "getLocalChangedAndCreated" fails', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -128,7 +122,7 @@ describe('Branch changes', () => {
|
|
|
128
122
|
mockGitImpl.diffRange.mockResolvedValue(new Set(['File.txt', 'AnotherClass.txt']));
|
|
129
123
|
mockGitImpl.getLocalChangedAndCreated.mockRejectedValue(Error('op failed'));
|
|
130
124
|
//When/Then
|
|
131
|
-
yield expect((0,
|
|
125
|
+
yield expect((0, src_1.getDiffRange)('./some/path/to/dir', 'ref1', 'ref2')).rejects.toEqual(Error("Getting diff operation failed. Cause: 'op failed'"));
|
|
132
126
|
}));
|
|
133
127
|
});
|
|
134
128
|
describe('getLocalChanges', () => {
|
|
@@ -136,17 +130,66 @@ describe('Branch changes', () => {
|
|
|
136
130
|
//Given
|
|
137
131
|
mockGitImpl.getLocalChangedAndCreated.mockResolvedValue(new Set(['SomeFile.txt']));
|
|
138
132
|
//When
|
|
139
|
-
const res = yield (0,
|
|
133
|
+
const res = yield (0, src_1.getLocalChanges)('./some/path/to/dir');
|
|
140
134
|
//Then
|
|
141
|
-
expect(mockedGit).toHaveBeenCalledWith('./some/path/to/dir');
|
|
142
135
|
expect(mockGitImpl.getLocalChangedAndCreated).toBeCalledTimes(1);
|
|
143
|
-
expect(res).toEqual(new Set([`${mockRootDir}/
|
|
136
|
+
expect(res).toEqual(new Set([`${mockRootDir}/SomeFile.txt`]));
|
|
144
137
|
}));
|
|
145
138
|
it('rejects and throws error when op fails', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
146
139
|
//Given
|
|
147
140
|
mockGitImpl.getLocalChangedAndCreated.mockRejectedValue(Error('op failed'));
|
|
148
141
|
//When/Then
|
|
149
|
-
yield expect((0,
|
|
142
|
+
yield expect((0, src_1.getLocalChanges)('./some/path/to/dir')).rejects.toEqual(Error("Getting local changes operation failed. Cause: 'op failed'"));
|
|
143
|
+
}));
|
|
144
|
+
});
|
|
145
|
+
describe('getDeployableClasses', () => {
|
|
146
|
+
it('returns the correct set of files', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
147
|
+
//Given
|
|
148
|
+
const pdir = `${mockRootDir}/project/dir`;
|
|
149
|
+
mockGitImpl.getFilteredStatus.mockImplementation(fn => {
|
|
150
|
+
const files = [
|
|
151
|
+
{
|
|
152
|
+
path: `${pdir}/SomeFile.cls`,
|
|
153
|
+
working_dir: 'M',
|
|
154
|
+
},
|
|
155
|
+
];
|
|
156
|
+
return Promise.resolve(new Set(files.filter(fn).map(p => p.path)));
|
|
157
|
+
});
|
|
158
|
+
//When
|
|
159
|
+
const res = yield (0, src_1.getDeployableClasses)(pdir, 'orgId');
|
|
160
|
+
//Then
|
|
161
|
+
expect(mockGitImpl.getFilteredStatus).toBeCalledTimes(1);
|
|
162
|
+
expect(mockGitImpl.getFilteredStatus).toHaveBeenCalledWith(expect.anything(), `${pdir}/.sf/orgs/orgId/localSourceTracking`);
|
|
163
|
+
expect(res).toEqual(new Set([`${pdir}/SomeFile.cls`]));
|
|
164
|
+
}));
|
|
165
|
+
it('filters non classes and deleted', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
166
|
+
//Given
|
|
167
|
+
const pdir = `${mockRootDir}/project/dir`;
|
|
168
|
+
mockGitImpl.getFilteredStatus.mockImplementation(fn => {
|
|
169
|
+
const files = [
|
|
170
|
+
{
|
|
171
|
+
path: `${pdir}/SomeFile.txt`,
|
|
172
|
+
working_dir: 'M',
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
path: `${pdir}/SomeFile2.cls`,
|
|
176
|
+
working_dir: 'D',
|
|
177
|
+
},
|
|
178
|
+
];
|
|
179
|
+
return Promise.resolve(new Set(files.filter(fn).map(p => p.path)));
|
|
180
|
+
});
|
|
181
|
+
//When
|
|
182
|
+
const res = yield (0, src_1.getDeployableClasses)(pdir, 'orgId');
|
|
183
|
+
//Then
|
|
184
|
+
expect(mockGitImpl.getFilteredStatus).toBeCalledTimes(1);
|
|
185
|
+
expect(mockGitImpl.getFilteredStatus).toHaveBeenCalledWith(expect.anything(), `${pdir}/.sf/orgs/orgId/localSourceTracking`);
|
|
186
|
+
expect(res).toEqual(new Set());
|
|
187
|
+
}));
|
|
188
|
+
it('rejects and throws error when op fails', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
189
|
+
//Given
|
|
190
|
+
mockGitImpl.getFilteredStatus.mockRejectedValue(Error('op failed'));
|
|
191
|
+
//When/Then
|
|
192
|
+
yield expect((0, src_1.getDeployableClasses)('/project/dir', 'orgId')).rejects.toEqual(Error("Getting local changes operation failed. Cause: 'op failed'"));
|
|
150
193
|
}));
|
|
151
194
|
});
|
|
152
195
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
* Copyright (c)
|
|
3
|
+
* Copyright (c) 2024 Certinia Inc. All rights reserved.
|
|
4
4
|
*/
|
|
5
5
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
6
6
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
@@ -16,17 +16,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
16
16
|
};
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
const path_1 = __importDefault(require("path"));
|
|
19
|
-
const
|
|
20
|
-
const
|
|
19
|
+
const src_1 = require("../src");
|
|
20
|
+
const repo_1 = require("./helpers/repo");
|
|
21
21
|
describe('Git', () => {
|
|
22
22
|
const dir = './test/repos';
|
|
23
|
-
const
|
|
23
|
+
const repoHelper = repo_1.RepoHelper.getInstance(dir);
|
|
24
24
|
beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
|
-
yield
|
|
26
|
-
}));
|
|
27
|
-
afterEach(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
|
-
yield repoManager.tearDown();
|
|
25
|
+
yield repoHelper.init();
|
|
29
26
|
}));
|
|
27
|
+
afterEach(() => {
|
|
28
|
+
repoHelper.tearDown();
|
|
29
|
+
});
|
|
30
30
|
describe('version check', () => {
|
|
31
31
|
it('does not fail when Git version is equal to 2.20.0', () => {
|
|
32
32
|
//Given/When
|
|
@@ -38,7 +38,7 @@ describe('Git', () => {
|
|
|
38
38
|
patch: 0,
|
|
39
39
|
}),
|
|
40
40
|
};
|
|
41
|
-
expect(
|
|
41
|
+
expect(src_1.Git.versionCheck(mock)).resolves;
|
|
42
42
|
});
|
|
43
43
|
it('does not fail when Git version is higher', () => {
|
|
44
44
|
//Given/When
|
|
@@ -51,7 +51,7 @@ describe('Git', () => {
|
|
|
51
51
|
}),
|
|
52
52
|
};
|
|
53
53
|
//Then
|
|
54
|
-
expect(
|
|
54
|
+
expect(src_1.Git.versionCheck(mock)).resolves;
|
|
55
55
|
});
|
|
56
56
|
it('fails when Git is not installed', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
57
57
|
//Given/When
|
|
@@ -59,7 +59,7 @@ describe('Git', () => {
|
|
|
59
59
|
version: jest.fn().mockReturnValue({ installed: false }),
|
|
60
60
|
};
|
|
61
61
|
//Then
|
|
62
|
-
yield expect(
|
|
62
|
+
yield expect(src_1.Git.versionCheck(mock)).rejects.toThrow(Error('"git" is not installed or available on the PATH'));
|
|
63
63
|
}));
|
|
64
64
|
it('fails when Git major version is lower', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
65
65
|
//Given/When
|
|
@@ -70,7 +70,7 @@ describe('Git', () => {
|
|
|
70
70
|
}),
|
|
71
71
|
};
|
|
72
72
|
//Then
|
|
73
|
-
yield expect(
|
|
73
|
+
yield expect(src_1.Git.versionCheck(mock)).rejects.toThrow(Error('Unsupported version of git. Min version must be 2.20'));
|
|
74
74
|
}));
|
|
75
75
|
it('fails when Git minor version is lower', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
76
76
|
//Given/When
|
|
@@ -82,130 +82,126 @@ describe('Git', () => {
|
|
|
82
82
|
}),
|
|
83
83
|
};
|
|
84
84
|
//Then
|
|
85
|
-
yield expect(
|
|
85
|
+
yield expect(src_1.Git.versionCheck(mock)).rejects.toThrow(Error('Unsupported version of git. Min version must be 2.20'));
|
|
86
86
|
}));
|
|
87
87
|
});
|
|
88
88
|
describe('rev parse', () => {
|
|
89
89
|
it('get git root', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
90
|
-
const repoDirPath = path_1.default.resolve(
|
|
91
|
-
const revParse = yield new
|
|
90
|
+
const repoDirPath = path_1.default.resolve(repoHelper.repoDir);
|
|
91
|
+
const revParse = yield new src_1.Git(repoHelper.repoDir).gitRoot();
|
|
92
92
|
expect(revParse).toBe(repoDirPath);
|
|
93
93
|
}));
|
|
94
94
|
});
|
|
95
95
|
describe('branch operation', () => {
|
|
96
96
|
it('fails to find default branch name when head is not set', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
97
97
|
//Given/When/Then
|
|
98
|
-
yield expect(new
|
|
98
|
+
yield expect(new src_1.Git(repoHelper.repoDir).getDefaultBranchName()).rejects.toThrow(Error("Failed to find symbolic ref no remote HEAD with message: 'fatal: ref refs/remotes/origin/HEAD is not a symbolic ref'"));
|
|
99
99
|
}));
|
|
100
100
|
it('find default branch name when head is set', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
101
101
|
//Given
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
.
|
|
105
|
-
.then(() =>
|
|
106
|
-
.then(() =>
|
|
102
|
+
repoHelper.createOrUpdateFile('file.txt', 'Test Text');
|
|
103
|
+
yield repoHelper
|
|
104
|
+
.stageAndCommitAll(['file.txt'])
|
|
105
|
+
.then(() => repoHelper.push())
|
|
106
|
+
.then(() => repoHelper.setHead());
|
|
107
107
|
//When
|
|
108
|
-
const branchName = yield new
|
|
108
|
+
const branchName = yield new src_1.Git(repoHelper.repoDir).getDefaultBranchName();
|
|
109
109
|
//Then
|
|
110
110
|
expect(branchName).toBe('origin/main');
|
|
111
111
|
}));
|
|
112
112
|
it('find default branch name when head is set', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
113
113
|
//Given
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
.
|
|
117
|
-
.then(() =>
|
|
118
|
-
.then(() =>
|
|
114
|
+
repoHelper.createOrUpdateFile('file.txt', 'Test Text');
|
|
115
|
+
yield repoHelper
|
|
116
|
+
.stageAndCommitAll(['file.txt'])
|
|
117
|
+
.then(() => repoHelper.push())
|
|
118
|
+
.then(() => repoHelper.setHead());
|
|
119
119
|
//When
|
|
120
|
-
const branchName = yield new
|
|
120
|
+
const branchName = yield new src_1.Git(repoHelper.repoDir).getDefaultBranchName();
|
|
121
121
|
//Then
|
|
122
122
|
expect(branchName).toBe('origin/main');
|
|
123
123
|
}));
|
|
124
124
|
});
|
|
125
125
|
describe('file change operations', () => {
|
|
126
126
|
beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
.
|
|
130
|
-
.then(() =>
|
|
131
|
-
.then(() =>
|
|
127
|
+
repoHelper.createOrUpdateFile('file.txt', 'text');
|
|
128
|
+
yield repoHelper
|
|
129
|
+
.stageAndCommitAll(['file.txt'])
|
|
130
|
+
.then(() => repoHelper.push())
|
|
131
|
+
.then(() => repoHelper.setHead());
|
|
132
132
|
}));
|
|
133
133
|
describe('local changes', () => {
|
|
134
134
|
it('finds modified files', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
135
135
|
//Given
|
|
136
|
-
|
|
136
|
+
repoHelper.createOrUpdateFile('file.txt', 'modify');
|
|
137
137
|
//When
|
|
138
|
-
const files = yield new
|
|
138
|
+
const files = yield new src_1.Git(repoHelper.repoDir).getLocalChangedAndCreated();
|
|
139
139
|
//Then
|
|
140
140
|
expect(files).toEqual(new Set(['file.txt']));
|
|
141
141
|
}));
|
|
142
142
|
it('finds unstaged renamed files', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
143
143
|
//Given
|
|
144
|
-
|
|
145
|
-
// await
|
|
144
|
+
repoHelper.renameFileInRepo('file.txt', 'renamed.txt');
|
|
145
|
+
// await repoHelper.gitStage();
|
|
146
146
|
//When
|
|
147
|
-
const files = yield new
|
|
147
|
+
const files = yield new src_1.Git(repoHelper.repoDir).getLocalChangedAndCreated();
|
|
148
148
|
//Then
|
|
149
149
|
expect(files).toEqual(new Set(['renamed.txt']));
|
|
150
150
|
}));
|
|
151
151
|
it('finds unstaged new files', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
152
152
|
//Given
|
|
153
|
-
|
|
153
|
+
repoHelper.createOrUpdateFile('newFile.txt', 'content');
|
|
154
154
|
//When
|
|
155
|
-
const files = yield new
|
|
155
|
+
const files = yield new src_1.Git(repoHelper.repoDir).getLocalChangedAndCreated();
|
|
156
156
|
//Then
|
|
157
157
|
expect(files).toEqual(new Set(['newFile.txt']));
|
|
158
158
|
}));
|
|
159
159
|
it('does not include deleted files', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
160
160
|
//Given
|
|
161
|
-
|
|
161
|
+
repoHelper.rmFile('file.txt');
|
|
162
162
|
//When
|
|
163
|
-
const files = yield new
|
|
163
|
+
const files = yield new src_1.Git(repoHelper.repoDir).getLocalChangedAndCreated();
|
|
164
164
|
//Then
|
|
165
165
|
expect(files).toEqual(new Set());
|
|
166
166
|
}));
|
|
167
167
|
it('finds staged renamed, modified and new files ', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
168
168
|
//Setup for renamed file
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
.then(() => repoManager.stageAndCommitAll(['second.txt']));
|
|
169
|
+
repoHelper.createOrUpdateFile('second.txt', 'txt');
|
|
170
|
+
yield repoHelper.stageAndCommitAll(['second.txt']);
|
|
172
171
|
//Given
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
.then(() => repoManager.stageAll());
|
|
172
|
+
repoHelper.createOrUpdateFile('file.txt', 'modifiy');
|
|
173
|
+
repoHelper.renameFileInRepo('second.txt', 'renamed.txt');
|
|
174
|
+
repoHelper.createOrUpdateFile('newFile.txt', 'content');
|
|
175
|
+
yield repoHelper.stageAll();
|
|
178
176
|
//When
|
|
179
|
-
const files = yield new
|
|
177
|
+
const files = yield new src_1.Git(repoHelper.repoDir).getLocalChangedAndCreated();
|
|
180
178
|
//Then
|
|
181
179
|
expect(files).toEqual(new Set(['file.txt', 'renamed.txt', 'newFile.txt']));
|
|
182
180
|
}));
|
|
183
181
|
});
|
|
184
182
|
describe('branch diff changes', () => {
|
|
185
183
|
beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
186
|
-
yield
|
|
184
|
+
yield repoHelper
|
|
187
185
|
.checkout('dev', 'main')
|
|
188
|
-
.then(() =>
|
|
189
|
-
.then(() =>
|
|
186
|
+
.then(() => repoHelper.createOrUpdateFile('newFile.txt', 'text'))
|
|
187
|
+
.then(() => repoHelper.stageAndCommitAll(['newFile.txt']));
|
|
190
188
|
}));
|
|
191
189
|
it('finds diff against for default branch and HEAD', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
192
190
|
//Given
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
.then(() => repoManager.stageAndCommitAll(['anotherFileForCommit.txt']));
|
|
191
|
+
repoHelper.createOrUpdateFile('anotherFileForCommit.txt', 'text');
|
|
192
|
+
yield repoHelper.stageAndCommitAll(['anotherFileForCommit.txt']);
|
|
196
193
|
//When
|
|
197
|
-
const files = yield new
|
|
194
|
+
const files = yield new src_1.Git(repoHelper.repoDir).diffRange('origin/main', 'HEAD');
|
|
198
195
|
//Then
|
|
199
196
|
expect(files).toEqual(new Set(['newFile.txt', 'anotherFileForCommit.txt']));
|
|
200
197
|
}));
|
|
201
198
|
it('finds diff against default branch and commit ref', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
202
199
|
//Given
|
|
203
|
-
const currentRef = (yield
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
.then(() => repoManager.stageAndCommitAll(['anotherFileForCommit.txt']));
|
|
200
|
+
const currentRef = (yield repoHelper.getGitLog())[0].hash;
|
|
201
|
+
repoHelper.createOrUpdateFile('anotherFileForCommit.txt', 'text');
|
|
202
|
+
yield repoHelper.stageAndCommitAll(['anotherFileForCommit.txt']);
|
|
207
203
|
//When
|
|
208
|
-
const files = yield new
|
|
204
|
+
const files = yield new src_1.Git(repoHelper.repoDir).diffRange('origin/main', currentRef);
|
|
209
205
|
//Then
|
|
210
206
|
expect(files).toEqual(new Set(['newFile.txt']));
|
|
211
207
|
}));
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export declare class
|
|
1
|
+
export declare class RepoHelper {
|
|
2
2
|
private isInit;
|
|
3
3
|
private rootDir;
|
|
4
4
|
private remoteRepoDir;
|
|
5
5
|
private testRepoDir;
|
|
6
6
|
private static instances;
|
|
7
7
|
private constructor();
|
|
8
|
-
static getInstance(rootDir: string):
|
|
8
|
+
static getInstance(rootDir: string): RepoHelper;
|
|
9
9
|
private get git();
|
|
10
10
|
private initRemoteRepo;
|
|
11
11
|
private cloneRepo;
|
|
@@ -17,8 +17,8 @@ export declare class RepoManager {
|
|
|
17
17
|
stageAll(files?: string[]): Promise<string>;
|
|
18
18
|
getGitLog(): Promise<readonly (import("simple-git").DefaultLogFields & import("simple-git").ListLogLine)[]>;
|
|
19
19
|
stageAndCommitAll(files?: string[]): Promise<import("simple-git").CommitResult>;
|
|
20
|
-
tearDown():
|
|
21
|
-
createOrUpdateFile(fileName: string, content: string):
|
|
20
|
+
tearDown(): void;
|
|
21
|
+
createOrUpdateFile(fileName: string, content: string): void;
|
|
22
22
|
rmFile(file: string): void;
|
|
23
23
|
renameFileInRepo(from: string, to: string): void;
|
|
24
24
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
* Copyright (c)
|
|
3
|
+
* Copyright (c) 2024 Certinia Inc. All rights reserved.
|
|
4
4
|
*/
|
|
5
5
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
6
6
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
@@ -15,11 +15,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
15
15
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
16
16
|
};
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.
|
|
18
|
+
exports.RepoHelper = void 0;
|
|
19
19
|
const simple_git_1 = __importDefault(require("simple-git"));
|
|
20
20
|
const fs_1 = __importDefault(require("fs"));
|
|
21
21
|
const path_1 = __importDefault(require("path"));
|
|
22
|
-
class
|
|
22
|
+
class RepoHelper {
|
|
23
23
|
constructor(rootDir) {
|
|
24
24
|
this.isInit = false;
|
|
25
25
|
this.rootDir = rootDir;
|
|
@@ -27,10 +27,12 @@ class RepoManager {
|
|
|
27
27
|
this.testRepoDir = rootDir + '/test-repo';
|
|
28
28
|
}
|
|
29
29
|
static getInstance(rootDir) {
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
let mng = this.instances.get(rootDir);
|
|
31
|
+
if (!mng) {
|
|
32
|
+
mng = new RepoHelper(rootDir);
|
|
33
|
+
this.instances.set(rootDir, mng);
|
|
32
34
|
}
|
|
33
|
-
return
|
|
35
|
+
return mng;
|
|
34
36
|
}
|
|
35
37
|
get git() {
|
|
36
38
|
if (!this.isInit) {
|
|
@@ -105,20 +107,16 @@ class RepoManager {
|
|
|
105
107
|
});
|
|
106
108
|
}
|
|
107
109
|
tearDown() {
|
|
108
|
-
|
|
109
|
-
yield fs_1.default.promises.rm(this.rootDir, { recursive: true, force: true });
|
|
110
|
-
});
|
|
110
|
+
fs_1.default.rmSync(this.rootDir, { recursive: true, force: true });
|
|
111
111
|
}
|
|
112
112
|
createOrUpdateFile(fileName, content) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
});
|
|
113
|
+
const fPath = path_1.default.join(this.testRepoDir, fileName);
|
|
114
|
+
if (fs_1.default.existsSync(fPath)) {
|
|
115
|
+
fs_1.default.appendFileSync(fPath, content);
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
fs_1.default.writeFileSync(fPath, content);
|
|
119
|
+
}
|
|
122
120
|
}
|
|
123
121
|
rmFile(file) {
|
|
124
122
|
fs_1.default.unlinkSync(path_1.default.join(this.testRepoDir, file));
|
|
@@ -129,5 +127,5 @@ class RepoManager {
|
|
|
129
127
|
fs_1.default.renameSync(fromPath, toPath);
|
|
130
128
|
}
|
|
131
129
|
}
|
|
132
|
-
exports.
|
|
133
|
-
|
|
130
|
+
exports.RepoHelper = RepoHelper;
|
|
131
|
+
RepoHelper.instances = new Map();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
* Copyright (c)
|
|
3
|
+
* Copyright (c) 2024 Certinia Inc. All rights reserved.
|
|
4
4
|
*/
|
|
5
5
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
6
6
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
@@ -12,7 +12,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
12
12
|
});
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const src_1 = require("
|
|
15
|
+
const src_1 = require("../src");
|
|
16
16
|
const core_1 = require("@salesforce/core");
|
|
17
17
|
const mockGetStatusData = [
|
|
18
18
|
{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apexdevtools/git-ops",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Library to do git operations to find changed files in a given git repository",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Apex Dev Tools Team",
|
|
@@ -17,44 +17,39 @@
|
|
|
17
17
|
"type": "git",
|
|
18
18
|
"url": "git+https://github.com/apex-dev-tools/git-ops.git"
|
|
19
19
|
},
|
|
20
|
-
"engines": {
|
|
21
|
-
"node": ">=14.0"
|
|
22
|
-
},
|
|
23
20
|
"keywords": [
|
|
24
21
|
"salesforce",
|
|
25
|
-
"
|
|
26
|
-
"apexlink"
|
|
22
|
+
"source"
|
|
27
23
|
],
|
|
28
24
|
"bugs": {
|
|
29
25
|
"url": "https://github.com/apex-dev-tools/git-ops/issues"
|
|
30
26
|
},
|
|
31
27
|
"homepage": "https://github.com/apex-dev-tools/git-ops#readme",
|
|
32
|
-
"
|
|
33
|
-
"@ryansonshine/commitizen": "4.2.8",
|
|
34
|
-
"@ryansonshine/cz-conventional-changelog": "3.3.4",
|
|
35
|
-
"@types/jest": "^29.4.0",
|
|
36
|
-
"@types/node": "^18.11.19",
|
|
37
|
-
"@typescript-eslint/eslint-plugin": "^5.52.0",
|
|
38
|
-
"@typescript-eslint/parser": "^5.0.0",
|
|
39
|
-
"conventional-changelog-conventionalcommits": "5.0.0",
|
|
40
|
-
"eslint": "7.25.0",
|
|
41
|
-
"eslint-config-prettier": "8.3.0",
|
|
42
|
-
"eslint-plugin-node": "11.1.0",
|
|
43
|
-
"eslint-plugin-prettier": "3.4.0",
|
|
44
|
-
"husky": "^8.0.0",
|
|
45
|
-
"jest": "^29.4.2",
|
|
46
|
-
"lint-staged": "10.5.4",
|
|
47
|
-
"prettier": "2.2.1",
|
|
48
|
-
"semantic-release": "19.0.2",
|
|
49
|
-
"ts-jest": "^29.0.5",
|
|
50
|
-
"typescript": "^4.9.5"
|
|
51
|
-
},
|
|
28
|
+
"packageManager": "pnpm@8.9.2",
|
|
52
29
|
"dependencies": {
|
|
53
|
-
"@salesforce/core": "^3.
|
|
54
|
-
"@salesforce/source-deploy-retrieve": "
|
|
55
|
-
"@salesforce/source-tracking": "
|
|
30
|
+
"@salesforce/core": "^4.3.11",
|
|
31
|
+
"@salesforce/source-deploy-retrieve": "^9.2.8",
|
|
32
|
+
"@salesforce/source-tracking": "^4.2.2",
|
|
56
33
|
"simple-git": "^3.16.0"
|
|
57
34
|
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@ryansonshine/commitizen": "^4.2.8",
|
|
37
|
+
"@ryansonshine/cz-conventional-changelog": "^3.3.4",
|
|
38
|
+
"@types/jest": "^29.5.0",
|
|
39
|
+
"@types/node": "^18.15.11",
|
|
40
|
+
"@typescript-eslint/eslint-plugin": "^5.59.8",
|
|
41
|
+
"@typescript-eslint/parser": "^5.59.8",
|
|
42
|
+
"eslint": "^8.41.0",
|
|
43
|
+
"eslint-config-prettier": "^8.8.0",
|
|
44
|
+
"eslint-plugin-node": "^11.1.0",
|
|
45
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
46
|
+
"husky": "^8.0.3",
|
|
47
|
+
"jest": "^29.5.0",
|
|
48
|
+
"lint-staged": "^13.2.2",
|
|
49
|
+
"prettier": "^2.8.8",
|
|
50
|
+
"ts-jest": "^29.1.0",
|
|
51
|
+
"typescript": "^4.9.5"
|
|
52
|
+
},
|
|
58
53
|
"config": {
|
|
59
54
|
"commitizen": {
|
|
60
55
|
"path": "./node_modules/@ryansonshine/cz-conventional-changelog"
|
|
@@ -63,59 +58,12 @@
|
|
|
63
58
|
"lint-staged": {
|
|
64
59
|
"*.ts": "eslint --cache --cache-location .eslintcache --fix"
|
|
65
60
|
},
|
|
66
|
-
"release": {
|
|
67
|
-
"branches": [
|
|
68
|
-
"main"
|
|
69
|
-
],
|
|
70
|
-
"plugins": [
|
|
71
|
-
[
|
|
72
|
-
"@semantic-release/commit-analyzer",
|
|
73
|
-
{
|
|
74
|
-
"preset": "conventionalcommits",
|
|
75
|
-
"releaseRules": [
|
|
76
|
-
{
|
|
77
|
-
"type": "build",
|
|
78
|
-
"scope": "deps",
|
|
79
|
-
"release": "patch"
|
|
80
|
-
}
|
|
81
|
-
]
|
|
82
|
-
}
|
|
83
|
-
],
|
|
84
|
-
[
|
|
85
|
-
"@semantic-release/release-notes-generator",
|
|
86
|
-
{
|
|
87
|
-
"preset": "conventionalcommits",
|
|
88
|
-
"presetConfig": {
|
|
89
|
-
"types": [
|
|
90
|
-
{
|
|
91
|
-
"type": "feat",
|
|
92
|
-
"section": "Features"
|
|
93
|
-
},
|
|
94
|
-
{
|
|
95
|
-
"type": "fix",
|
|
96
|
-
"section": "Bug Fixes"
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
"type": "build",
|
|
100
|
-
"section": "Dependencies and Other Build Updates",
|
|
101
|
-
"hidden": false
|
|
102
|
-
}
|
|
103
|
-
]
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
],
|
|
107
|
-
"@semantic-release/npm",
|
|
108
|
-
"@semantic-release/github"
|
|
109
|
-
]
|
|
110
|
-
},
|
|
111
61
|
"scripts": {
|
|
112
62
|
"build": "tsc",
|
|
113
63
|
"clean": "rm -rf ./lib/",
|
|
114
|
-
"
|
|
64
|
+
"commit": "cz",
|
|
115
65
|
"lint": "eslint ./src/ --fix",
|
|
116
|
-
"semantic-release": "semantic-release",
|
|
117
|
-
"test:watch": "jest --watch",
|
|
118
66
|
"test": "jest --coverage --runInBand",
|
|
119
|
-
"
|
|
67
|
+
"test:watch": "jest --watch"
|
|
120
68
|
}
|
|
121
69
|
}
|
package/lib/src/api/IGit.d.ts
DELETED
package/lib/src/api/IGit.js
DELETED
package/lib/src/logger/Logger.js
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|