backport 5.6.3 → 6.0.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/README.md +48 -39
- package/dist/entrypoint.cli.js +1 -1
- package/dist/entrypoint.module.d.ts +6 -5
- package/dist/entrypoint.module.js +8 -6
- package/dist/ink.d.ts +1 -0
- package/dist/ink.js +49 -0
- package/dist/main.d.ts +11 -6
- package/dist/main.js +40 -24
- package/dist/options/ConfigOptions.d.ts +47 -39
- package/dist/options/cliArgs.d.ts +28 -34
- package/dist/options/cliArgs.js +113 -94
- package/dist/options/cliArgs.test.js +103 -119
- package/dist/options/config/config.d.ts +81 -2
- package/dist/options/config/config.js +46 -6
- package/dist/options/config/config.test.js +24 -2
- package/dist/options/config/getOptionsFromGit.d.ts +3 -0
- package/dist/options/config/getOptionsFromGit.js +10 -0
- package/dist/options/config/globalConfig.d.ts +2 -1
- package/dist/options/config/globalConfig.js +8 -8
- package/dist/options/config/globalConfig.test.js +7 -3
- package/dist/options/config/projectConfig.d.ts +2 -1
- package/dist/options/config/projectConfig.js +3 -3
- package/dist/options/config/projectConfig.test.js +4 -4
- package/dist/options/config/readConfigFile.d.ts +2 -2
- package/dist/options/config/readConfigFile.js +3 -3
- package/dist/options/options.d.ts +40 -27
- package/dist/options/options.js +8 -16
- package/dist/options/options.test.js +66 -26
- package/dist/options/parseRequiredOptions.d.ts +71 -0
- package/dist/options/parseRequiredOptions.js +70 -0
- package/dist/options/parseRequiredOptions.test.d.ts +1 -0
- package/dist/options/parseRequiredOptions.test.js +127 -0
- package/dist/runSequentially.d.ts +20 -0
- package/dist/runSequentially.js +41 -0
- package/dist/runSequentially.test.d.ts +1 -0
- package/dist/runSequentially.test.js +235 -0
- package/dist/runWithOptions.js +7 -14
- package/dist/runWithOptions.test.js +142 -16
- package/dist/scripts/generate-gql.d.ts +1 -0
- package/dist/scripts/generate-gql.js +15 -0
- package/dist/scripts/postinstall.js +4 -4
- package/dist/scripts/postinstall.test.js +9 -2
- package/dist/scripts/runPostinstall.js +1 -1
- package/dist/services/HandledError.d.ts +11 -1
- package/dist/services/HandledError.js +2 -1
- package/dist/services/child-process-promisified.d.ts +1 -1
- package/dist/services/child-process-promisified.js +2 -2
- package/dist/services/env.js +5 -5
- package/dist/services/env.test.js +11 -4
- package/dist/services/fs-promisified.js +4 -4
- package/dist/services/getExpectedTarget.d.ts +9 -0
- package/dist/services/getExpectedTarget.js +77 -0
- package/dist/services/getExpectedTargetPullRequests.d.ts +9 -0
- package/dist/services/getExpectedTargetPullRequests.js +77 -0
- package/dist/services/git.d.ts +19 -4
- package/dist/services/git.integration.test.d.ts +1 -0
- package/dist/services/git.integration.test.js +168 -0
- package/dist/services/git.js +129 -57
- package/dist/services/git.test.js +155 -51
- package/dist/services/github/commitFormatters.d.ts +3 -7
- package/dist/services/github/commitFormatters.js +10 -19
- package/dist/services/github/commitFormatters.test.js +2 -24
- package/dist/services/github/v3/addAssigneesToPullRequest.d.ts +1 -1
- package/dist/services/github/v3/addAssigneesToPullRequest.js +2 -6
- package/dist/services/github/v3/addAssigneesToPullRequest.test.js +2 -3
- package/dist/services/github/v3/addLabelsToPullRequest.d.ts +1 -1
- package/dist/services/github/v3/addLabelsToPullRequest.js +2 -6
- package/dist/services/github/v3/addReviewersToPullRequest.d.ts +2 -0
- package/dist/services/github/v3/addReviewersToPullRequest.js +34 -0
- package/dist/services/github/v3/createPullRequest.d.ts +3 -2
- package/dist/services/github/v3/createPullRequest.js +33 -24
- package/dist/services/github/v3/createStatusComment.d.ts +11 -0
- package/dist/services/github/v3/createStatusComment.js +97 -0
- package/dist/services/github/v3/createStatusComment.test.d.ts +1 -0
- package/dist/services/github/v3/createStatusComment.test.js +209 -0
- package/dist/services/github/v4/FetchPullRequestId.d.ts +9 -0
- package/dist/services/github/v4/FetchPullRequestId.js +32 -0
- package/dist/services/github/v4/apiRequestV4.d.ts +1 -1
- package/dist/services/github/v4/apiRequestV4.js +8 -10
- package/dist/services/github/v4/apiRequestV4.test.js +7 -7
- package/dist/services/github/v4/disablePullRequestAutoMerge.d.ts +9 -0
- package/dist/services/github/v4/disablePullRequestAutoMerge.js +28 -0
- package/dist/services/github/v4/enablePullRequestAutoMerge.d.ts +9 -0
- package/dist/services/github/v4/enablePullRequestAutoMerge.js +51 -0
- package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.d.ts +1 -0
- package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +113 -0
- package/dist/services/github/v4/fetchAuthorId.d.ts +5 -0
- package/dist/services/github/v4/fetchAuthorId.js +1 -1
- package/dist/services/github/v4/fetchAuthorId.private.test.js +3 -3
- package/dist/services/github/v4/fetchCommitByPullNumber.js +11 -9
- package/dist/services/github/v4/fetchCommitByPullNumber.private.test.js +6 -6
- package/dist/services/github/v4/fetchCommitBySha.js +14 -12
- package/dist/services/github/v4/fetchCommitBySha.private.test.js +7 -5
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +5 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +46 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +67 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +5 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +36 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +55 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +16 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +90 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +130 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +127 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsInDateRange.d.ts +28 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsInDateRange.js +52 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.d.ts +10 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +49 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +81 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.test.js +252 -0
- package/dist/services/github/v4/fetchCommitsByAuthor.d.ts +3 -2
- package/dist/services/github/v4/fetchCommitsByAuthor.js +81 -70
- package/dist/services/github/v4/fetchCommitsByAuthor.private.test.js +81 -8
- package/dist/services/github/v4/fetchCommitsByAuthor.test.js +29 -21
- package/dist/services/github/v4/fetchDefaultBranch.d.ts +1 -1
- package/dist/services/github/v4/fetchDefaultBranch.js +1 -1
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.d.ts +4 -0
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.js +52 -0
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.private.test.js +32 -0
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.d.ts +4 -0
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.js +72 -0
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.private.test.js +34 -0
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/query.d.ts +40 -0
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/query.js +72 -0
- package/dist/services/github/v4/fetchExistingPullRequest.js +2 -3
- package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +3 -3
- package/dist/services/github/v4/fetchMergedPullRequests.d.ts +19 -20
- package/dist/services/github/v4/fetchMergedPullRequests.js +22 -68
- package/dist/services/github/v4/fetchMergedPullRequests.private.test.js +8 -9
- package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.d.ts +11 -0
- package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.js +35 -0
- package/dist/services/github/v4/fetchPullRequestBySearchQuery.d.ts +1 -1
- package/dist/services/github/v4/fetchPullRequestBySearchQuery.js +12 -10
- package/dist/services/github/v4/fetchPullRequestBySearchQuery.private.test.js +8 -6
- package/dist/services/github/v4/fetchPullRequestBySearchQuery.test.js +2 -2
- package/dist/services/github/v4/getExistingTargetPullRequests.d.ts +4 -58
- package/dist/services/github/v4/getExistingTargetPullRequests.js +3 -58
- package/dist/services/github/v4/getOptionsFromGithub/index.d.ts +61 -0
- package/dist/services/github/v4/getOptionsFromGithub/index.js +139 -0
- package/dist/services/github/v4/getOptionsFromGithub/index.private.test.d.ts +1 -0
- package/dist/services/github/v4/getOptionsFromGithub/index.private.test.js +126 -0
- package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +34 -0
- package/dist/services/github/v4/getOptionsFromGithub/query.js +44 -0
- package/dist/services/github/v4/getTargetBranchesFromLabels.d.ts +0 -7
- package/dist/services/github/v4/getTargetBranchesFromLabels.js +1 -26
- package/dist/services/github/v4/getTargetBranchesFromLabels.test.js +69 -32
- package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +2 -2
- package/dist/services/github/v4/mocks/commitsByAuthorMock.js +39 -25
- package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.d.ts +2 -2
- package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.js +10 -0
- package/dist/services/github/v4/mocks/getCommitsByAuthorMock.d.ts +2 -2
- package/dist/services/github/v4/mocks/getCommitsByAuthorMock.js +4 -1
- package/dist/services/github/v4/mocks/getPullRequestNodeMock.d.ts +1 -1
- package/dist/services/github/v4/mocks/getPullRequestNodeMock.js +1 -0
- package/dist/services/github/v4/throwOnInvalidAccessToken.d.ts +1 -1
- package/dist/services/github/v4/throwOnInvalidAccessToken.js +10 -15
- package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +7 -7
- package/dist/services/logger.d.ts +3 -3
- package/dist/services/logger.js +24 -24
- package/dist/services/prompt.test.d.ts +1 -0
- package/dist/services/prompt.test.js +87 -0
- package/dist/services/prompts.d.ts +10 -4
- package/dist/services/prompts.js +85 -22
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +9 -0
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +92 -0
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +1 -0
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +396 -0
- package/dist/services/sourceCommit/getMockSourceCommit.d.ts +21 -0
- package/dist/services/sourceCommit/getMockSourceCommit.js +67 -0
- package/dist/services/sourceCommit/getTargetBranchesFromLabels.d.ts +5 -0
- package/dist/services/sourceCommit/getTargetBranchesFromLabels.js +20 -0
- package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.d.ts +1 -0
- package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.js +201 -0
- package/dist/services/sourceCommit/parseSourceCommit.d.ts +78 -0
- package/dist/services/sourceCommit/parseSourceCommit.js +96 -0
- package/dist/services/sourceCommit/parseSourceCommit.test.d.ts +1 -0
- package/dist/services/sourceCommit/parseSourceCommit.test.js +114 -0
- package/dist/services/sourceCommit/sourceCommit.d.ts +78 -0
- package/dist/services/sourceCommit/sourceCommit.js +86 -0
- package/dist/services/sourceCommit/sourceCommit.test.d.ts +1 -0
- package/dist/services/sourceCommit/sourceCommit.test.js +287 -0
- package/dist/services/sourceCommit.d.ts +78 -0
- package/dist/services/sourceCommit.js +86 -0
- package/dist/services/sourceCommit.test.d.ts +1 -0
- package/dist/services/sourceCommit.test.js +280 -0
- package/dist/test/inquirer.private.test.js +81 -45
- package/dist/test/integration/createSpies.d.ts +1 -1
- package/dist/test/integration/createSpies.js +21 -9
- package/dist/test/integration/envConstants.js +5 -6
- package/dist/test/integration/helpers.js +1 -1
- package/dist/test/integration/integration.private.test.d.ts +1 -0
- package/dist/test/integration/integration.private.test.js +308 -0
- package/dist/test/integration/integration.test.js +30 -31
- package/dist/test/nockHelpers.d.ts +2 -2
- package/dist/test/nockHelpers.js +3 -7
- package/dist/test/setupFiles/automatic-mocks.d.ts +0 -1
- package/dist/test/setupFiles/automatic-mocks.js +0 -22
- package/dist/types/Commit.d.ts +85 -0
- package/dist/types/Commit.js +139 -0
- package/dist/types/commitNode.d.ts +89 -0
- package/dist/types/commitNode.js +139 -0
- package/dist/types/commitNode.test.d.ts +1 -0
- package/dist/types/commitNode.test.js +255 -0
- package/dist/types/commitWithAssociatedPullRequests.d.ts +86 -0
- package/dist/types/commitWithAssociatedPullRequests.js +145 -0
- package/dist/ui/cherrypickAndCreatePullRequest.test.js +277 -59
- package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +11 -1
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +135 -67
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +468 -0
- package/dist/ui/getCommits.d.ts +1 -1
- package/dist/ui/getCommits.js +55 -25
- package/dist/ui/getTargetBranches.d.ts +2 -2
- package/dist/ui/getTargetBranches.js +16 -17
- package/dist/ui/getTargetBranches.test.js +75 -99
- package/dist/ui/getTargetBranchesFromLabels.d.ts +6 -0
- package/dist/ui/getTargetBranchesFromLabels.js +40 -0
- package/dist/ui/getTargetBranchesFromLabels.test.d.ts +1 -0
- package/dist/ui/getTargetBranchesFromLabels.test.js +288 -0
- package/dist/ui/maybeSetupRepo.js +9 -9
- package/dist/ui/maybeSetupRepo.test.js +5 -1
- package/package.json +36 -51
- package/yarn.lock +2387 -2979
package/dist/services/git.d.ts
CHANGED
|
@@ -1,16 +1,31 @@
|
|
|
1
1
|
import { ValidConfigOptions } from '../options/options';
|
|
2
|
-
import { Commit } from '
|
|
2
|
+
import { Commit } from './sourceCommit/parseSourceCommit';
|
|
3
3
|
export declare function repoExists(options: ValidConfigOptions): Promise<boolean>;
|
|
4
4
|
export declare function deleteRepo(options: ValidConfigOptions): Promise<string[]>;
|
|
5
5
|
export declare function getRemoteUrl({ repoName, accessToken, gitHostname }: ValidConfigOptions, repoOwner: string): string;
|
|
6
6
|
export declare function cloneRepo(options: ValidConfigOptions, callback: (progress: string) => void): Promise<void>;
|
|
7
|
+
export declare function getLocalConfigFileCommitDate(): Promise<number | undefined>;
|
|
8
|
+
export declare function isLocalConfigFileUntracked(): Promise<boolean | undefined>;
|
|
9
|
+
export declare function isLocalConfigFileModified(): Promise<boolean | undefined>;
|
|
10
|
+
export declare function getUpstreamFromGitRemote(): Promise<string | undefined>;
|
|
11
|
+
export declare function getIsCommitInBranch(options: ValidConfigOptions, commitSha: string): Promise<boolean>;
|
|
7
12
|
export declare function deleteRemote(options: ValidConfigOptions, remoteName: string): Promise<void>;
|
|
8
13
|
export declare function addRemote(options: ValidConfigOptions, remoteName: string): Promise<void>;
|
|
9
|
-
export declare function
|
|
14
|
+
export declare function fetchBranch(options: ValidConfigOptions, branch: string): Promise<void>;
|
|
15
|
+
export declare function cherrypick(options: ValidConfigOptions, sha: Commit['sha']): Promise<{
|
|
16
|
+
conflictingFiles: {
|
|
17
|
+
absolute: string;
|
|
18
|
+
relative: string;
|
|
19
|
+
}[];
|
|
20
|
+
unstagedFiles: string[];
|
|
10
21
|
needsResolving: boolean;
|
|
11
22
|
}>;
|
|
12
23
|
export declare function commitChanges(commit: Commit, options: ValidConfigOptions): Promise<void>;
|
|
13
|
-
export declare
|
|
24
|
+
export declare type ConflictingFiles = Awaited<ReturnType<typeof getConflictingFiles>>;
|
|
25
|
+
export declare function getConflictingFiles(options: ValidConfigOptions): Promise<{
|
|
26
|
+
absolute: string;
|
|
27
|
+
relative: string;
|
|
28
|
+
}[]>;
|
|
14
29
|
export declare function getUnstagedFiles(options: ValidConfigOptions): Promise<string[]>;
|
|
15
30
|
export declare function setCommitAuthor(options: ValidConfigOptions, username: string): Promise<{
|
|
16
31
|
stdout: string;
|
|
@@ -35,4 +50,4 @@ export declare function pushBackportBranch({ options, backportBranch, }: {
|
|
|
35
50
|
}): Promise<{
|
|
36
51
|
stdout: string;
|
|
37
52
|
stderr: string;
|
|
38
|
-
}
|
|
53
|
+
}>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
const path_1 = require("path");
|
|
26
|
+
const del_1 = __importDefault(require("del"));
|
|
27
|
+
const make_dir_1 = __importDefault(require("make-dir"));
|
|
28
|
+
const childProcess = __importStar(require("./child-process-promisified"));
|
|
29
|
+
const env = __importStar(require("./env"));
|
|
30
|
+
const git_1 = require("./git");
|
|
31
|
+
const commitFormatters_1 = require("./github/commitFormatters");
|
|
32
|
+
jest.unmock('make-dir');
|
|
33
|
+
jest.unmock('del');
|
|
34
|
+
const GIT_SANDBOX_DIR_PATH = (0, path_1.resolve)(`${__dirname}/git-test-temp`);
|
|
35
|
+
async function resetGitSandbox() {
|
|
36
|
+
await (0, del_1.default)(GIT_SANDBOX_DIR_PATH);
|
|
37
|
+
await (0, make_dir_1.default)(GIT_SANDBOX_DIR_PATH);
|
|
38
|
+
// mock repo path to point to git-sandbox dir
|
|
39
|
+
jest.spyOn(env, 'getRepoPath').mockReturnValue(GIT_SANDBOX_DIR_PATH);
|
|
40
|
+
}
|
|
41
|
+
async function createAndCommitFile({ filename, content, execOpts, }) {
|
|
42
|
+
await childProcess.exec(`echo "${content}" > "${filename}"`, execOpts);
|
|
43
|
+
await childProcess.exec(`git add -A && git commit -m 'Update ${filename}'`, execOpts);
|
|
44
|
+
return getCurrentSha(execOpts);
|
|
45
|
+
}
|
|
46
|
+
async function getCurrentSha(execOpts) {
|
|
47
|
+
const { stdout } = await childProcess.exec('git rev-parse HEAD', execOpts);
|
|
48
|
+
return stdout.trim();
|
|
49
|
+
}
|
|
50
|
+
async function getCurrentMessage(execOpts) {
|
|
51
|
+
const { stdout } = await childProcess.exec('git --no-pager log -1 --pretty=%B', execOpts);
|
|
52
|
+
return stdout.trim();
|
|
53
|
+
}
|
|
54
|
+
describe('git.integration', () => {
|
|
55
|
+
describe('getIsCommitInBranch', () => {
|
|
56
|
+
let firstSha;
|
|
57
|
+
let secondSha;
|
|
58
|
+
beforeEach(async () => {
|
|
59
|
+
await resetGitSandbox();
|
|
60
|
+
const execOpts = { cwd: GIT_SANDBOX_DIR_PATH };
|
|
61
|
+
// create and commit first file
|
|
62
|
+
await childProcess.exec('git init', execOpts);
|
|
63
|
+
firstSha = await createAndCommitFile({
|
|
64
|
+
filename: 'foo.md',
|
|
65
|
+
content: 'My first file',
|
|
66
|
+
execOpts,
|
|
67
|
+
});
|
|
68
|
+
// create 7.x branch (but stay on `main` branch)
|
|
69
|
+
await childProcess.exec('git branch 7.x', execOpts);
|
|
70
|
+
// create and commit second file
|
|
71
|
+
secondSha = await createAndCommitFile({
|
|
72
|
+
filename: 'bar.md',
|
|
73
|
+
content: 'My second file',
|
|
74
|
+
execOpts,
|
|
75
|
+
});
|
|
76
|
+
// checkout 7.x
|
|
77
|
+
await childProcess.exec('git checkout 7.x', execOpts);
|
|
78
|
+
});
|
|
79
|
+
it('should contain the first commit', async () => {
|
|
80
|
+
const isFirstCommitInBranch = await (0, git_1.getIsCommitInBranch)({}, firstSha);
|
|
81
|
+
expect(isFirstCommitInBranch).toEqual(true);
|
|
82
|
+
});
|
|
83
|
+
it('should not contain the second commit', async () => {
|
|
84
|
+
const isSecondCommitInBranch = await (0, git_1.getIsCommitInBranch)({}, secondSha);
|
|
85
|
+
expect(isSecondCommitInBranch).toEqual(false);
|
|
86
|
+
});
|
|
87
|
+
it('should not contain a random commit', async () => {
|
|
88
|
+
const isSecondCommitInBranch = await (0, git_1.getIsCommitInBranch)({}, 'abcdefg');
|
|
89
|
+
expect(isSecondCommitInBranch).toEqual(false);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
describe('cherrypick', () => {
|
|
93
|
+
let firstSha;
|
|
94
|
+
let secondSha;
|
|
95
|
+
let fourthSha;
|
|
96
|
+
let execOpts;
|
|
97
|
+
beforeEach(async () => {
|
|
98
|
+
await resetGitSandbox();
|
|
99
|
+
execOpts = { cwd: GIT_SANDBOX_DIR_PATH };
|
|
100
|
+
// create and commit first file
|
|
101
|
+
await childProcess.exec('git init', execOpts);
|
|
102
|
+
firstSha = await createAndCommitFile({
|
|
103
|
+
filename: 'foo.md',
|
|
104
|
+
content: 'Creating first file',
|
|
105
|
+
execOpts,
|
|
106
|
+
});
|
|
107
|
+
// create 7.x branch (but stay on `main` branch)
|
|
108
|
+
await childProcess.exec('git branch 7.x', execOpts);
|
|
109
|
+
// create and commit second file
|
|
110
|
+
secondSha = await createAndCommitFile({
|
|
111
|
+
filename: 'bar.md',
|
|
112
|
+
content: 'Creating second file\nHello',
|
|
113
|
+
execOpts,
|
|
114
|
+
});
|
|
115
|
+
// edit first file
|
|
116
|
+
await createAndCommitFile({
|
|
117
|
+
filename: 'foo.md',
|
|
118
|
+
content: 'Changing first file',
|
|
119
|
+
execOpts,
|
|
120
|
+
});
|
|
121
|
+
// edit first file
|
|
122
|
+
fourthSha = await createAndCommitFile({
|
|
123
|
+
filename: 'foo.md',
|
|
124
|
+
content: 'Some more changes to the first file',
|
|
125
|
+
execOpts,
|
|
126
|
+
});
|
|
127
|
+
// checkout 7.x
|
|
128
|
+
await childProcess.exec('git checkout 7.x', execOpts);
|
|
129
|
+
});
|
|
130
|
+
it('should not cherrypick commit that already exists', async () => {
|
|
131
|
+
const shortSha = (0, commitFormatters_1.getShortSha)(firstSha);
|
|
132
|
+
return expect(() => (0, git_1.cherrypick)({}, firstSha)).rejects.toThrowError(`Cherrypick failed because the selected commit (${shortSha}) is empty. Did you already backport this commit?`);
|
|
133
|
+
});
|
|
134
|
+
it('should cherrypick commit cleanly', async () => {
|
|
135
|
+
const res = await (0, git_1.cherrypick)({ cherrypickRef: false }, secondSha);
|
|
136
|
+
expect(res).toEqual({
|
|
137
|
+
conflictingFiles: [],
|
|
138
|
+
needsResolving: false,
|
|
139
|
+
unstagedFiles: [],
|
|
140
|
+
});
|
|
141
|
+
const message = await getCurrentMessage(execOpts);
|
|
142
|
+
expect(message).toEqual(`Update bar.md`);
|
|
143
|
+
});
|
|
144
|
+
it('should cherrypick commit cleanly and append "(cherry picked from commit...)"', async () => {
|
|
145
|
+
const res = await (0, git_1.cherrypick)({ cherrypickRef: true }, secondSha);
|
|
146
|
+
expect(res).toEqual({
|
|
147
|
+
conflictingFiles: [],
|
|
148
|
+
needsResolving: false,
|
|
149
|
+
unstagedFiles: [],
|
|
150
|
+
});
|
|
151
|
+
const message = await getCurrentMessage(execOpts);
|
|
152
|
+
expect(message).toEqual(`Update bar.md\n\n(cherry picked from commit ${secondSha})`);
|
|
153
|
+
});
|
|
154
|
+
it('should cherrypick commit with conflicts', async () => {
|
|
155
|
+
const res = await (0, git_1.cherrypick)({}, fourthSha);
|
|
156
|
+
expect(res).toEqual({
|
|
157
|
+
needsResolving: true,
|
|
158
|
+
conflictingFiles: [
|
|
159
|
+
{
|
|
160
|
+
absolute: `${GIT_SANDBOX_DIR_PATH}/foo.md`,
|
|
161
|
+
relative: 'foo.md',
|
|
162
|
+
},
|
|
163
|
+
],
|
|
164
|
+
unstagedFiles: [`${GIT_SANDBOX_DIR_PATH}/foo.md`],
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
});
|
package/dist/services/git.js
CHANGED
|
@@ -3,11 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.pushBackportBranch = exports.getRepoForkOwner = exports.deleteBackportBranch = exports.createBackportBranch = exports.setCommitAuthor = exports.getUnstagedFiles = exports.getConflictingFiles = exports.commitChanges = exports.cherrypick = exports.addRemote = exports.deleteRemote = exports.cloneRepo = exports.getRemoteUrl = exports.deleteRepo = exports.repoExists = void 0;
|
|
6
|
+
exports.pushBackportBranch = exports.getRepoForkOwner = exports.deleteBackportBranch = exports.createBackportBranch = exports.setCommitAuthor = exports.getUnstagedFiles = exports.getConflictingFiles = exports.commitChanges = exports.cherrypick = exports.fetchBranch = exports.addRemote = exports.deleteRemote = exports.getIsCommitInBranch = exports.getUpstreamFromGitRemote = exports.isLocalConfigFileModified = exports.isLocalConfigFileUntracked = exports.getLocalConfigFileCommitDate = exports.cloneRepo = exports.getRemoteUrl = exports.deleteRepo = exports.repoExists = void 0;
|
|
7
7
|
const path_1 = require("path");
|
|
8
8
|
const del_1 = __importDefault(require("del"));
|
|
9
|
-
const
|
|
10
|
-
const lodash_uniq_1 = __importDefault(require("lodash.uniq"));
|
|
9
|
+
const lodash_1 = require("lodash");
|
|
11
10
|
const ora_1 = __importDefault(require("ora"));
|
|
12
11
|
const HandledError_1 = require("./HandledError");
|
|
13
12
|
const child_process_promisified_1 = require("./child-process-promisified");
|
|
@@ -17,7 +16,7 @@ const commitFormatters_1 = require("./github/commitFormatters");
|
|
|
17
16
|
const logger_1 = require("./logger");
|
|
18
17
|
async function folderExists(path) {
|
|
19
18
|
try {
|
|
20
|
-
const stats = await fs_promisified_1.stat(path);
|
|
19
|
+
const stats = await (0, fs_promisified_1.stat)(path);
|
|
21
20
|
return stats.isDirectory();
|
|
22
21
|
}
|
|
23
22
|
catch (e) {
|
|
@@ -28,12 +27,12 @@ async function folderExists(path) {
|
|
|
28
27
|
}
|
|
29
28
|
}
|
|
30
29
|
function repoExists(options) {
|
|
31
|
-
return folderExists(env_1.getRepoPath(options));
|
|
30
|
+
return folderExists((0, env_1.getRepoPath)(options));
|
|
32
31
|
}
|
|
33
32
|
exports.repoExists = repoExists;
|
|
34
33
|
function deleteRepo(options) {
|
|
35
|
-
const repoPath = env_1.getRepoPath(options);
|
|
36
|
-
return del_1.default(repoPath);
|
|
34
|
+
const repoPath = (0, env_1.getRepoPath)(options);
|
|
35
|
+
return (0, del_1.default)(repoPath);
|
|
37
36
|
}
|
|
38
37
|
exports.deleteRepo = deleteRepo;
|
|
39
38
|
function getRemoteUrl({ repoName, accessToken, gitHostname }, repoOwner) {
|
|
@@ -50,7 +49,7 @@ function cloneRepo(options, callback) {
|
|
|
50
49
|
resolve();
|
|
51
50
|
}
|
|
52
51
|
};
|
|
53
|
-
const execProcess = child_process_promisified_1.execAsCallback(`git clone ${getRemoteUrl(options, options.repoOwner)} --progress`, { cwd: env_1.getRepoOwnerPath(options), maxBuffer: 100 * 1024 * 1024 }, cb);
|
|
52
|
+
const execProcess = (0, child_process_promisified_1.execAsCallback)(`git clone ${getRemoteUrl(options, options.repoOwner)} --progress`, { cwd: (0, env_1.getRepoOwnerPath)(options), maxBuffer: 100 * 1024 * 1024 }, cb);
|
|
54
53
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
55
54
|
if (execProcess.stderr) {
|
|
56
55
|
execProcess.stderr.on('data', (data) => {
|
|
@@ -64,9 +63,74 @@ function cloneRepo(options, callback) {
|
|
|
64
63
|
});
|
|
65
64
|
}
|
|
66
65
|
exports.cloneRepo = cloneRepo;
|
|
66
|
+
async function getLocalConfigFileCommitDate() {
|
|
67
|
+
try {
|
|
68
|
+
const { stdout } = await (0, child_process_promisified_1.exec)('git --no-pager log -1 --format=%cd .backportrc.js*', {});
|
|
69
|
+
const timestamp = Date.parse(stdout);
|
|
70
|
+
if (timestamp > 0) {
|
|
71
|
+
return timestamp;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
catch (e) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.getLocalConfigFileCommitDate = getLocalConfigFileCommitDate;
|
|
79
|
+
async function isLocalConfigFileUntracked() {
|
|
80
|
+
try {
|
|
81
|
+
// list untracked files
|
|
82
|
+
const { stdout } = await (0, child_process_promisified_1.exec)('git ls-files .backportrc.js* --exclude-standard --others', {});
|
|
83
|
+
return !!stdout;
|
|
84
|
+
}
|
|
85
|
+
catch (e) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
exports.isLocalConfigFileUntracked = isLocalConfigFileUntracked;
|
|
90
|
+
async function isLocalConfigFileModified() {
|
|
91
|
+
try {
|
|
92
|
+
const { stdout } = await (0, child_process_promisified_1.exec)('git --no-pager diff HEAD --name-only .backportrc.js*', {});
|
|
93
|
+
return !!stdout;
|
|
94
|
+
}
|
|
95
|
+
catch (e) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
exports.isLocalConfigFileModified = isLocalConfigFileModified;
|
|
100
|
+
async function getUpstreamFromGitRemote() {
|
|
101
|
+
try {
|
|
102
|
+
const { stdout } = await (0, child_process_promisified_1.exec)('git remote --verbose', {});
|
|
103
|
+
const matches = stdout.match(/github.com[:/]{1}(.*).git/);
|
|
104
|
+
if (matches !== null) {
|
|
105
|
+
return matches[1];
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
catch (e) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
exports.getUpstreamFromGitRemote = getUpstreamFromGitRemote;
|
|
113
|
+
async function getIsCommitInBranch(options, commitSha) {
|
|
114
|
+
try {
|
|
115
|
+
const cwd = (0, env_1.getRepoPath)(options);
|
|
116
|
+
await (0, child_process_promisified_1.exec)(`git merge-base --is-ancestor ${commitSha} HEAD`, {
|
|
117
|
+
cwd,
|
|
118
|
+
});
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
catch (e) {
|
|
122
|
+
const isExecError = e.cmd && e.code > 0;
|
|
123
|
+
// re-throw if error is not an exec related error
|
|
124
|
+
if (!isExecError) {
|
|
125
|
+
throw e;
|
|
126
|
+
}
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
exports.getIsCommitInBranch = getIsCommitInBranch;
|
|
67
131
|
async function deleteRemote(options, remoteName) {
|
|
68
132
|
try {
|
|
69
|
-
await child_process_promisified_1.exec(`git remote rm ${remoteName}`, { cwd: env_1.getRepoPath(options) });
|
|
133
|
+
await (0, child_process_promisified_1.exec)(`git remote rm ${remoteName}`, { cwd: (0, env_1.getRepoPath)(options) });
|
|
70
134
|
}
|
|
71
135
|
catch (e) {
|
|
72
136
|
const isExecError = e.cmd && e.code > 0;
|
|
@@ -79,7 +143,7 @@ async function deleteRemote(options, remoteName) {
|
|
|
79
143
|
exports.deleteRemote = deleteRemote;
|
|
80
144
|
async function addRemote(options, remoteName) {
|
|
81
145
|
try {
|
|
82
|
-
await child_process_promisified_1.exec(`git remote add ${remoteName} ${getRemoteUrl(options, remoteName)}`, { cwd: env_1.getRepoPath(options) });
|
|
146
|
+
await (0, child_process_promisified_1.exec)(`git remote add ${remoteName} ${getRemoteUrl(options, remoteName)}`, { cwd: (0, env_1.getRepoPath)(options) });
|
|
83
147
|
}
|
|
84
148
|
catch (e) {
|
|
85
149
|
// note: swallowing error
|
|
@@ -87,13 +151,19 @@ async function addRemote(options, remoteName) {
|
|
|
87
151
|
}
|
|
88
152
|
}
|
|
89
153
|
exports.addRemote = addRemote;
|
|
90
|
-
async function
|
|
91
|
-
await child_process_promisified_1.exec(`git fetch ${options.repoOwner} ${
|
|
92
|
-
|
|
93
|
-
|
|
154
|
+
async function fetchBranch(options, branch) {
|
|
155
|
+
await (0, child_process_promisified_1.exec)(`git fetch ${options.repoOwner} ${branch}:${branch} --force`, {
|
|
156
|
+
cwd: (0, env_1.getRepoPath)(options),
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
exports.fetchBranch = fetchBranch;
|
|
160
|
+
async function cherrypick(options, sha) {
|
|
161
|
+
const mainlinArg = options.mainline != undefined ? ` --mainline ${options.mainline}` : '';
|
|
162
|
+
const cherrypickRefArg = options.cherrypickRef ? ' -x' : '';
|
|
163
|
+
const cmd = `git cherry-pick${cherrypickRefArg}${mainlinArg} ${sha}`;
|
|
94
164
|
try {
|
|
95
|
-
await child_process_promisified_1.exec(cmd, { cwd: env_1.getRepoPath(options) });
|
|
96
|
-
return { needsResolving: false };
|
|
165
|
+
await (0, child_process_promisified_1.exec)(cmd, { cwd: (0, env_1.getRepoPath)(options) });
|
|
166
|
+
return { conflictingFiles: [], unstagedFiles: [], needsResolving: false };
|
|
97
167
|
}
|
|
98
168
|
catch (e) {
|
|
99
169
|
// missing `mainline` option
|
|
@@ -102,21 +172,24 @@ async function cherrypick(options, commit) {
|
|
|
102
172
|
}
|
|
103
173
|
// commit was already backported
|
|
104
174
|
if (e.message.includes('The previous cherry-pick is now empty')) {
|
|
105
|
-
const shortSha = commitFormatters_1.getShortSha(
|
|
175
|
+
const shortSha = (0, commitFormatters_1.getShortSha)(sha);
|
|
106
176
|
throw new HandledError_1.HandledError(`Cherrypick failed because the selected commit (${shortSha}) is empty. Did you already backport this commit?`);
|
|
107
177
|
}
|
|
108
178
|
// git info missing
|
|
109
179
|
if (e.message.includes('Please tell me who you are')) {
|
|
110
180
|
throw new HandledError_1.HandledError(`Cherrypick failed:\n${e.message}`);
|
|
111
181
|
}
|
|
112
|
-
if (e.message.includes(`bad object ${
|
|
113
|
-
throw new HandledError_1.HandledError(`Cherrypick failed because commit "${
|
|
182
|
+
if (e.message.includes(`bad object ${sha}`)) {
|
|
183
|
+
throw new HandledError_1.HandledError(`Cherrypick failed because commit "${sha}" was not found`);
|
|
114
184
|
}
|
|
115
185
|
const isCherryPickError = e.cmd === cmd;
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
186
|
+
if (isCherryPickError) {
|
|
187
|
+
const [conflictingFiles, unstagedFiles] = await Promise.all([
|
|
188
|
+
getConflictingFiles(options),
|
|
189
|
+
getUnstagedFiles(options),
|
|
190
|
+
]);
|
|
191
|
+
if (!(0, lodash_1.isEmpty)(conflictingFiles) || !(0, lodash_1.isEmpty)(unstagedFiles))
|
|
192
|
+
return { conflictingFiles, unstagedFiles, needsResolving: true };
|
|
120
193
|
}
|
|
121
194
|
// re-throw error if there are no conflicts to solve
|
|
122
195
|
throw e;
|
|
@@ -124,23 +197,22 @@ async function cherrypick(options, commit) {
|
|
|
124
197
|
}
|
|
125
198
|
exports.cherrypick = cherrypick;
|
|
126
199
|
async function commitChanges(commit, options) {
|
|
127
|
-
|
|
128
|
-
const noVerify = options.noVerify ? ` --no-verify` : '';
|
|
200
|
+
const noVerifyFlag = options.noVerify ? ` --no-verify` : '';
|
|
129
201
|
try {
|
|
130
|
-
await child_process_promisified_1.exec(`git commit --no-edit${
|
|
131
|
-
cwd: env_1.getRepoPath(options),
|
|
202
|
+
await (0, child_process_promisified_1.exec)(`git commit --no-edit${noVerifyFlag}`, {
|
|
203
|
+
cwd: (0, env_1.getRepoPath)(options),
|
|
132
204
|
});
|
|
133
205
|
}
|
|
134
206
|
catch (e) {
|
|
135
|
-
if (
|
|
207
|
+
if (e.stdout?.includes('nothing to commit')) {
|
|
136
208
|
logger_1.logger.info(`Could not run "git commit". Probably because the changes were manually committed`, e);
|
|
137
209
|
return;
|
|
138
210
|
}
|
|
139
211
|
// manually set the commit message if the inferred commit message is empty
|
|
140
212
|
// this can happen if the user runs `git reset HEAD` and thereby aborts the cherrypick process
|
|
141
|
-
if (
|
|
142
|
-
await child_process_promisified_1.exec(`git commit -m "${commit.originalMessage}" ${
|
|
143
|
-
cwd: env_1.getRepoPath(options),
|
|
213
|
+
if (e.stderr?.includes('Aborting commit due to empty commit message')) {
|
|
214
|
+
await (0, child_process_promisified_1.exec)(`git commit -m "${commit.originalMessage}" ${noVerifyFlag}`, {
|
|
215
|
+
cwd: (0, env_1.getRepoPath)(options),
|
|
144
216
|
});
|
|
145
217
|
return;
|
|
146
218
|
}
|
|
@@ -150,9 +222,9 @@ async function commitChanges(commit, options) {
|
|
|
150
222
|
}
|
|
151
223
|
exports.commitChanges = commitChanges;
|
|
152
224
|
async function getConflictingFiles(options) {
|
|
153
|
-
const repoPath = env_1.getRepoPath(options);
|
|
225
|
+
const repoPath = (0, env_1.getRepoPath)(options);
|
|
154
226
|
try {
|
|
155
|
-
await child_process_promisified_1.exec(`git --no-pager diff --check`, { cwd: repoPath });
|
|
227
|
+
await (0, child_process_promisified_1.exec)(`git --no-pager diff --check`, { cwd: repoPath });
|
|
156
228
|
return [];
|
|
157
229
|
}
|
|
158
230
|
catch (e) {
|
|
@@ -164,9 +236,15 @@ async function getConflictingFiles(options) {
|
|
|
164
236
|
.map((line) => {
|
|
165
237
|
const posSeparator = line.indexOf(':');
|
|
166
238
|
const filename = line.slice(0, posSeparator).trim();
|
|
167
|
-
return
|
|
239
|
+
return filename;
|
|
240
|
+
});
|
|
241
|
+
const uniqueFiles = (0, lodash_1.uniq)(files);
|
|
242
|
+
return uniqueFiles.map((file) => {
|
|
243
|
+
return {
|
|
244
|
+
absolute: (0, path_1.resolve)(repoPath, file),
|
|
245
|
+
relative: file,
|
|
246
|
+
};
|
|
168
247
|
});
|
|
169
|
-
return lodash_uniq_1.default(files);
|
|
170
248
|
}
|
|
171
249
|
// rethrow error since it's unrelated
|
|
172
250
|
throw e;
|
|
@@ -175,21 +253,21 @@ async function getConflictingFiles(options) {
|
|
|
175
253
|
exports.getConflictingFiles = getConflictingFiles;
|
|
176
254
|
// retrieve the list of files that could not be cleanly merged
|
|
177
255
|
async function getUnstagedFiles(options) {
|
|
178
|
-
const repoPath = env_1.getRepoPath(options);
|
|
179
|
-
const res = await child_process_promisified_1.exec(`git --no-pager diff --name-only`, {
|
|
256
|
+
const repoPath = (0, env_1.getRepoPath)(options);
|
|
257
|
+
const res = await (0, child_process_promisified_1.exec)(`git --no-pager diff --name-only`, {
|
|
180
258
|
cwd: repoPath,
|
|
181
259
|
});
|
|
182
260
|
const files = res.stdout
|
|
183
261
|
.split('\n')
|
|
184
262
|
.filter((file) => !!file)
|
|
185
|
-
.map((file) => path_1.resolve(repoPath, file));
|
|
186
|
-
return
|
|
263
|
+
.map((file) => (0, path_1.resolve)(repoPath, file));
|
|
264
|
+
return (0, lodash_1.uniq)(files);
|
|
187
265
|
}
|
|
188
266
|
exports.getUnstagedFiles = getUnstagedFiles;
|
|
189
267
|
async function setCommitAuthor(options, username) {
|
|
190
|
-
const spinner = ora_1.default(`Changing author to "${
|
|
268
|
+
const spinner = (0, ora_1.default)(`Changing author to "${username}"`).start();
|
|
191
269
|
try {
|
|
192
|
-
const res = await child_process_promisified_1.exec(`git commit --amend --no-edit --author "${username} <${username}@users.noreply.github.com>"`, { cwd: env_1.getRepoPath(options) });
|
|
270
|
+
const res = await (0, child_process_promisified_1.exec)(`git commit --amend --no-edit --author "${username} <${username}@users.noreply.github.com>"`, { cwd: (0, env_1.getRepoPath)(options) });
|
|
193
271
|
spinner.succeed();
|
|
194
272
|
return res;
|
|
195
273
|
}
|
|
@@ -203,16 +281,16 @@ exports.setCommitAuthor = setCommitAuthor;
|
|
|
203
281
|
// ${sourceBranch} -> ${backportBranch} -> ${targetBranch}
|
|
204
282
|
// master -> backport/7.x/pr-1234 -> 7.x
|
|
205
283
|
async function createBackportBranch({ options, targetBranch, backportBranch, }) {
|
|
206
|
-
|
|
207
|
-
const spinner = ora_1.default('Pulling latest changes').start();
|
|
284
|
+
const spinner = (0, ora_1.default)('Pulling latest changes').start();
|
|
208
285
|
try {
|
|
209
|
-
const res = await child_process_promisified_1.exec(`git reset --hard && git clean -d --force && git fetch ${options.repoOwner} ${targetBranch} && git checkout -B ${backportBranch} ${options.repoOwner}/${targetBranch} --no-track`, { cwd: env_1.getRepoPath(options) });
|
|
286
|
+
const res = await (0, child_process_promisified_1.exec)(`git reset --hard && git clean -d --force && git fetch ${options.repoOwner} ${targetBranch} && git checkout -B ${backportBranch} ${options.repoOwner}/${targetBranch} --no-track`, { cwd: (0, env_1.getRepoPath)(options) });
|
|
210
287
|
spinner.succeed();
|
|
211
288
|
return res;
|
|
212
289
|
}
|
|
213
290
|
catch (e) {
|
|
214
291
|
spinner.fail();
|
|
215
|
-
const isBranchInvalid =
|
|
292
|
+
const isBranchInvalid = e.stderr?.toLowerCase().includes(`couldn't find remote ref`) ||
|
|
293
|
+
e.stderr?.toLowerCase().includes(`invalid refspec`);
|
|
216
294
|
if (isBranchInvalid) {
|
|
217
295
|
throw new HandledError_1.HandledError(`The branch "${targetBranch}" is invalid or doesn't exist`);
|
|
218
296
|
}
|
|
@@ -221,8 +299,8 @@ async function createBackportBranch({ options, targetBranch, backportBranch, })
|
|
|
221
299
|
}
|
|
222
300
|
exports.createBackportBranch = createBackportBranch;
|
|
223
301
|
async function deleteBackportBranch({ options, backportBranch, }) {
|
|
224
|
-
const spinner = ora_1.default().start();
|
|
225
|
-
await child_process_promisified_1.exec(`git reset --hard && git checkout ${options.sourceBranch} && git branch -D ${backportBranch}`, { cwd: env_1.getRepoPath(options) });
|
|
302
|
+
const spinner = (0, ora_1.default)().start();
|
|
303
|
+
await (0, child_process_promisified_1.exec)(`git reset --hard && git checkout ${options.sourceBranch} && git branch -D ${backportBranch}`, { cwd: (0, env_1.getRepoPath)(options) });
|
|
226
304
|
spinner.stop();
|
|
227
305
|
}
|
|
228
306
|
exports.deleteBackportBranch = deleteBackportBranch;
|
|
@@ -234,23 +312,17 @@ function getRepoForkOwner(options) {
|
|
|
234
312
|
}
|
|
235
313
|
exports.getRepoForkOwner = getRepoForkOwner;
|
|
236
314
|
async function pushBackportBranch({ options, backportBranch, }) {
|
|
237
|
-
var _a;
|
|
238
315
|
const repoForkOwner = getRepoForkOwner(options);
|
|
239
|
-
const
|
|
240
|
-
const spinner = ora_1.default(spinnerText).start();
|
|
241
|
-
if (options.dryRun) {
|
|
242
|
-
spinner.succeed(`Dry run: ${spinnerText}`);
|
|
243
|
-
return;
|
|
244
|
-
}
|
|
316
|
+
const spinner = (0, ora_1.default)(`Pushing branch "${repoForkOwner}:${backportBranch}"`).start();
|
|
245
317
|
try {
|
|
246
|
-
const res = await child_process_promisified_1.exec(`git push ${repoForkOwner} ${backportBranch}:${backportBranch} --force`, { cwd: env_1.getRepoPath(options) });
|
|
318
|
+
const res = await (0, child_process_promisified_1.exec)(`git push ${repoForkOwner} ${backportBranch}:${backportBranch} --force`, { cwd: (0, env_1.getRepoPath)(options) });
|
|
247
319
|
spinner.succeed();
|
|
248
320
|
return res;
|
|
249
321
|
}
|
|
250
322
|
catch (e) {
|
|
251
323
|
spinner.fail();
|
|
252
|
-
if (
|
|
253
|
-
throw new HandledError_1.HandledError(`Error pushing to https://github.com/${repoForkOwner}/${options.repoName}. Repository does not exist. Either fork the source repository (https://github.com/${options.repoOwner}/${options.repoName}) or disable fork mode "--fork
|
|
324
|
+
if (e.stderr?.toLowerCase().includes(`repository not found`)) {
|
|
325
|
+
throw new HandledError_1.HandledError(`Error pushing to https://github.com/${repoForkOwner}/${options.repoName}. Repository does not exist. Either fork the source repository (https://github.com/${options.repoOwner}/${options.repoName}) or disable fork mode "--no-fork". Read more about "fork mode" in the docs: https://github.com/sqren/backport/blob/3a182b17e0e7237c12915895aea9d71f49eb2886/docs/configuration.md#fork`);
|
|
254
326
|
}
|
|
255
327
|
throw e;
|
|
256
328
|
}
|