@apexdevtools/git-ops 1.0.2 → 1.1.1
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 +9 -0
- package/README.md +30 -4
- package/lib/src/FilesChanged/BranchChanges.d.ts +17 -2
- package/lib/src/FilesChanged/BranchChanges.js +74 -17
- package/lib/src/Git/Git.d.ts +1 -1
- package/lib/src/Git/Git.js +8 -5
- package/lib/src/index.d.ts +1 -1
- package/lib/src/index.js +3 -1
- package/lib/test/BranchChanges/BranchChanges.spec.js +47 -3
- package/lib/test/Git/Git.spec.js +37 -12
- package/package.json +1 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# git-ops - Changelog
|
|
2
2
|
|
|
3
|
+
## 1.1.1 - 2023-03-27
|
|
4
|
+
|
|
5
|
+
- Update minimum version to 2.20.0
|
|
6
|
+
|
|
7
|
+
## 1.1.0 - 2023-03-21
|
|
8
|
+
|
|
9
|
+
- add new method `getDiffRange`
|
|
10
|
+
- add new method `getLocalChanges`
|
|
11
|
+
|
|
3
12
|
## 1.0.2 - 2023-03-20
|
|
4
13
|
|
|
5
14
|
- downgrade min git version to 2.30.0
|
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ Library to do git operations to find changed files in a given git repository.
|
|
|
4
4
|
|
|
5
5
|
## Prerequisite
|
|
6
6
|
|
|
7
|
-
Minimum `git` version of `2.
|
|
7
|
+
Minimum `git` version of `2.20.0` must already be installed on the host machine.
|
|
8
8
|
|
|
9
9
|
## Getting Started
|
|
10
10
|
|
|
@@ -38,14 +38,40 @@ The output of the command is same as running `git diff branchName...ref` combine
|
|
|
38
38
|
|
|
39
39
|
**Note:** files with the status of deleted (`D`) and ignored (`!`) will not be included in the change set.
|
|
40
40
|
|
|
41
|
+
### `getDefaultBranchDiffByRef`
|
|
42
|
+
|
|
43
|
+
Works out changed files using the default branch in that repo given a ref.
|
|
44
|
+
This find the default branch in the repo using `git symbolic-ref 'refs/remotes/origin/HEAD'`
|
|
45
|
+
so the `HEAD` must be set. The output of the command is same as running `git diff branchName...ref` combined with `git status`.
|
|
46
|
+
|
|
47
|
+
Files with the status of deleted (`D`) and ignored (`!`) will not be included in the change set.
|
|
48
|
+
|
|
41
49
|
```TypeScript
|
|
42
|
-
getDefaultBranchDiffByRef(
|
|
50
|
+
getDefaultBranchDiffByRef(repoDir: string, ref: string): Promise<Set<string>>
|
|
43
51
|
```
|
|
44
52
|
|
|
45
|
-
|
|
53
|
+
### `getDefaultBranchDiff`
|
|
46
54
|
|
|
47
55
|
This command is same as calling `getDefaultBranchDiffByRef(repoRootDir, 'HEAD')`.
|
|
48
56
|
|
|
49
57
|
```TypeScript
|
|
50
|
-
getDefaultBranchDiff(
|
|
58
|
+
getDefaultBranchDiff(repoDir: string): Promise<Set<string>>
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### `getDiffRange`
|
|
62
|
+
|
|
63
|
+
Works out the diff between a given range. Equivalent to `git diff ref1...ref2`
|
|
64
|
+
|
|
65
|
+
```Typescript
|
|
66
|
+
getDiffRange(dir: string, fromRef: string, toRef: string): Promise<Set<string>>
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### `getLocalChanges`
|
|
70
|
+
|
|
71
|
+
Get the local changes that not have been committed. Equivalent to `git status`
|
|
72
|
+
|
|
73
|
+
Files with the status of deleted (`D`) and ignored (`!`) will not be included in the change set
|
|
74
|
+
|
|
75
|
+
```TypeScript
|
|
76
|
+
getLocalChanges(dir: string): Promise<Set<string>>
|
|
51
77
|
```
|
|
@@ -11,7 +11,22 @@ export declare function getDefaultBranchDiff(dir: string): Promise<Set<string>>;
|
|
|
11
11
|
* combined with `git status`.
|
|
12
12
|
* Files with the status of deleted (`D`) and ignored (`!`) will not be included in the change set.
|
|
13
13
|
* @param dir: string of the directory thr operation should be performed on
|
|
14
|
-
* @param
|
|
14
|
+
* @param refTo: string git ref. i.e HEAD, or commit hash
|
|
15
15
|
* @returns set of absolute paths of changed files
|
|
16
16
|
*/
|
|
17
|
-
export declare function getDefaultBranchDiffByRef(dir: string,
|
|
17
|
+
export declare function getDefaultBranchDiffByRef(dir: string, refTo: string): Promise<Set<string>>;
|
|
18
|
+
/**
|
|
19
|
+
* Works out the diff between a given range. Equivalent to `git diff ref1...ref2`
|
|
20
|
+
* @param dir string of the directory thr operation should be performed on
|
|
21
|
+
* @param fromRef string git ref. i.e HEAD, or commit hash
|
|
22
|
+
* @param toRef string git ref. i.e HEAD, or commit hash
|
|
23
|
+
* @returns set of absolute paths of changed files
|
|
24
|
+
*/
|
|
25
|
+
export declare function getDiffRange(dir: string, fromRef: string, toRef: string): Promise<Set<string>>;
|
|
26
|
+
/**
|
|
27
|
+
* Get the local changes that not have been committed. Equivalent to `git status`
|
|
28
|
+
* Files with the status of deleted (`D`) and ignored (`!`) will not be included in the change set.
|
|
29
|
+
* @param dir tring of the directory thr operation should be performed on
|
|
30
|
+
* @returns set of absolute paths of un committed files
|
|
31
|
+
*/
|
|
32
|
+
export declare function getLocalChanges(dir: string): Promise<Set<string>>;
|
|
@@ -15,7 +15,7 @@ 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.getDefaultBranchDiffByRef = exports.getDefaultBranchDiff = void 0;
|
|
18
|
+
exports.getLocalChanges = exports.getDiffRange = exports.getDefaultBranchDiffByRef = exports.getDefaultBranchDiff = void 0;
|
|
19
19
|
const path_1 = __importDefault(require("path"));
|
|
20
20
|
const Git_1 = require("../Git/Git");
|
|
21
21
|
/**
|
|
@@ -36,35 +36,67 @@ exports.getDefaultBranchDiff = getDefaultBranchDiff;
|
|
|
36
36
|
* combined with `git status`.
|
|
37
37
|
* Files with the status of deleted (`D`) and ignored (`!`) will not be included in the change set.
|
|
38
38
|
* @param dir: string of the directory thr operation should be performed on
|
|
39
|
-
* @param
|
|
39
|
+
* @param refTo: string git ref. i.e HEAD, or commit hash
|
|
40
40
|
* @returns set of absolute paths of changed files
|
|
41
41
|
*/
|
|
42
|
-
function getDefaultBranchDiffByRef(dir,
|
|
42
|
+
function getDefaultBranchDiffByRef(dir, refTo) {
|
|
43
43
|
return __awaiter(this, void 0, void 0, function* () {
|
|
44
44
|
const git = new Git_1.Git(dir);
|
|
45
|
-
const root = yield git.gitRoot();
|
|
46
45
|
return git
|
|
47
46
|
.getDefaultBranchName()
|
|
48
|
-
.then(
|
|
49
|
-
return yield getChanges(git, branchName, ref);
|
|
50
|
-
}))
|
|
51
|
-
.then(changes => {
|
|
52
|
-
const fullPaths = [...changes].map(p => path_1.default.resolve(path_1.default.join(root, p)));
|
|
53
|
-
return new Set(fullPaths);
|
|
54
|
-
})
|
|
47
|
+
.then(branch => getDiffRange(dir, branch, refTo))
|
|
55
48
|
.catch(er => {
|
|
56
|
-
|
|
57
|
-
throw Error(`Failed getting diff: ${er.message}`);
|
|
58
|
-
else
|
|
59
|
-
throw Error('Failed getting diff');
|
|
49
|
+
throw new NoLocalBranchException(er);
|
|
60
50
|
});
|
|
61
51
|
});
|
|
62
52
|
}
|
|
63
53
|
exports.getDefaultBranchDiffByRef = getDefaultBranchDiffByRef;
|
|
64
|
-
|
|
54
|
+
/**
|
|
55
|
+
* Works out the diff between a given range. Equivalent to `git diff ref1...ref2`
|
|
56
|
+
* @param dir string of the directory thr operation should be performed on
|
|
57
|
+
* @param fromRef string git ref. i.e HEAD, or commit hash
|
|
58
|
+
* @param toRef string git ref. i.e HEAD, or commit hash
|
|
59
|
+
* @returns set of absolute paths of changed files
|
|
60
|
+
*/
|
|
61
|
+
function getDiffRange(dir, fromRef, toRef) {
|
|
62
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
const git = new Git_1.Git(dir);
|
|
64
|
+
const root = yield git.gitRoot();
|
|
65
|
+
return getDiffChanges(git, fromRef, toRef)
|
|
66
|
+
.then(changes => resolvePaths(changes, root))
|
|
67
|
+
.catch(er => {
|
|
68
|
+
throw new DiffFailedException(er);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
exports.getDiffRange = getDiffRange;
|
|
73
|
+
/**
|
|
74
|
+
* Get the local changes that not have been committed. Equivalent to `git status`
|
|
75
|
+
* Files with the status of deleted (`D`) and ignored (`!`) will not be included in the change set.
|
|
76
|
+
* @param dir tring of the directory thr operation should be performed on
|
|
77
|
+
* @returns set of absolute paths of un committed files
|
|
78
|
+
*/
|
|
79
|
+
function getLocalChanges(dir) {
|
|
80
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
+
const git = new Git_1.Git(dir);
|
|
82
|
+
const root = yield git.gitRoot();
|
|
83
|
+
return git
|
|
84
|
+
.getLocalChangedAndCreated()
|
|
85
|
+
.then(changes => resolvePaths(changes, root))
|
|
86
|
+
.catch(er => {
|
|
87
|
+
throw new LocalChangeException(er);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
exports.getLocalChanges = getLocalChanges;
|
|
92
|
+
function resolvePaths(paths, root) {
|
|
93
|
+
const fullPaths = [...paths].map(p => path_1.default.resolve(path_1.default.join(root, p)));
|
|
94
|
+
return new Set(fullPaths);
|
|
95
|
+
}
|
|
96
|
+
function getDiffChanges(git, ref1, ref2) {
|
|
65
97
|
return __awaiter(this, void 0, void 0, function* () {
|
|
66
98
|
const changes = yield Promise.all([
|
|
67
|
-
git.diffRange(
|
|
99
|
+
git.diffRange(ref1, ref2),
|
|
68
100
|
git.getLocalChangedAndCreated(),
|
|
69
101
|
]);
|
|
70
102
|
const allChanges = new Set();
|
|
@@ -72,3 +104,28 @@ function getChanges(git, branchName, ref) {
|
|
|
72
104
|
return allChanges;
|
|
73
105
|
});
|
|
74
106
|
}
|
|
107
|
+
class GitException extends Error {
|
|
108
|
+
constructor(msg, err) {
|
|
109
|
+
if (err instanceof Error) {
|
|
110
|
+
super(`${msg}. Cause: '${err.message}'`);
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
super(msg);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
class NoLocalBranchException extends GitException {
|
|
118
|
+
constructor(err) {
|
|
119
|
+
super('Local branch operation failed', err);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
class LocalChangeException extends GitException {
|
|
123
|
+
constructor(err) {
|
|
124
|
+
super('Getting local changes operation failed', err);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
class DiffFailedException extends GitException {
|
|
128
|
+
constructor(err) {
|
|
129
|
+
super('Getting diff operation failed', err);
|
|
130
|
+
}
|
|
131
|
+
}
|
package/lib/src/Git/Git.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export declare class Git implements IGit {
|
|
|
16
16
|
private static MIN_GIT_VERSION_MAJOR;
|
|
17
17
|
private static MIN_GIT_VERSION_MINOR;
|
|
18
18
|
private static MIN_GIT_VERSION_PATCH;
|
|
19
|
-
private
|
|
19
|
+
private gitInstance;
|
|
20
20
|
private dir;
|
|
21
21
|
constructor(dir: string);
|
|
22
22
|
static versionCheck(git: SimpleGit): Promise<void>;
|
package/lib/src/Git/Git.js
CHANGED
|
@@ -29,6 +29,7 @@ var FileStatus;
|
|
|
29
29
|
})(FileStatus = exports.FileStatus || (exports.FileStatus = {}));
|
|
30
30
|
class Git {
|
|
31
31
|
constructor(dir) {
|
|
32
|
+
this.gitInstance = undefined;
|
|
32
33
|
this.dir = dir;
|
|
33
34
|
}
|
|
34
35
|
static versionCheck(git) {
|
|
@@ -37,17 +38,20 @@ class Git {
|
|
|
37
38
|
const isSupported = version.major >= this.MIN_GIT_VERSION_MAJOR &&
|
|
38
39
|
version.minor >= this.MIN_GIT_VERSION_MINOR &&
|
|
39
40
|
version.patch >= this.MIN_GIT_VERSION_PATCH;
|
|
41
|
+
if (!version.installed) {
|
|
42
|
+
throw new Error('"git" is not installed or available on the PATH');
|
|
43
|
+
}
|
|
40
44
|
if (!isSupported)
|
|
41
45
|
throw new Error(`Unsupported version of git. Min version must be ${this.MIN_GIT_VERSION_MAJOR}.${this.MIN_GIT_VERSION_MINOR}.${this.MIN_GIT_VERSION_PATCH}`);
|
|
42
46
|
});
|
|
43
47
|
}
|
|
44
48
|
get git() {
|
|
45
|
-
if (
|
|
46
|
-
return Promise.resolve(
|
|
49
|
+
if (this.gitInstance)
|
|
50
|
+
return Promise.resolve(this.gitInstance);
|
|
47
51
|
//eslint-disable-next-line
|
|
48
52
|
const git = (0, simple_git_1.simpleGit)(this.dir);
|
|
49
53
|
return Git.versionCheck(git).then(() => {
|
|
50
|
-
|
|
54
|
+
this.gitInstance = git;
|
|
51
55
|
return git;
|
|
52
56
|
});
|
|
53
57
|
}
|
|
@@ -104,6 +108,5 @@ class Git {
|
|
|
104
108
|
}
|
|
105
109
|
exports.Git = Git;
|
|
106
110
|
Git.MIN_GIT_VERSION_MAJOR = 2;
|
|
107
|
-
Git.MIN_GIT_VERSION_MINOR =
|
|
111
|
+
Git.MIN_GIT_VERSION_MINOR = 20;
|
|
108
112
|
Git.MIN_GIT_VERSION_PATCH = 0;
|
|
109
|
-
Git.gitInstance = undefined;
|
package/lib/src/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { getDefaultBranchDiff, getDefaultBranchDiffByRef, } from './FilesChanged/BranchChanges';
|
|
1
|
+
export { getDefaultBranchDiff, getDefaultBranchDiffByRef, getDiffRange, getLocalChanges, } from './FilesChanged/BranchChanges';
|
|
2
2
|
export { IGit } from './api/IGit';
|
|
3
3
|
export { Git } from './Git/Git';
|
package/lib/src/index.js
CHANGED
|
@@ -3,9 +3,11 @@
|
|
|
3
3
|
* Copyright (c) 2023, FinancialForce.com, inc. All rights reserved.
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Git = exports.getDefaultBranchDiffByRef = exports.getDefaultBranchDiff = void 0;
|
|
6
|
+
exports.Git = exports.getLocalChanges = exports.getDiffRange = exports.getDefaultBranchDiffByRef = exports.getDefaultBranchDiff = void 0;
|
|
7
7
|
var BranchChanges_1 = require("./FilesChanged/BranchChanges");
|
|
8
8
|
Object.defineProperty(exports, "getDefaultBranchDiff", { enumerable: true, get: function () { return BranchChanges_1.getDefaultBranchDiff; } });
|
|
9
9
|
Object.defineProperty(exports, "getDefaultBranchDiffByRef", { enumerable: true, get: function () { return BranchChanges_1.getDefaultBranchDiffByRef; } });
|
|
10
|
+
Object.defineProperty(exports, "getDiffRange", { enumerable: true, get: function () { return BranchChanges_1.getDiffRange; } });
|
|
11
|
+
Object.defineProperty(exports, "getLocalChanges", { enumerable: true, get: function () { return BranchChanges_1.getLocalChanges; } });
|
|
10
12
|
var Git_1 = require("./Git/Git");
|
|
11
13
|
Object.defineProperty(exports, "Git", { enumerable: true, get: function () { return Git_1.Git; } });
|
|
@@ -66,7 +66,7 @@ describe('Branch changes', () => {
|
|
|
66
66
|
//Given
|
|
67
67
|
mockGitImpl.getDefaultBranchName.mockRejectedValue(Error('no head ref error'));
|
|
68
68
|
//When/Then
|
|
69
|
-
yield expect((0, BranchChanges_1.getDefaultBranchDiffByRef)('./some/path/to/dir', 'abc12fcd')).rejects.toEqual(Error(
|
|
69
|
+
yield expect((0, BranchChanges_1.getDefaultBranchDiffByRef)('./some/path/to/dir', 'abc12fcd')).rejects.toEqual(Error("Local branch operation failed. Cause: 'no head ref error'"));
|
|
70
70
|
}));
|
|
71
71
|
it('rejects and throws error when "getLocalChangedAndCreated" fails', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
72
72
|
//Given
|
|
@@ -74,7 +74,7 @@ describe('Branch changes', () => {
|
|
|
74
74
|
mockGitImpl.diffRange.mockResolvedValue(new Set(['File.txt', 'AnotherClass.txt']));
|
|
75
75
|
mockGitImpl.getLocalChangedAndCreated.mockRejectedValue(Error('op failed'));
|
|
76
76
|
//When/Then
|
|
77
|
-
yield expect((0, BranchChanges_1.getDefaultBranchDiffByRef)('./some/path/to/dir', 'abc12fcd')).rejects.toEqual(Error('
|
|
77
|
+
yield expect((0, BranchChanges_1.getDefaultBranchDiffByRef)('./some/path/to/dir', 'abc12fcd')).rejects.toEqual(Error("Local branch operation failed. Cause: 'Getting diff operation failed. Cause: 'op failed''"));
|
|
78
78
|
}));
|
|
79
79
|
});
|
|
80
80
|
describe('getDefaultBranchDiff', () => {
|
|
@@ -102,7 +102,51 @@ describe('Branch changes', () => {
|
|
|
102
102
|
mockGitImpl.diffRange.mockResolvedValue(new Set(['File.txt', 'AnotherClass.txt']));
|
|
103
103
|
mockGitImpl.getLocalChangedAndCreated.mockRejectedValue(Error('op failed'));
|
|
104
104
|
//When/Then
|
|
105
|
-
yield expect((0, BranchChanges_1.getDefaultBranchDiff)('./some/path/to/dir')).rejects.toEqual(Error('
|
|
105
|
+
yield expect((0, BranchChanges_1.getDefaultBranchDiff)('./some/path/to/dir')).rejects.toEqual(Error("Local branch operation failed. Cause: 'Getting diff operation failed. Cause: 'op failed''"));
|
|
106
|
+
}));
|
|
107
|
+
});
|
|
108
|
+
describe('getDiffRange', () => {
|
|
109
|
+
it('returns the correct set of files', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
110
|
+
//Given
|
|
111
|
+
mockGitImpl.diffRange.mockResolvedValue(new Set(['File.txt', 'AnotherClass.txt']));
|
|
112
|
+
mockGitImpl.getLocalChangedAndCreated.mockResolvedValue(new Set(['SomeFile.txt']));
|
|
113
|
+
//When
|
|
114
|
+
const res = yield (0, BranchChanges_1.getDiffRange)('./some/path/to/dir', 'ref1', 'ref2');
|
|
115
|
+
//Then
|
|
116
|
+
expect(mockedGit).toHaveBeenCalledWith('./some/path/to/dir');
|
|
117
|
+
expect(mockGitImpl.getLocalChangedAndCreated).toBeCalledTimes(1);
|
|
118
|
+
expect(mockGitImpl.diffRange).toHaveBeenCalledWith('ref1', 'ref2');
|
|
119
|
+
expect(res).toEqual(new Set([
|
|
120
|
+
`${mockRootDir}/abs/path/to/repo/File.txt`,
|
|
121
|
+
`${mockRootDir}/abs/path/to/repo/AnotherClass.txt`,
|
|
122
|
+
`${mockRootDir}/abs/path/to/repo/SomeFile.txt`,
|
|
123
|
+
]));
|
|
124
|
+
}));
|
|
125
|
+
it('rejects and throws error when "getLocalChangedAndCreated" fails', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
126
|
+
//Given
|
|
127
|
+
mockGitImpl.getDefaultBranchName.mockResolvedValue('default/branch/name');
|
|
128
|
+
mockGitImpl.diffRange.mockResolvedValue(new Set(['File.txt', 'AnotherClass.txt']));
|
|
129
|
+
mockGitImpl.getLocalChangedAndCreated.mockRejectedValue(Error('op failed'));
|
|
130
|
+
//When/Then
|
|
131
|
+
yield expect((0, BranchChanges_1.getDiffRange)('./some/path/to/dir', 'ref1', 'ref2')).rejects.toEqual(Error("Getting diff operation failed. Cause: 'op failed'"));
|
|
132
|
+
}));
|
|
133
|
+
});
|
|
134
|
+
describe('getLocalChanges', () => {
|
|
135
|
+
it('returns the correct set of files', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
136
|
+
//Given
|
|
137
|
+
mockGitImpl.getLocalChangedAndCreated.mockResolvedValue(new Set(['SomeFile.txt']));
|
|
138
|
+
//When
|
|
139
|
+
const res = yield (0, BranchChanges_1.getLocalChanges)('./some/path/to/dir');
|
|
140
|
+
//Then
|
|
141
|
+
expect(mockedGit).toHaveBeenCalledWith('./some/path/to/dir');
|
|
142
|
+
expect(mockGitImpl.getLocalChangedAndCreated).toBeCalledTimes(1);
|
|
143
|
+
expect(res).toEqual(new Set([`${mockRootDir}/abs/path/to/repo/SomeFile.txt`]));
|
|
144
|
+
}));
|
|
145
|
+
it('rejects and throws error when op fails', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
146
|
+
//Given
|
|
147
|
+
mockGitImpl.getLocalChangedAndCreated.mockRejectedValue(Error('op failed'));
|
|
148
|
+
//When/Then
|
|
149
|
+
yield expect((0, BranchChanges_1.getLocalChanges)('./some/path/to/dir')).rejects.toEqual(Error("Getting local changes operation failed. Cause: 'op failed'"));
|
|
106
150
|
}));
|
|
107
151
|
});
|
|
108
152
|
});
|
package/lib/test/Git/Git.spec.js
CHANGED
|
@@ -28,37 +28,62 @@ describe('Git', () => {
|
|
|
28
28
|
yield repoManager.tearDown();
|
|
29
29
|
}));
|
|
30
30
|
describe('version check', () => {
|
|
31
|
-
it('does not fail when Git version is equal to 2.
|
|
31
|
+
it('does not fail when Git version is equal to 2.20.0', () => {
|
|
32
32
|
//Given/When
|
|
33
33
|
const mock = {
|
|
34
|
-
version: jest.fn().mockReturnValue({
|
|
34
|
+
version: jest.fn().mockReturnValue({
|
|
35
|
+
installed: true,
|
|
36
|
+
major: 2,
|
|
37
|
+
minor: 20,
|
|
38
|
+
patch: 0,
|
|
39
|
+
}),
|
|
35
40
|
};
|
|
36
41
|
expect(Git_1.Git.versionCheck(mock)).resolves;
|
|
37
42
|
});
|
|
38
|
-
it('
|
|
43
|
+
it('does not fail when Git version is higher', () => {
|
|
44
|
+
//Given/When
|
|
45
|
+
const mock = {
|
|
46
|
+
version: jest.fn().mockReturnValue({
|
|
47
|
+
installed: true,
|
|
48
|
+
major: 2,
|
|
49
|
+
minor: 30,
|
|
50
|
+
patch: 2,
|
|
51
|
+
}),
|
|
52
|
+
};
|
|
53
|
+
//Then
|
|
54
|
+
expect(Git_1.Git.versionCheck(mock)).resolves;
|
|
55
|
+
});
|
|
56
|
+
it('fails when Git is not installed', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
57
|
//Given/When
|
|
40
58
|
const mock = {
|
|
41
|
-
version: jest.fn().mockReturnValue({
|
|
59
|
+
version: jest.fn().mockReturnValue({ installed: false }),
|
|
42
60
|
};
|
|
43
61
|
//Then
|
|
44
|
-
yield expect(Git_1.Git.versionCheck(mock)).rejects.toThrow(Error('
|
|
62
|
+
yield expect(Git_1.Git.versionCheck(mock)).rejects.toThrow(Error('"git" is not installed or available on the PATH'));
|
|
45
63
|
}));
|
|
46
|
-
it('fails when Git
|
|
64
|
+
it('fails when Git major version is lower', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
47
65
|
//Given/When
|
|
48
66
|
const mock = {
|
|
49
|
-
version: jest.fn().mockReturnValue({
|
|
67
|
+
version: jest.fn().mockReturnValue({
|
|
68
|
+
installed: true,
|
|
69
|
+
major: 1,
|
|
70
|
+
}),
|
|
50
71
|
};
|
|
51
72
|
//Then
|
|
52
|
-
yield expect(Git_1.Git.versionCheck(mock)).rejects.toThrow(Error('Unsupported version of git. Min version must be 2.
|
|
73
|
+
yield expect(Git_1.Git.versionCheck(mock)).rejects.toThrow(Error('Unsupported version of git. Min version must be 2.20.0'));
|
|
53
74
|
}));
|
|
54
|
-
it('fails when Git
|
|
75
|
+
it('fails when Git minor version is lower', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
55
76
|
//Given/When
|
|
56
77
|
const mock = {
|
|
57
|
-
version: jest.fn().mockReturnValue({
|
|
78
|
+
version: jest.fn().mockReturnValue({
|
|
79
|
+
installed: true,
|
|
80
|
+
major: 2,
|
|
81
|
+
minor: 19,
|
|
82
|
+
}),
|
|
58
83
|
};
|
|
59
84
|
//Then
|
|
60
|
-
expect(Git_1.Git.versionCheck(mock)).
|
|
61
|
-
});
|
|
85
|
+
yield expect(Git_1.Git.versionCheck(mock)).rejects.toThrow(Error('Unsupported version of git. Min version must be 2.20.0'));
|
|
86
|
+
}));
|
|
62
87
|
});
|
|
63
88
|
describe('rev parse', () => {
|
|
64
89
|
it('get git root', () => __awaiter(void 0, void 0, void 0, function* () {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apexdevtools/git-ops",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
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",
|
|
@@ -50,7 +50,6 @@
|
|
|
50
50
|
"typescript": "^4.9.5"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"install": "^0.13.0",
|
|
54
53
|
"simple-git": "^3.16.0"
|
|
55
54
|
},
|
|
56
55
|
"config": {
|