workspace-tools 0.41.0 → 0.41.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/README.md +1 -1
- package/lib/dependencies/index.d.ts +2 -2
- package/lib/dependencies/index.js +31 -12
- package/lib/dependencies/index.js.map +1 -1
- package/lib/dependencies/transitiveDeps.d.ts +1 -1
- package/lib/dependencies/transitiveDeps.js +59 -38
- package/lib/dependencies/transitiveDeps.js.map +1 -1
- package/lib/getPackageInfo.d.ts +1 -1
- package/lib/getPackageInfo.js +46 -40
- package/lib/getPackageInfo.js.map +1 -1
- package/lib/getPackageInfos.d.ts +4 -2
- package/lib/getPackageInfos.js +35 -53
- package/lib/getPackageInfos.js.map +1 -1
- package/lib/git/config.d.ts +1 -1
- package/lib/git/config.js +15 -12
- package/lib/git/config.js.map +1 -1
- package/lib/git/getDefaultRemote.js +45 -30
- package/lib/git/getDefaultRemote.js.map +1 -1
- package/lib/git/getDefaultRemoteBranch.d.ts +1 -1
- package/lib/git/getDefaultRemoteBranch.js +35 -24
- package/lib/git/getDefaultRemoteBranch.js.map +1 -1
- package/lib/git/getRepositoryName.d.ts +1 -1
- package/lib/git/getRepositoryName.js +17 -19
- package/lib/git/getRepositoryName.js.map +1 -1
- package/lib/git/git.d.ts +2 -5
- package/lib/git/git.js +62 -64
- package/lib/git/git.js.map +1 -1
- package/lib/git/gitUtilities.d.ts +3 -3
- package/lib/git/gitUtilities.js +377 -147
- package/lib/git/gitUtilities.js.map +1 -1
- package/lib/git/index.d.ts +5 -5
- package/lib/git/index.js +50 -28
- package/lib/git/index.js.map +1 -1
- package/lib/git/types.js +4 -3
- package/lib/git/types.js.map +1 -1
- package/lib/graph/createDependencyMap.d.ts +2 -2
- package/lib/graph/createDependencyMap.js +18 -18
- package/lib/graph/createDependencyMap.js.map +1 -1
- package/lib/graph/createPackageGraph.d.ts +3 -3
- package/lib/graph/createPackageGraph.js +58 -45
- package/lib/graph/createPackageGraph.js.map +1 -1
- package/lib/graph/getPackageDependencies.d.ts +1 -1
- package/lib/graph/getPackageDependencies.js +17 -17
- package/lib/graph/getPackageDependencies.js.map +1 -1
- package/lib/graph/index.d.ts +4 -4
- package/lib/graph/index.js +25 -27
- package/lib/graph/index.js.map +1 -1
- package/lib/index.d.ts +29 -26
- package/lib/index.js +154 -70
- package/lib/index.js.map +1 -1
- package/lib/isCachingEnabled.js +17 -6
- package/lib/isCachingEnabled.js.map +1 -1
- package/lib/lockfile/nameAtVersion.js +9 -4
- package/lib/lockfile/nameAtVersion.js.map +1 -1
- package/lib/lockfile/parseBerryLock.d.ts +1 -1
- package/lib/lockfile/parseBerryLock.js +13 -11
- package/lib/lockfile/parseBerryLock.js.map +1 -1
- package/lib/lockfile/parseLockFile.d.ts +2 -0
- package/lib/lockfile/parseLockFile.js +87 -0
- package/lib/lockfile/parseLockFile.js.map +1 -0
- package/lib/lockfile/parseNpmLock.d.ts +1 -1
- package/lib/lockfile/parseNpmLock.js +15 -7
- package/lib/lockfile/parseNpmLock.js.map +1 -1
- package/lib/lockfile/parsePnpmLock.d.ts +1 -1
- package/lib/lockfile/parsePnpmLock.js +14 -9
- package/lib/lockfile/parsePnpmLock.js.map +1 -1
- package/lib/lockfile/queryLockFile.d.ts +1 -1
- package/lib/lockfile/queryLockFile.js +11 -6
- package/lib/lockfile/queryLockFile.js.map +1 -1
- package/lib/lockfile/readYaml.js +17 -9
- package/lib/lockfile/readYaml.js.map +1 -1
- package/lib/lockfile/types.js +3 -2
- package/lib/lockfile/types.js.map +1 -1
- package/lib/logging.js +10 -6
- package/lib/logging.js.map +1 -1
- package/lib/paths.d.ts +1 -1
- package/lib/paths.js +59 -59
- package/lib/paths.js.map +1 -1
- package/lib/scope.js +30 -21
- package/lib/scope.js.map +1 -1
- package/lib/types/Catalogs.js +8 -3
- package/lib/types/Catalogs.js.map +1 -1
- package/lib/types/PackageGraph.js +4 -3
- package/lib/types/PackageGraph.js.map +1 -1
- package/lib/types/PackageInfo.d.ts +1 -1
- package/lib/types/PackageInfo.js +3 -2
- package/lib/types/PackageInfo.js.map +1 -1
- package/lib/types/WorkspaceInfo.d.ts +1 -1
- package/lib/types/WorkspaceInfo.js +3 -2
- package/lib/types/WorkspaceInfo.js.map +1 -1
- package/lib/types/WorkspaceManager.js +3 -2
- package/lib/types/WorkspaceManager.js.map +1 -1
- package/lib/workspaces/catalogsToYaml.d.ts +1 -1
- package/lib/workspaces/catalogsToYaml.js +12 -10
- package/lib/workspaces/catalogsToYaml.js.map +1 -1
- package/lib/workspaces/findWorkspacePath.d.ts +2 -1
- package/lib/workspaces/findWorkspacePath.js +10 -12
- package/lib/workspaces/findWorkspacePath.js.map +1 -1
- package/lib/workspaces/getAllPackageJsonFiles.js +32 -28
- package/lib/workspaces/getAllPackageJsonFiles.js.map +1 -1
- package/lib/workspaces/getCatalogVersion.d.ts +1 -1
- package/lib/workspaces/getCatalogVersion.js +19 -32
- package/lib/workspaces/getCatalogVersion.js.map +1 -1
- package/lib/workspaces/getCatalogs.d.ts +2 -2
- package/lib/workspaces/getCatalogs.js +17 -22
- package/lib/workspaces/getCatalogs.js.map +1 -1
- package/lib/workspaces/getChangedPackages.d.ts +1 -1
- package/lib/workspaces/getChangedPackages.js +47 -30
- package/lib/workspaces/getChangedPackages.js.map +1 -1
- package/lib/workspaces/getPackagesByFiles.js +29 -24
- package/lib/workspaces/getPackagesByFiles.js.map +1 -1
- package/lib/workspaces/getWorkspaceInfos.d.ts +2 -2
- package/lib/workspaces/getWorkspaceInfos.js +43 -58
- package/lib/workspaces/getWorkspaceInfos.js.map +1 -1
- package/lib/workspaces/getWorkspaceManagerRoot.d.ts +1 -1
- package/lib/workspaces/getWorkspaceManagerRoot.js +16 -13
- package/lib/workspaces/getWorkspaceManagerRoot.js.map +1 -1
- package/lib/workspaces/getWorkspacePackagePaths.d.ts +1 -1
- package/lib/workspaces/getWorkspacePackagePaths.js +86 -72
- package/lib/workspaces/getWorkspacePackagePaths.js.map +1 -1
- package/lib/workspaces/getWorkspacePatterns.d.ts +1 -1
- package/lib/workspaces/getWorkspacePatterns.js +18 -20
- package/lib/workspaces/getWorkspacePatterns.js.map +1 -1
- package/lib/workspaces/implementations/WorkspaceUtilities.d.ts +1 -1
- package/lib/workspaces/implementations/WorkspaceUtilities.js +3 -2
- package/lib/workspaces/implementations/WorkspaceUtilities.js.map +1 -1
- package/lib/workspaces/implementations/getPackageJsonWorkspacePatterns.d.ts +1 -1
- package/lib/workspaces/implementations/getPackageJsonWorkspacePatterns.js +24 -22
- package/lib/workspaces/implementations/getPackageJsonWorkspacePatterns.js.map +1 -1
- package/lib/workspaces/implementations/getWorkspaceManagerAndRoot.d.ts +1 -1
- package/lib/workspaces/implementations/getWorkspaceManagerAndRoot.js +38 -43
- package/lib/workspaces/implementations/getWorkspaceManagerAndRoot.js.map +1 -1
- package/lib/workspaces/implementations/getWorkspaceUtilities.d.ts +2 -2
- package/lib/workspaces/implementations/getWorkspaceUtilities.js +25 -13
- package/lib/workspaces/implementations/getWorkspaceUtilities.js.map +1 -1
- package/lib/workspaces/implementations/index.d.ts +2 -2
- package/lib/workspaces/implementations/index.js +19 -7
- package/lib/workspaces/implementations/index.js.map +1 -1
- package/lib/workspaces/implementations/lerna.d.ts +1 -1
- package/lib/workspaces/implementations/lerna.js +55 -31
- package/lib/workspaces/implementations/lerna.js.map +1 -1
- package/lib/workspaces/implementations/npm.d.ts +1 -1
- package/lib/workspaces/implementations/npm.js +12 -7
- package/lib/workspaces/implementations/npm.js.map +1 -1
- package/lib/workspaces/implementations/pnpm.d.ts +1 -1
- package/lib/workspaces/implementations/pnpm.js +28 -17
- package/lib/workspaces/implementations/pnpm.js.map +1 -1
- package/lib/workspaces/implementations/rush.d.ts +1 -1
- package/lib/workspaces/implementations/rush.js +27 -16
- package/lib/workspaces/implementations/rush.js.map +1 -1
- package/lib/workspaces/implementations/yarn.d.ts +1 -1
- package/lib/workspaces/implementations/yarn.js +34 -26
- package/lib/workspaces/implementations/yarn.js.map +1 -1
- package/lib/workspaces/wrapWorkspaceUtility.d.ts +1 -1
- package/lib/workspaces/wrapWorkspaceUtility.js +25 -27
- package/lib/workspaces/wrapWorkspaceUtility.js.map +1 -1
- package/package.json +21 -12
- package/lib/lockfile/index.d.ts +0 -6
- package/lib/lockfile/index.js +0 -105
- package/lib/lockfile/index.js.map +0 -1
package/lib/git/gitUtilities.js
CHANGED
|
@@ -1,288 +1,518 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
//
|
|
3
2
|
// Assorted other git utilities
|
|
4
3
|
// (could be split into separate files later if desired)
|
|
5
4
|
//
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
"use strict";
|
|
6
|
+
Object.defineProperty(exports, "__esModule", {
|
|
7
|
+
value: true
|
|
8
|
+
});
|
|
9
|
+
function _export(target, all) {
|
|
10
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
_export(exports, {
|
|
16
|
+
get commit () {
|
|
17
|
+
return commit;
|
|
18
|
+
},
|
|
19
|
+
get fetchRemote () {
|
|
20
|
+
return fetchRemote;
|
|
21
|
+
},
|
|
22
|
+
get fetchRemoteBranch () {
|
|
23
|
+
return fetchRemoteBranch;
|
|
24
|
+
},
|
|
25
|
+
get getBranchChanges () {
|
|
26
|
+
return getBranchChanges;
|
|
27
|
+
},
|
|
28
|
+
get getBranchName () {
|
|
29
|
+
return getBranchName;
|
|
30
|
+
},
|
|
31
|
+
get getChanges () {
|
|
32
|
+
return getChanges;
|
|
33
|
+
},
|
|
34
|
+
get getChangesBetweenRefs () {
|
|
35
|
+
return getChangesBetweenRefs;
|
|
36
|
+
},
|
|
37
|
+
get getCurrentHash () {
|
|
38
|
+
return getCurrentHash;
|
|
39
|
+
},
|
|
40
|
+
get getDefaultBranch () {
|
|
41
|
+
return getDefaultBranch;
|
|
42
|
+
},
|
|
43
|
+
get getFileAddedHash () {
|
|
44
|
+
return getFileAddedHash;
|
|
45
|
+
},
|
|
46
|
+
get getFullBranchRef () {
|
|
47
|
+
return getFullBranchRef;
|
|
48
|
+
},
|
|
49
|
+
get getParentBranch () {
|
|
50
|
+
return getParentBranch;
|
|
51
|
+
},
|
|
52
|
+
get getRecentCommitMessages () {
|
|
53
|
+
return getRecentCommitMessages;
|
|
54
|
+
},
|
|
55
|
+
get getRemoteBranch () {
|
|
56
|
+
return getRemoteBranch;
|
|
57
|
+
},
|
|
58
|
+
get getShortBranchName () {
|
|
59
|
+
return getShortBranchName;
|
|
60
|
+
},
|
|
61
|
+
get getStagedChanges () {
|
|
62
|
+
return getStagedChanges;
|
|
63
|
+
},
|
|
64
|
+
get getUnstagedChanges () {
|
|
65
|
+
return getUnstagedChanges;
|
|
66
|
+
},
|
|
67
|
+
get getUntrackedChanges () {
|
|
68
|
+
return getUntrackedChanges;
|
|
69
|
+
},
|
|
70
|
+
get getUserEmail () {
|
|
71
|
+
return getUserEmail;
|
|
72
|
+
},
|
|
73
|
+
get init () {
|
|
74
|
+
return init;
|
|
75
|
+
},
|
|
76
|
+
get listAllTrackedFiles () {
|
|
77
|
+
return listAllTrackedFiles;
|
|
78
|
+
},
|
|
79
|
+
get parseRemoteBranch () {
|
|
80
|
+
return parseRemoteBranch;
|
|
81
|
+
},
|
|
82
|
+
get revertLocalChanges () {
|
|
83
|
+
return revertLocalChanges;
|
|
84
|
+
},
|
|
85
|
+
get stage () {
|
|
86
|
+
return stage;
|
|
87
|
+
},
|
|
88
|
+
get stageAndCommit () {
|
|
89
|
+
return stageAndCommit;
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
const _config = require("./config.js");
|
|
93
|
+
const _git = require("./git.js");
|
|
94
|
+
const diffArgs = [
|
|
95
|
+
"--no-pager",
|
|
96
|
+
"diff",
|
|
97
|
+
"--name-only",
|
|
98
|
+
"--relative"
|
|
99
|
+
];
|
|
11
100
|
function getUntrackedChanges(cwdOrOptions) {
|
|
12
|
-
const options = typeof cwdOrOptions === "string" ? {
|
|
13
|
-
|
|
101
|
+
const options = typeof cwdOrOptions === "string" ? {
|
|
102
|
+
cwd: cwdOrOptions
|
|
103
|
+
} : cwdOrOptions;
|
|
104
|
+
const results = (0, _git.git)([
|
|
105
|
+
"ls-files",
|
|
106
|
+
"--others",
|
|
107
|
+
"--exclude-standard"
|
|
108
|
+
], {
|
|
14
109
|
description: "Gathering information about untracked changes",
|
|
15
110
|
throwOnError: true,
|
|
16
|
-
...options
|
|
111
|
+
...options
|
|
112
|
+
});
|
|
113
|
+
return (0, _git.processGitOutput)(results, {
|
|
114
|
+
excludeNodeModules: true
|
|
17
115
|
});
|
|
18
|
-
return (0, git_1.processGitOutput)(results, { excludeNodeModules: true });
|
|
19
116
|
}
|
|
20
|
-
exports.getUntrackedChanges = getUntrackedChanges;
|
|
21
117
|
function fetchRemote(remoteOrOptions, cwd) {
|
|
22
|
-
const { remote, remoteBranch, options, ...gitOptions } = typeof remoteOrOptions === "string"
|
|
23
|
-
|
|
24
|
-
:
|
|
118
|
+
const { remote, remoteBranch, options, ...gitOptions } = typeof remoteOrOptions === "string" ? {
|
|
119
|
+
remote: remoteOrOptions,
|
|
120
|
+
cwd: cwd
|
|
121
|
+
} : remoteOrOptions;
|
|
25
122
|
if (remoteBranch && !remote) {
|
|
26
123
|
throw new Error('Must provide "remote" when using "remoteBranch" option');
|
|
27
124
|
}
|
|
28
125
|
const fetchArgs = [
|
|
29
126
|
"fetch",
|
|
30
127
|
"--",
|
|
31
|
-
...
|
|
32
|
-
|
|
33
|
-
|
|
128
|
+
...remote ? [
|
|
129
|
+
remote
|
|
130
|
+
] : [],
|
|
131
|
+
...remoteBranch ? [
|
|
132
|
+
remoteBranch
|
|
133
|
+
] : [],
|
|
134
|
+
...options || []
|
|
34
135
|
];
|
|
35
|
-
(0,
|
|
36
|
-
description: remote
|
|
37
|
-
? `Fetching ${remoteBranch ? `branch "${remoteBranch}" from ` : ""}remote "${remote}"`
|
|
38
|
-
: "Fetching all remotes",
|
|
136
|
+
(0, _git.git)(fetchArgs, {
|
|
137
|
+
description: remote ? `Fetching ${remoteBranch ? `branch "${remoteBranch}" from ` : ""}remote "${remote}"` : "Fetching all remotes",
|
|
39
138
|
throwOnError: true,
|
|
40
|
-
...gitOptions
|
|
139
|
+
...gitOptions
|
|
41
140
|
});
|
|
42
141
|
}
|
|
43
|
-
exports.fetchRemote = fetchRemote;
|
|
44
|
-
/**
|
|
45
|
-
* Fetch from the given remote and branch. Throws an error on failure.
|
|
46
|
-
* @deprecated Use `fetchRemote({ remote, remoteBranch, cwd })`
|
|
47
|
-
*/
|
|
48
|
-
// TODO: move to fetch.ts
|
|
49
142
|
function fetchRemoteBranch(remote, remoteBranch, cwd) {
|
|
50
|
-
fetchRemote({
|
|
143
|
+
fetchRemote({
|
|
144
|
+
remote,
|
|
145
|
+
remoteBranch,
|
|
146
|
+
cwd,
|
|
147
|
+
throwOnError: true
|
|
148
|
+
});
|
|
51
149
|
}
|
|
52
|
-
exports.fetchRemoteBranch = fetchRemoteBranch;
|
|
53
150
|
function getUnstagedChanges(cwdOrOptions) {
|
|
54
|
-
const options = typeof cwdOrOptions === "string" ? {
|
|
55
|
-
|
|
151
|
+
const options = typeof cwdOrOptions === "string" ? {
|
|
152
|
+
cwd: cwdOrOptions
|
|
153
|
+
} : cwdOrOptions;
|
|
154
|
+
const results = (0, _git.git)(diffArgs, {
|
|
56
155
|
description: "Gathering information about unstaged changes",
|
|
57
156
|
throwOnError: true,
|
|
58
|
-
...options
|
|
157
|
+
...options
|
|
158
|
+
});
|
|
159
|
+
return (0, _git.processGitOutput)(results, {
|
|
160
|
+
excludeNodeModules: true
|
|
59
161
|
});
|
|
60
|
-
return (0, git_1.processGitOutput)(results, { excludeNodeModules: true });
|
|
61
162
|
}
|
|
62
|
-
exports.getUnstagedChanges = getUnstagedChanges;
|
|
63
|
-
/**
|
|
64
|
-
* Gets file paths with changes between the current branch and the given branch.
|
|
65
|
-
* Throws an error on failure.
|
|
66
|
-
*
|
|
67
|
-
* @returns An array of relative file paths that have changed
|
|
68
|
-
* @deprecated Use `getBranchChanges({ branch, cwd })`
|
|
69
|
-
*/
|
|
70
|
-
// TODO: move to getChanges.ts
|
|
71
163
|
function getChanges(branch, cwd) {
|
|
72
|
-
return getChangesBetweenRefs({
|
|
164
|
+
return getChangesBetweenRefs({
|
|
165
|
+
fromRef: branch,
|
|
166
|
+
cwd,
|
|
167
|
+
throwOnError: true
|
|
168
|
+
});
|
|
73
169
|
}
|
|
74
|
-
exports.getChanges = getChanges;
|
|
75
170
|
function getBranchChanges(branchOrOptions, cwd) {
|
|
76
|
-
const { branch, ...options } = typeof branchOrOptions === "string" ? {
|
|
77
|
-
|
|
171
|
+
const { branch, ...options } = typeof branchOrOptions === "string" ? {
|
|
172
|
+
branch: branchOrOptions,
|
|
173
|
+
cwd: cwd
|
|
174
|
+
} : branchOrOptions;
|
|
175
|
+
return getChangesBetweenRefs({
|
|
176
|
+
fromRef: branch,
|
|
177
|
+
throwOnError: true,
|
|
178
|
+
...options
|
|
179
|
+
});
|
|
78
180
|
}
|
|
79
|
-
exports.getBranchChanges = getBranchChanges;
|
|
80
181
|
function getChangesBetweenRefs(fromRef, toRef, options, pattern, cwd) {
|
|
81
182
|
let gitOptions;
|
|
82
183
|
if (typeof fromRef === "string") {
|
|
83
|
-
gitOptions = {
|
|
84
|
-
|
|
85
|
-
|
|
184
|
+
gitOptions = {
|
|
185
|
+
cwd: cwd
|
|
186
|
+
};
|
|
187
|
+
} else {
|
|
86
188
|
({ fromRef, toRef, options, pattern, ...gitOptions } = fromRef);
|
|
87
189
|
}
|
|
88
190
|
const range = `${fromRef}...${toRef || ""}`;
|
|
89
|
-
const results = (0,
|
|
191
|
+
const results = (0, _git.git)([
|
|
192
|
+
...diffArgs,
|
|
193
|
+
...options || [],
|
|
194
|
+
range,
|
|
195
|
+
...pattern ? [
|
|
196
|
+
"--",
|
|
197
|
+
pattern
|
|
198
|
+
] : []
|
|
199
|
+
], {
|
|
90
200
|
description: `Gathering information about changes between refs (${range})`,
|
|
91
201
|
throwOnError: true,
|
|
92
|
-
...gitOptions
|
|
202
|
+
...gitOptions
|
|
203
|
+
});
|
|
204
|
+
return (0, _git.processGitOutput)(results, {
|
|
205
|
+
excludeNodeModules: true
|
|
93
206
|
});
|
|
94
|
-
return (0, git_1.processGitOutput)(results, { excludeNodeModules: true });
|
|
95
207
|
}
|
|
96
|
-
exports.getChangesBetweenRefs = getChangesBetweenRefs;
|
|
97
208
|
function getStagedChanges(cwdOrOptions) {
|
|
98
|
-
const options = typeof cwdOrOptions === "string" ? {
|
|
99
|
-
|
|
209
|
+
const options = typeof cwdOrOptions === "string" ? {
|
|
210
|
+
cwd: cwdOrOptions
|
|
211
|
+
} : cwdOrOptions;
|
|
212
|
+
const results = (0, _git.git)([
|
|
213
|
+
...diffArgs,
|
|
214
|
+
"--staged"
|
|
215
|
+
], {
|
|
100
216
|
description: "Gathering information about staged changes",
|
|
101
217
|
throwOnError: true,
|
|
102
|
-
...options
|
|
218
|
+
...options
|
|
219
|
+
});
|
|
220
|
+
return (0, _git.processGitOutput)(results, {
|
|
221
|
+
excludeNodeModules: true
|
|
103
222
|
});
|
|
104
|
-
return (0, git_1.processGitOutput)(results, { excludeNodeModules: true });
|
|
105
223
|
}
|
|
106
|
-
exports.getStagedChanges = getStagedChanges;
|
|
107
224
|
function getRecentCommitMessages(branchOrOptions, cwd) {
|
|
108
|
-
const { branch, ...options } = typeof branchOrOptions === "string" ? {
|
|
109
|
-
|
|
225
|
+
const { branch, ...options } = typeof branchOrOptions === "string" ? {
|
|
226
|
+
branch: branchOrOptions,
|
|
227
|
+
cwd: cwd
|
|
228
|
+
} : branchOrOptions;
|
|
229
|
+
const results = (0, _git.git)([
|
|
230
|
+
"log",
|
|
231
|
+
"--decorate",
|
|
232
|
+
"--pretty=format:%s",
|
|
233
|
+
`${branch}..HEAD`
|
|
234
|
+
], {
|
|
110
235
|
description: `Getting recent commit messages for branch "${branch}"`,
|
|
111
|
-
...options
|
|
236
|
+
...options
|
|
112
237
|
});
|
|
113
|
-
return (0,
|
|
238
|
+
return (0, _git.processGitOutput)(results);
|
|
114
239
|
}
|
|
115
|
-
exports.getRecentCommitMessages = getRecentCommitMessages;
|
|
116
240
|
function getUserEmail(cwdOrOptions) {
|
|
117
|
-
const options = typeof cwdOrOptions === "string" ? {
|
|
118
|
-
|
|
241
|
+
const options = typeof cwdOrOptions === "string" ? {
|
|
242
|
+
cwd: cwdOrOptions
|
|
243
|
+
} : cwdOrOptions;
|
|
244
|
+
return (0, _config.getConfigValue)({
|
|
245
|
+
key: "user.email",
|
|
246
|
+
...options
|
|
247
|
+
});
|
|
119
248
|
}
|
|
120
|
-
exports.getUserEmail = getUserEmail;
|
|
121
249
|
function getBranchName(cwdOrOptions) {
|
|
122
|
-
const options = typeof cwdOrOptions === "string" ? {
|
|
123
|
-
|
|
250
|
+
const options = typeof cwdOrOptions === "string" ? {
|
|
251
|
+
cwd: cwdOrOptions
|
|
252
|
+
} : cwdOrOptions;
|
|
253
|
+
const results = (0, _git.git)([
|
|
254
|
+
"rev-parse",
|
|
255
|
+
"--abbrev-ref",
|
|
256
|
+
"HEAD"
|
|
257
|
+
], {
|
|
124
258
|
description: "Getting current branch name",
|
|
125
|
-
...options
|
|
259
|
+
...options
|
|
126
260
|
});
|
|
127
261
|
return results.success ? results.stdout : null;
|
|
128
262
|
}
|
|
129
|
-
exports.getBranchName = getBranchName;
|
|
130
263
|
function getFullBranchRef(branchOrOptions, cwd) {
|
|
131
|
-
const { branch, ...options } = typeof branchOrOptions === "string" ? {
|
|
132
|
-
|
|
264
|
+
const { branch, ...options } = typeof branchOrOptions === "string" ? {
|
|
265
|
+
branch: branchOrOptions,
|
|
266
|
+
cwd: cwd
|
|
267
|
+
} : branchOrOptions;
|
|
268
|
+
const showRefResults = (0, _git.git)([
|
|
269
|
+
"show-ref",
|
|
270
|
+
"--heads",
|
|
271
|
+
branch
|
|
272
|
+
], options);
|
|
133
273
|
return showRefResults.success ? showRefResults.stdout.split(" ")[1] : null;
|
|
134
274
|
}
|
|
135
|
-
exports.getFullBranchRef = getFullBranchRef;
|
|
136
275
|
function getShortBranchName(refOrOptions, cwd) {
|
|
137
|
-
const { fullBranchRef, ...options } = typeof refOrOptions === "string" ? {
|
|
276
|
+
const { fullBranchRef, ...options } = typeof refOrOptions === "string" ? {
|
|
277
|
+
fullBranchRef: refOrOptions,
|
|
278
|
+
cwd: cwd
|
|
279
|
+
} : refOrOptions;
|
|
138
280
|
// The original command `git name-rev --name-only` returned unreliable results if multiple
|
|
139
281
|
// named refs point to the same commit as the branch.
|
|
140
|
-
const showRefResults = (0,
|
|
282
|
+
const showRefResults = (0, _git.git)([
|
|
283
|
+
"rev-parse",
|
|
284
|
+
"--abbrev-ref",
|
|
285
|
+
fullBranchRef
|
|
286
|
+
], options);
|
|
141
287
|
return showRefResults.success ? showRefResults.stdout || null : null;
|
|
142
288
|
}
|
|
143
|
-
exports.getShortBranchName = getShortBranchName;
|
|
144
289
|
function getCurrentHash(cwdOrOptions) {
|
|
145
|
-
const options = typeof cwdOrOptions === "string" ? {
|
|
146
|
-
|
|
290
|
+
const options = typeof cwdOrOptions === "string" ? {
|
|
291
|
+
cwd: cwdOrOptions
|
|
292
|
+
} : cwdOrOptions;
|
|
293
|
+
const results = (0, _git.git)([
|
|
294
|
+
"rev-parse",
|
|
295
|
+
"HEAD"
|
|
296
|
+
], {
|
|
147
297
|
description: "Getting current git hash",
|
|
148
|
-
...options
|
|
298
|
+
...options
|
|
149
299
|
});
|
|
150
300
|
return results.success ? results.stdout : null;
|
|
151
301
|
}
|
|
152
|
-
exports.getCurrentHash = getCurrentHash;
|
|
153
302
|
function getFileAddedHash(filenameOrOptions, cwd) {
|
|
154
|
-
const { filename, ...options } = typeof filenameOrOptions === "string" ? {
|
|
155
|
-
|
|
303
|
+
const { filename, ...options } = typeof filenameOrOptions === "string" ? {
|
|
304
|
+
filename: filenameOrOptions,
|
|
305
|
+
cwd: cwd
|
|
306
|
+
} : filenameOrOptions;
|
|
307
|
+
const results = (0, _git.git)([
|
|
308
|
+
"rev-list",
|
|
309
|
+
"--max-count=1",
|
|
310
|
+
"HEAD",
|
|
311
|
+
filename
|
|
312
|
+
], options);
|
|
156
313
|
return results.success ? results.stdout.trim() : undefined;
|
|
157
314
|
}
|
|
158
|
-
exports.getFileAddedHash = getFileAddedHash;
|
|
159
315
|
function init(cwdOrOptions, _email, _username) {
|
|
160
|
-
const { email, username, ...options } = typeof cwdOrOptions === "string" ? {
|
|
161
|
-
|
|
162
|
-
|
|
316
|
+
const { email, username, ...options } = typeof cwdOrOptions === "string" ? {
|
|
317
|
+
cwd: cwdOrOptions,
|
|
318
|
+
email: _email,
|
|
319
|
+
username: _username
|
|
320
|
+
} : cwdOrOptions;
|
|
321
|
+
(0, _git.git)([
|
|
322
|
+
"init"
|
|
323
|
+
], {
|
|
324
|
+
...options,
|
|
325
|
+
throwOnError: true
|
|
326
|
+
});
|
|
327
|
+
if (!(0, _config.getConfigValue)({
|
|
328
|
+
key: "user.name",
|
|
329
|
+
...options
|
|
330
|
+
})) {
|
|
163
331
|
if (!username) {
|
|
164
332
|
throw new Error("must include a username when initializing git repo");
|
|
165
333
|
}
|
|
166
|
-
(0,
|
|
334
|
+
(0, _git.git)([
|
|
335
|
+
"config",
|
|
336
|
+
"user.name",
|
|
337
|
+
username
|
|
338
|
+
], options);
|
|
167
339
|
}
|
|
168
340
|
if (!getUserEmail(options)) {
|
|
169
341
|
if (!email) {
|
|
170
342
|
throw new Error("must include a email when initializing git repo");
|
|
171
343
|
}
|
|
172
|
-
(0,
|
|
344
|
+
(0, _git.git)([
|
|
345
|
+
"config",
|
|
346
|
+
"user.email",
|
|
347
|
+
email
|
|
348
|
+
], options);
|
|
173
349
|
}
|
|
174
350
|
}
|
|
175
|
-
exports.init = init;
|
|
176
351
|
function stage(patternsOrOptions, cwd) {
|
|
177
|
-
const { patterns, ...options } = Array.isArray(patternsOrOptions)
|
|
178
|
-
|
|
179
|
-
:
|
|
180
|
-
|
|
181
|
-
|
|
352
|
+
const { patterns, ...options } = Array.isArray(patternsOrOptions) ? {
|
|
353
|
+
patterns: patternsOrOptions,
|
|
354
|
+
cwd: cwd
|
|
355
|
+
} : patternsOrOptions;
|
|
356
|
+
for (const pattern of patterns){
|
|
357
|
+
(0, _git.git)([
|
|
358
|
+
"add",
|
|
359
|
+
pattern
|
|
360
|
+
], {
|
|
361
|
+
...options,
|
|
362
|
+
description: `Staging changes (git add ${pattern})`
|
|
363
|
+
});
|
|
182
364
|
}
|
|
183
365
|
}
|
|
184
|
-
exports.stage = stage;
|
|
185
366
|
function commit(messageOrOptions, _cwd, _options) {
|
|
186
|
-
const { message, options, ...gitOptions } = typeof messageOrOptions === "string"
|
|
187
|
-
|
|
188
|
-
:
|
|
189
|
-
|
|
367
|
+
const { message, options, ...gitOptions } = typeof messageOrOptions === "string" ? {
|
|
368
|
+
message: messageOrOptions,
|
|
369
|
+
cwd: _cwd,
|
|
370
|
+
options: _options
|
|
371
|
+
} : messageOrOptions;
|
|
372
|
+
(0, _git.git)([
|
|
373
|
+
"commit",
|
|
374
|
+
"-m",
|
|
375
|
+
message,
|
|
376
|
+
...options || []
|
|
377
|
+
], {
|
|
190
378
|
throwOnError: true,
|
|
191
379
|
description: "Committing changes",
|
|
192
|
-
...gitOptions
|
|
380
|
+
...gitOptions
|
|
193
381
|
});
|
|
194
382
|
}
|
|
195
|
-
exports.commit = commit;
|
|
196
383
|
function stageAndCommit(patternsOrOptions, message, cwd, commitOptions) {
|
|
197
|
-
const options = Array.isArray(patternsOrOptions)
|
|
198
|
-
|
|
199
|
-
:
|
|
384
|
+
const options = Array.isArray(patternsOrOptions) ? {
|
|
385
|
+
patterns: patternsOrOptions,
|
|
386
|
+
message: message,
|
|
387
|
+
cwd: cwd,
|
|
388
|
+
options: commitOptions
|
|
389
|
+
} : patternsOrOptions;
|
|
200
390
|
stage(options);
|
|
201
391
|
commit(options);
|
|
202
392
|
}
|
|
203
|
-
exports.stageAndCommit = stageAndCommit;
|
|
204
393
|
function revertLocalChanges(cwdOrOptions) {
|
|
205
|
-
const options = typeof cwdOrOptions === "string" ? {
|
|
394
|
+
const options = typeof cwdOrOptions === "string" ? {
|
|
395
|
+
cwd: cwdOrOptions
|
|
396
|
+
} : cwdOrOptions;
|
|
206
397
|
const stash = `workspace-tools_${new Date().getTime()}`;
|
|
207
|
-
if (!(0,
|
|
398
|
+
if (!(0, _git.git)([
|
|
399
|
+
"stash",
|
|
400
|
+
"push",
|
|
401
|
+
"-u",
|
|
402
|
+
"-m",
|
|
403
|
+
stash
|
|
404
|
+
], options).success) {
|
|
208
405
|
return false;
|
|
209
406
|
}
|
|
210
|
-
const results = (0,
|
|
407
|
+
const results = (0, _git.git)([
|
|
408
|
+
"stash",
|
|
409
|
+
"list"
|
|
410
|
+
], options);
|
|
211
411
|
if (results.success) {
|
|
212
|
-
const matched = results.stdout
|
|
213
|
-
.split(/\n/)
|
|
214
|
-
.find((line) => line.includes(stash))
|
|
215
|
-
?.match(/^[^:]+/);
|
|
412
|
+
const matched = results.stdout.split(/\n/).find((line)=>line.includes(stash))?.match(/^[^:]+/);
|
|
216
413
|
if (matched) {
|
|
217
|
-
(0,
|
|
414
|
+
(0, _git.git)([
|
|
415
|
+
"stash",
|
|
416
|
+
"drop",
|
|
417
|
+
matched[0]
|
|
418
|
+
], options);
|
|
218
419
|
return true;
|
|
219
420
|
}
|
|
220
421
|
}
|
|
221
422
|
return false;
|
|
222
423
|
}
|
|
223
|
-
exports.revertLocalChanges = revertLocalChanges;
|
|
224
|
-
/**
|
|
225
|
-
* Attempts to determine the parent branch of the current branch using `git show-branch`.
|
|
226
|
-
* @returns The parent branch name if found, null otherwise
|
|
227
|
-
* @deprecated Does not appear to be used
|
|
228
|
-
*/
|
|
229
424
|
function getParentBranch(cwd) {
|
|
230
|
-
const branchName = getBranchName({
|
|
425
|
+
const branchName = getBranchName({
|
|
426
|
+
cwd
|
|
427
|
+
});
|
|
231
428
|
if (!branchName || branchName === "HEAD") {
|
|
232
429
|
return null;
|
|
233
430
|
}
|
|
234
|
-
const showBranchResult = (0,
|
|
431
|
+
const showBranchResult = (0, _git.git)([
|
|
432
|
+
"show-branch",
|
|
433
|
+
"-a"
|
|
434
|
+
], {
|
|
435
|
+
cwd
|
|
436
|
+
});
|
|
235
437
|
if (showBranchResult.success) {
|
|
236
438
|
const showBranchLines = showBranchResult.stdout.split(/\n/);
|
|
237
|
-
const parentLine = showBranchLines.find((line)
|
|
439
|
+
const parentLine = showBranchLines.find((line)=>line.includes("*") && !line.includes(branchName) && !line.includes("publish_"));
|
|
238
440
|
const matched = parentLine?.match(/\[(.*)\]/);
|
|
239
441
|
return matched ? matched[1] : null;
|
|
240
442
|
}
|
|
241
443
|
return null;
|
|
242
444
|
}
|
|
243
|
-
exports.getParentBranch = getParentBranch;
|
|
244
445
|
function getRemoteBranch(branchOrOptions, cwd) {
|
|
245
|
-
const options = typeof branchOrOptions === "string" ? {
|
|
246
|
-
|
|
446
|
+
const options = typeof branchOrOptions === "string" ? {
|
|
447
|
+
branch: branchOrOptions,
|
|
448
|
+
cwd: cwd
|
|
449
|
+
} : branchOrOptions;
|
|
450
|
+
const results = (0, _git.git)([
|
|
451
|
+
"rev-parse",
|
|
452
|
+
"--abbrev-ref",
|
|
453
|
+
"--symbolic-full-name",
|
|
454
|
+
`${options.branch}@{u}`
|
|
455
|
+
], options);
|
|
247
456
|
return results.success ? results.stdout.trim() : null;
|
|
248
457
|
}
|
|
249
|
-
exports.getRemoteBranch = getRemoteBranch;
|
|
250
458
|
function parseRemoteBranch(branchOrOptions) {
|
|
251
459
|
if (typeof branchOrOptions === "string") {
|
|
252
460
|
const branch = branchOrOptions;
|
|
253
461
|
const firstSlashPos = branch.indexOf("/", 0);
|
|
254
462
|
return {
|
|
255
463
|
remote: branch.substring(0, firstSlashPos),
|
|
256
|
-
remoteBranch: branch.substring(firstSlashPos + 1)
|
|
464
|
+
remoteBranch: branch.substring(firstSlashPos + 1)
|
|
257
465
|
};
|
|
258
466
|
}
|
|
259
|
-
const { branch, knownRemotes = [
|
|
467
|
+
const { branch, knownRemotes = [
|
|
468
|
+
"origin",
|
|
469
|
+
"upstream"
|
|
470
|
+
], ...options } = branchOrOptions;
|
|
260
471
|
if (!branch.includes("/")) {
|
|
261
|
-
return {
|
|
472
|
+
return {
|
|
473
|
+
remote: "",
|
|
474
|
+
remoteBranch: branch
|
|
475
|
+
};
|
|
262
476
|
}
|
|
263
|
-
let remote = knownRemotes.find((
|
|
477
|
+
let remote = knownRemotes.find((r)=>branch.startsWith(`${r}/`));
|
|
264
478
|
if (!remote) {
|
|
265
|
-
const remotes = (0,
|
|
266
|
-
|
|
479
|
+
const remotes = (0, _git.git)([
|
|
480
|
+
"remote"
|
|
481
|
+
], options).stdout.trim().split(/\n/);
|
|
482
|
+
remote = remotes.find((r)=>branch.startsWith(`${r}/`));
|
|
267
483
|
}
|
|
268
484
|
if (remote) {
|
|
269
|
-
return {
|
|
485
|
+
return {
|
|
486
|
+
remote,
|
|
487
|
+
remoteBranch: branch.slice(remote.length + 1)
|
|
488
|
+
};
|
|
270
489
|
}
|
|
271
|
-
return {
|
|
490
|
+
return {
|
|
491
|
+
remote: "",
|
|
492
|
+
remoteBranch: branch
|
|
493
|
+
};
|
|
272
494
|
}
|
|
273
|
-
exports.parseRemoteBranch = parseRemoteBranch;
|
|
274
495
|
function getDefaultBranch(cwdOrOptions) {
|
|
275
|
-
const options = typeof cwdOrOptions === "string" ? {
|
|
496
|
+
const options = typeof cwdOrOptions === "string" ? {
|
|
497
|
+
cwd: cwdOrOptions
|
|
498
|
+
} : cwdOrOptions;
|
|
276
499
|
// Default to the legacy 'master' for backwards compat and old git clients
|
|
277
|
-
return (0,
|
|
500
|
+
return (0, _config.getConfigValue)({
|
|
501
|
+
key: "init.defaultBranch",
|
|
502
|
+
...options
|
|
503
|
+
}) || "master";
|
|
278
504
|
}
|
|
279
|
-
exports.getDefaultBranch = getDefaultBranch;
|
|
280
505
|
function listAllTrackedFiles(patternsOrOptions, cwd) {
|
|
281
|
-
const { patterns, ...options } = Array.isArray(patternsOrOptions)
|
|
282
|
-
|
|
283
|
-
:
|
|
284
|
-
|
|
285
|
-
|
|
506
|
+
const { patterns, ...options } = Array.isArray(patternsOrOptions) ? {
|
|
507
|
+
patterns: patternsOrOptions,
|
|
508
|
+
cwd: cwd
|
|
509
|
+
} : patternsOrOptions;
|
|
510
|
+
const results = (0, _git.git)([
|
|
511
|
+
"ls-files",
|
|
512
|
+
...patterns
|
|
513
|
+
], {
|
|
514
|
+
throwOnError: true,
|
|
515
|
+
...options
|
|
516
|
+
});
|
|
517
|
+
return (0, _git.processGitOutput)(results);
|
|
286
518
|
}
|
|
287
|
-
exports.listAllTrackedFiles = listAllTrackedFiles;
|
|
288
|
-
//# sourceMappingURL=gitUtilities.js.map
|