backport 5.6.5 → 6.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/README.md +166 -41
- package/dist/entrypoint.cli.js +3 -1
- package/dist/entrypoint.module.d.ts +18 -5
- package/dist/entrypoint.module.js +42 -12
- package/dist/entrypoint.module.private.test.d.ts +1 -0
- package/dist/entrypoint.module.private.test.js +34 -0
- 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 -25
- package/dist/options/ConfigOptions.d.ts +28 -12
- package/dist/options/cliArgs.d.ts +36 -35
- package/dist/options/cliArgs.js +91 -52
- package/dist/options/cliArgs.test.js +41 -42
- package/dist/options/config/config.d.ts +34 -57
- package/dist/options/config/config.js +5 -39
- package/dist/options/config/config.test.js +11 -25
- package/dist/options/config/getOptionsFromGit.d.ts +3 -2
- package/dist/options/config/getOptionsFromGit.js +1 -3
- package/dist/options/config/globalConfig.d.ts +2 -49
- package/dist/options/config/globalConfig.js +9 -12
- package/dist/options/config/globalConfig.test.js +7 -5
- package/dist/options/config/projectConfig.d.ts +2 -49
- package/dist/options/config/projectConfig.js +2 -2
- package/dist/options/config/projectConfig.test.js +53 -16
- package/dist/options/config/readConfigFile.d.ts +43 -39
- package/dist/options/config/readConfigFile.js +30 -4
- package/dist/options/options.d.ts +57 -31
- package/dist/options/options.js +102 -10
- package/dist/options/options.test.js +263 -61
- package/dist/options/parseRequiredOptions.d.ts +19 -14
- package/dist/options/parseRequiredOptions.js +9 -15
- package/dist/options/parseRequiredOptions.test.js +30 -26
- 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 +196 -0
- package/dist/runWithOptions.js +7 -14
- package/dist/runWithOptions.test.js +140 -17
- 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 +1 -1
- 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 +20 -6
- package/dist/services/git.integration.test.d.ts +1 -0
- package/dist/services/git.integration.test.js +168 -0
- package/dist/services/git.js +93 -67
- package/dist/services/git.test.js +68 -68
- 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 +3 -8
- package/dist/services/github/v3/addAssigneesToPullRequest.test.js +6 -8
- 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 +31 -29
- package/dist/services/github/v3/createPullRequest.test.d.ts +1 -0
- package/dist/services/github/v3/createPullRequest.test.js +110 -0
- 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 +2 -2
- 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 +1 -8
- package/dist/services/github/v4/disablePullRequestAutoMerge.js +6 -32
- package/dist/services/github/v4/enablePullRequestAutoMerge.d.ts +1 -8
- package/dist/services/github/v4/enablePullRequestAutoMerge.js +31 -40
- package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.d.ts +1 -0
- package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +112 -0
- package/dist/services/github/v4/fetchAuthorId.d.ts +5 -2
- package/dist/services/github/v4/fetchAuthorId.js +6 -7
- package/dist/services/github/v4/fetchAuthorId.private.test.js +6 -9
- package/dist/services/github/v4/fetchCommitByPullNumber.js +11 -9
- package/dist/services/github/v4/fetchCommitByPullNumber.private.test.js +4 -4
- package/dist/services/github/v4/fetchCommitBySha.js +14 -12
- package/dist/services/github/v4/fetchCommitBySha.private.test.js +4 -4
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +12 -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 +70 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +12 -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 +27 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +88 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +128 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +125 -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/fetchProjectConfig.d.ts +3 -0
- package/dist/services/github/v4/fetchCommits/fetchProjectConfig.js +55 -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 +77 -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 +2 -1
- package/dist/services/github/v4/fetchCommitsByAuthor.js +81 -70
- package/dist/services/github/v4/fetchCommitsByAuthor.private.test.js +78 -5
- package/dist/services/github/v4/fetchCommitsByAuthor.test.js +29 -21
- package/dist/services/github/v4/fetchDefaultBranch.js +1 -1
- package/dist/services/github/v4/fetchExistingPullRequest.js +2 -3
- package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +3 -5
- package/dist/services/github/v4/fetchMergedPullRequests.d.ts +18 -19
- package/dist/services/github/v4/fetchMergedPullRequests.js +22 -69
- package/dist/services/github/v4/fetchMergedPullRequests.private.test.js +8 -9
- package/dist/services/github/v4/fetchProjectConfig.d.ts +8 -0
- package/dist/services/github/v4/fetchProjectConfig.js +56 -0
- package/dist/services/github/v4/fetchProjectConfig.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchProjectConfig.private.test.js +52 -0
- package/dist/services/github/v4/fetchProjectConfig.test.d.ts +1 -0
- package/dist/services/github/v4/fetchProjectConfig.test.js +37 -0
- 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.js +12 -10
- package/dist/services/github/v4/fetchPullRequestBySearchQuery.private.test.js +3 -3
- 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/getOptionsFromGithub.d.ts +66 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +130 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +1 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +130 -0
- package/dist/services/github/v4/getOptionsFromGithub/index.d.ts +19 -9
- package/dist/services/github/v4/getOptionsFromGithub/index.js +59 -19
- package/dist/services/github/v4/getOptionsFromGithub/index.private.test.js +119 -32
- package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +16 -16
- package/dist/services/github/v4/getOptionsFromGithub/query.js +16 -15
- 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 +1 -1
- package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.js +10 -0
- package/dist/services/github/v4/mocks/getCommitsByAuthorMock.d.ts +1 -1
- package/dist/services/github/v4/mocks/getCommitsByAuthorMock.js +2 -0
- 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 +16 -15
- 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 +413 -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 +82 -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 +229 -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 +64 -49
- package/dist/test/integration/createSpies.js +6 -6
- 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 +327 -0
- package/dist/test/integration/integration.test.js +28 -29
- package/dist/test/mockConfigFiles.d.ts +5 -0
- package/dist/test/mockConfigFiles.js +37 -0
- package/dist/test/nockHelpers.d.ts +1 -1
- package/dist/test/nockHelpers.js +7 -11
- package/dist/test/private/getDevAccessToken.js +1 -1
- package/dist/test/setupFiles/automatic-mocks.d.ts +0 -1
- package/dist/test/setupFiles/automatic-mocks.js +1 -51
- 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 +346 -76
- package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +11 -1
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +138 -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 +3 -2
- package/dist/ui/getTargetBranches.js +33 -18
- 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 +11 -10
- package/dist/ui/maybeSetupRepo.test.js +54 -4
- package/dist/utils/excludeUndefined.d.ts +6 -0
- package/dist/utils/excludeUndefined.js +7 -0
- package/dist/utils/excludeUndefined.test.d.ts +1 -0
- package/dist/utils/excludeUndefined.test.js +24 -0
- package/package.json +37 -51
- package/yarn.lock +2414 -2993
package/dist/services/git.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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;
|
|
@@ -7,16 +7,30 @@ export declare function cloneRepo(options: ValidConfigOptions, callback: (progre
|
|
|
7
7
|
export declare function getLocalConfigFileCommitDate(): Promise<number | undefined>;
|
|
8
8
|
export declare function isLocalConfigFileUntracked(): Promise<boolean | undefined>;
|
|
9
9
|
export declare function isLocalConfigFileModified(): Promise<boolean | undefined>;
|
|
10
|
-
export declare function
|
|
10
|
+
export declare function getRepoOwnerAndNameFromGitRemote(): Promise<{
|
|
11
|
+
repoOwner: string;
|
|
12
|
+
repoName: string;
|
|
13
|
+
} | undefined>;
|
|
14
|
+
export declare function getIsCommitInBranch(options: ValidConfigOptions, commitSha: string): Promise<boolean>;
|
|
11
15
|
export declare function deleteRemote(options: ValidConfigOptions, remoteName: string): Promise<void>;
|
|
12
16
|
export declare function addRemote(options: ValidConfigOptions, remoteName: string): Promise<void>;
|
|
13
|
-
export declare function
|
|
17
|
+
export declare function fetchBranch(options: ValidConfigOptions, branch: string): Promise<void>;
|
|
18
|
+
export declare function cherrypick(options: ValidConfigOptions, sha: Commit['sha']): Promise<{
|
|
19
|
+
conflictingFiles: {
|
|
20
|
+
absolute: string;
|
|
21
|
+
relative: string;
|
|
22
|
+
}[];
|
|
23
|
+
unstagedFiles: string[];
|
|
14
24
|
needsResolving: boolean;
|
|
15
25
|
}>;
|
|
16
26
|
export declare function commitChanges(commit: Commit, options: ValidConfigOptions): Promise<void>;
|
|
17
|
-
export declare
|
|
27
|
+
export declare type ConflictingFiles = Awaited<ReturnType<typeof getConflictingFiles>>;
|
|
28
|
+
export declare function getConflictingFiles(options: ValidConfigOptions): Promise<{
|
|
29
|
+
absolute: string;
|
|
30
|
+
relative: string;
|
|
31
|
+
}[]>;
|
|
18
32
|
export declare function getUnstagedFiles(options: ValidConfigOptions): Promise<string[]>;
|
|
19
|
-
export declare function setCommitAuthor(options: ValidConfigOptions,
|
|
33
|
+
export declare function setCommitAuthor(options: ValidConfigOptions, author: string): Promise<{
|
|
20
34
|
stdout: string;
|
|
21
35
|
stderr: string;
|
|
22
36
|
}>;
|
|
@@ -39,4 +53,4 @@ export declare function pushBackportBranch({ options, backportBranch, }: {
|
|
|
39
53
|
}): Promise<{
|
|
40
54
|
stdout: string;
|
|
41
55
|
stderr: string;
|
|
42
|
-
}
|
|
56
|
+
}>;
|
|
@@ -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.
|
|
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.getRepoOwnerAndNameFromGitRemote = 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,15 +27,15 @@ 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
|
-
function getRemoteUrl({ repoName, accessToken, gitHostname }, repoOwner) {
|
|
38
|
+
function getRemoteUrl({ repoName, accessToken, gitHostname = 'github.com' }, repoOwner) {
|
|
40
39
|
return `https://x-access-token:${accessToken}@${gitHostname}/${repoOwner}/${repoName}.git`;
|
|
41
40
|
}
|
|
42
41
|
exports.getRemoteUrl = getRemoteUrl;
|
|
@@ -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) => {
|
|
@@ -66,7 +65,7 @@ function cloneRepo(options, callback) {
|
|
|
66
65
|
exports.cloneRepo = cloneRepo;
|
|
67
66
|
async function getLocalConfigFileCommitDate() {
|
|
68
67
|
try {
|
|
69
|
-
const { stdout } = await child_process_promisified_1.exec('git --no-pager log -1 --format=%cd .backportrc.js*', {});
|
|
68
|
+
const { stdout } = await (0, child_process_promisified_1.exec)('git --no-pager log -1 --format=%cd .backportrc.js*', {});
|
|
70
69
|
const timestamp = Date.parse(stdout);
|
|
71
70
|
if (timestamp > 0) {
|
|
72
71
|
return timestamp;
|
|
@@ -80,7 +79,7 @@ exports.getLocalConfigFileCommitDate = getLocalConfigFileCommitDate;
|
|
|
80
79
|
async function isLocalConfigFileUntracked() {
|
|
81
80
|
try {
|
|
82
81
|
// list untracked files
|
|
83
|
-
const { stdout } = await child_process_promisified_1.exec('git ls-files .backportrc.js* --exclude-standard --others', {});
|
|
82
|
+
const { stdout } = await (0, child_process_promisified_1.exec)('git ls-files .backportrc.js* --exclude-standard --others', {});
|
|
84
83
|
return !!stdout;
|
|
85
84
|
}
|
|
86
85
|
catch (e) {
|
|
@@ -90,7 +89,7 @@ async function isLocalConfigFileUntracked() {
|
|
|
90
89
|
exports.isLocalConfigFileUntracked = isLocalConfigFileUntracked;
|
|
91
90
|
async function isLocalConfigFileModified() {
|
|
92
91
|
try {
|
|
93
|
-
const { stdout } = await child_process_promisified_1.exec('git --no-pager diff HEAD --name-only .backportrc.js*', {});
|
|
92
|
+
const { stdout } = await (0, child_process_promisified_1.exec)('git --no-pager diff HEAD --name-only .backportrc.js*', {});
|
|
94
93
|
return !!stdout;
|
|
95
94
|
}
|
|
96
95
|
catch (e) {
|
|
@@ -98,22 +97,41 @@ async function isLocalConfigFileModified() {
|
|
|
98
97
|
}
|
|
99
98
|
}
|
|
100
99
|
exports.isLocalConfigFileModified = isLocalConfigFileModified;
|
|
101
|
-
async function
|
|
100
|
+
async function getRepoOwnerAndNameFromGitRemote() {
|
|
102
101
|
try {
|
|
103
|
-
const { stdout } = await child_process_promisified_1.exec('git remote --verbose', {});
|
|
102
|
+
const { stdout } = await (0, child_process_promisified_1.exec)('git remote --verbose', {});
|
|
104
103
|
const matches = stdout.match(/github.com[:/]{1}(.*).git/);
|
|
105
104
|
if (matches !== null) {
|
|
106
|
-
|
|
105
|
+
const [repoOwner, repoName] = matches[1].split('/');
|
|
106
|
+
return { repoOwner, repoName };
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
catch (e) {
|
|
110
110
|
return;
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
|
-
exports.
|
|
113
|
+
exports.getRepoOwnerAndNameFromGitRemote = getRepoOwnerAndNameFromGitRemote;
|
|
114
|
+
async function getIsCommitInBranch(options, commitSha) {
|
|
115
|
+
try {
|
|
116
|
+
const cwd = (0, env_1.getRepoPath)(options);
|
|
117
|
+
await (0, child_process_promisified_1.exec)(`git merge-base --is-ancestor ${commitSha} HEAD`, {
|
|
118
|
+
cwd,
|
|
119
|
+
});
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
catch (e) {
|
|
123
|
+
const isExecError = e.cmd && e.code > 0;
|
|
124
|
+
// re-throw if error is not an exec related error
|
|
125
|
+
if (!isExecError) {
|
|
126
|
+
throw e;
|
|
127
|
+
}
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
exports.getIsCommitInBranch = getIsCommitInBranch;
|
|
114
132
|
async function deleteRemote(options, remoteName) {
|
|
115
133
|
try {
|
|
116
|
-
await child_process_promisified_1.exec(`git remote rm ${remoteName}`, { cwd: env_1.getRepoPath(options) });
|
|
134
|
+
await (0, child_process_promisified_1.exec)(`git remote rm ${remoteName}`, { cwd: (0, env_1.getRepoPath)(options) });
|
|
117
135
|
}
|
|
118
136
|
catch (e) {
|
|
119
137
|
const isExecError = e.cmd && e.code > 0;
|
|
@@ -126,7 +144,7 @@ async function deleteRemote(options, remoteName) {
|
|
|
126
144
|
exports.deleteRemote = deleteRemote;
|
|
127
145
|
async function addRemote(options, remoteName) {
|
|
128
146
|
try {
|
|
129
|
-
await child_process_promisified_1.exec(`git remote add ${remoteName} ${getRemoteUrl(options, remoteName)}`, { cwd: env_1.getRepoPath(options) });
|
|
147
|
+
await (0, child_process_promisified_1.exec)(`git remote add ${remoteName} ${getRemoteUrl(options, remoteName)}`, { cwd: (0, env_1.getRepoPath)(options) });
|
|
130
148
|
}
|
|
131
149
|
catch (e) {
|
|
132
150
|
// note: swallowing error
|
|
@@ -134,13 +152,19 @@ async function addRemote(options, remoteName) {
|
|
|
134
152
|
}
|
|
135
153
|
}
|
|
136
154
|
exports.addRemote = addRemote;
|
|
137
|
-
async function
|
|
138
|
-
await child_process_promisified_1.exec(`git fetch ${options.repoOwner} ${
|
|
139
|
-
|
|
140
|
-
|
|
155
|
+
async function fetchBranch(options, branch) {
|
|
156
|
+
await (0, child_process_promisified_1.exec)(`git fetch ${options.repoOwner} ${branch}:${branch} --force`, {
|
|
157
|
+
cwd: (0, env_1.getRepoPath)(options),
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
exports.fetchBranch = fetchBranch;
|
|
161
|
+
async function cherrypick(options, sha) {
|
|
162
|
+
const mainlinArg = options.mainline != undefined ? ` --mainline ${options.mainline}` : '';
|
|
163
|
+
const cherrypickRefArg = options.cherrypickRef === false ? '' : ' -x';
|
|
164
|
+
const cmd = `git cherry-pick${cherrypickRefArg}${mainlinArg} ${sha}`;
|
|
141
165
|
try {
|
|
142
|
-
await child_process_promisified_1.exec(cmd, { cwd: env_1.getRepoPath(options) });
|
|
143
|
-
return { needsResolving: false };
|
|
166
|
+
await (0, child_process_promisified_1.exec)(cmd, { cwd: (0, env_1.getRepoPath)(options) });
|
|
167
|
+
return { conflictingFiles: [], unstagedFiles: [], needsResolving: false };
|
|
144
168
|
}
|
|
145
169
|
catch (e) {
|
|
146
170
|
// missing `mainline` option
|
|
@@ -149,21 +173,24 @@ async function cherrypick(options, commit) {
|
|
|
149
173
|
}
|
|
150
174
|
// commit was already backported
|
|
151
175
|
if (e.message.includes('The previous cherry-pick is now empty')) {
|
|
152
|
-
const shortSha = commitFormatters_1.getShortSha(
|
|
176
|
+
const shortSha = (0, commitFormatters_1.getShortSha)(sha);
|
|
153
177
|
throw new HandledError_1.HandledError(`Cherrypick failed because the selected commit (${shortSha}) is empty. Did you already backport this commit?`);
|
|
154
178
|
}
|
|
155
179
|
// git info missing
|
|
156
180
|
if (e.message.includes('Please tell me who you are')) {
|
|
157
181
|
throw new HandledError_1.HandledError(`Cherrypick failed:\n${e.message}`);
|
|
158
182
|
}
|
|
159
|
-
if (e.message.includes(`bad object ${
|
|
160
|
-
throw new HandledError_1.HandledError(`Cherrypick failed because commit "${
|
|
183
|
+
if (e.message.includes(`bad object ${sha}`)) {
|
|
184
|
+
throw new HandledError_1.HandledError(`Cherrypick failed because commit "${sha}" was not found`);
|
|
161
185
|
}
|
|
162
186
|
const isCherryPickError = e.cmd === cmd;
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
187
|
+
if (isCherryPickError) {
|
|
188
|
+
const [conflictingFiles, unstagedFiles] = await Promise.all([
|
|
189
|
+
getConflictingFiles(options),
|
|
190
|
+
getUnstagedFiles(options),
|
|
191
|
+
]);
|
|
192
|
+
if (!(0, lodash_1.isEmpty)(conflictingFiles) || !(0, lodash_1.isEmpty)(unstagedFiles))
|
|
193
|
+
return { conflictingFiles, unstagedFiles, needsResolving: true };
|
|
167
194
|
}
|
|
168
195
|
// re-throw error if there are no conflicts to solve
|
|
169
196
|
throw e;
|
|
@@ -171,23 +198,22 @@ async function cherrypick(options, commit) {
|
|
|
171
198
|
}
|
|
172
199
|
exports.cherrypick = cherrypick;
|
|
173
200
|
async function commitChanges(commit, options) {
|
|
174
|
-
|
|
175
|
-
const noVerify = options.noVerify ? ` --no-verify` : '';
|
|
201
|
+
const noVerifyFlag = options.noVerify ? ` --no-verify` : '';
|
|
176
202
|
try {
|
|
177
|
-
await child_process_promisified_1.exec(`git commit --no-edit${
|
|
178
|
-
cwd: env_1.getRepoPath(options),
|
|
203
|
+
await (0, child_process_promisified_1.exec)(`git commit --no-edit${noVerifyFlag}`, {
|
|
204
|
+
cwd: (0, env_1.getRepoPath)(options),
|
|
179
205
|
});
|
|
180
206
|
}
|
|
181
207
|
catch (e) {
|
|
182
|
-
if (
|
|
208
|
+
if (e.stdout?.includes('nothing to commit')) {
|
|
183
209
|
logger_1.logger.info(`Could not run "git commit". Probably because the changes were manually committed`, e);
|
|
184
210
|
return;
|
|
185
211
|
}
|
|
186
212
|
// manually set the commit message if the inferred commit message is empty
|
|
187
213
|
// this can happen if the user runs `git reset HEAD` and thereby aborts the cherrypick process
|
|
188
|
-
if (
|
|
189
|
-
await child_process_promisified_1.exec(`git commit -m "${commit.originalMessage}" ${
|
|
190
|
-
cwd: env_1.getRepoPath(options),
|
|
214
|
+
if (e.stderr?.includes('Aborting commit due to empty commit message')) {
|
|
215
|
+
await (0, child_process_promisified_1.exec)(`git commit -m "${commit.originalMessage}" ${noVerifyFlag}`, {
|
|
216
|
+
cwd: (0, env_1.getRepoPath)(options),
|
|
191
217
|
});
|
|
192
218
|
return;
|
|
193
219
|
}
|
|
@@ -197,9 +223,9 @@ async function commitChanges(commit, options) {
|
|
|
197
223
|
}
|
|
198
224
|
exports.commitChanges = commitChanges;
|
|
199
225
|
async function getConflictingFiles(options) {
|
|
200
|
-
const repoPath = env_1.getRepoPath(options);
|
|
226
|
+
const repoPath = (0, env_1.getRepoPath)(options);
|
|
201
227
|
try {
|
|
202
|
-
await child_process_promisified_1.exec(`git --no-pager diff --check`, { cwd: repoPath });
|
|
228
|
+
await (0, child_process_promisified_1.exec)(`git --no-pager diff --check`, { cwd: repoPath });
|
|
203
229
|
return [];
|
|
204
230
|
}
|
|
205
231
|
catch (e) {
|
|
@@ -211,9 +237,15 @@ async function getConflictingFiles(options) {
|
|
|
211
237
|
.map((line) => {
|
|
212
238
|
const posSeparator = line.indexOf(':');
|
|
213
239
|
const filename = line.slice(0, posSeparator).trim();
|
|
214
|
-
return
|
|
240
|
+
return filename;
|
|
241
|
+
});
|
|
242
|
+
const uniqueFiles = (0, lodash_1.uniq)(files);
|
|
243
|
+
return uniqueFiles.map((file) => {
|
|
244
|
+
return {
|
|
245
|
+
absolute: (0, path_1.resolve)(repoPath, file),
|
|
246
|
+
relative: file,
|
|
247
|
+
};
|
|
215
248
|
});
|
|
216
|
-
return lodash_uniq_1.default(files);
|
|
217
249
|
}
|
|
218
250
|
// rethrow error since it's unrelated
|
|
219
251
|
throw e;
|
|
@@ -222,21 +254,21 @@ async function getConflictingFiles(options) {
|
|
|
222
254
|
exports.getConflictingFiles = getConflictingFiles;
|
|
223
255
|
// retrieve the list of files that could not be cleanly merged
|
|
224
256
|
async function getUnstagedFiles(options) {
|
|
225
|
-
const repoPath = env_1.getRepoPath(options);
|
|
226
|
-
const res = await child_process_promisified_1.exec(`git --no-pager diff --name-only`, {
|
|
257
|
+
const repoPath = (0, env_1.getRepoPath)(options);
|
|
258
|
+
const res = await (0, child_process_promisified_1.exec)(`git --no-pager diff --name-only`, {
|
|
227
259
|
cwd: repoPath,
|
|
228
260
|
});
|
|
229
261
|
const files = res.stdout
|
|
230
262
|
.split('\n')
|
|
231
263
|
.filter((file) => !!file)
|
|
232
|
-
.map((file) => path_1.resolve(repoPath, file));
|
|
233
|
-
return
|
|
264
|
+
.map((file) => (0, path_1.resolve)(repoPath, file));
|
|
265
|
+
return (0, lodash_1.uniq)(files);
|
|
234
266
|
}
|
|
235
267
|
exports.getUnstagedFiles = getUnstagedFiles;
|
|
236
|
-
async function setCommitAuthor(options,
|
|
237
|
-
const spinner = ora_1.default(`Changing author to "${
|
|
268
|
+
async function setCommitAuthor(options, author) {
|
|
269
|
+
const spinner = (0, ora_1.default)(`Changing author to "${author}"`).start();
|
|
238
270
|
try {
|
|
239
|
-
const res = await child_process_promisified_1.exec(`git commit --amend --no-edit --author "${
|
|
271
|
+
const res = await (0, child_process_promisified_1.exec)(`git commit --amend --no-edit --author "${author} <${author}@users.noreply.github.com>"`, { cwd: (0, env_1.getRepoPath)(options) });
|
|
240
272
|
spinner.succeed();
|
|
241
273
|
return res;
|
|
242
274
|
}
|
|
@@ -250,16 +282,16 @@ exports.setCommitAuthor = setCommitAuthor;
|
|
|
250
282
|
// ${sourceBranch} -> ${backportBranch} -> ${targetBranch}
|
|
251
283
|
// master -> backport/7.x/pr-1234 -> 7.x
|
|
252
284
|
async function createBackportBranch({ options, targetBranch, backportBranch, }) {
|
|
253
|
-
|
|
254
|
-
const spinner = ora_1.default('Pulling latest changes').start();
|
|
285
|
+
const spinner = (0, ora_1.default)('Pulling latest changes').start();
|
|
255
286
|
try {
|
|
256
|
-
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) });
|
|
287
|
+
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) });
|
|
257
288
|
spinner.succeed();
|
|
258
289
|
return res;
|
|
259
290
|
}
|
|
260
291
|
catch (e) {
|
|
261
292
|
spinner.fail();
|
|
262
|
-
const isBranchInvalid =
|
|
293
|
+
const isBranchInvalid = e.stderr?.toLowerCase().includes(`couldn't find remote ref`) ||
|
|
294
|
+
e.stderr?.toLowerCase().includes(`invalid refspec`);
|
|
263
295
|
if (isBranchInvalid) {
|
|
264
296
|
throw new HandledError_1.HandledError(`The branch "${targetBranch}" is invalid or doesn't exist`);
|
|
265
297
|
}
|
|
@@ -268,8 +300,8 @@ async function createBackportBranch({ options, targetBranch, backportBranch, })
|
|
|
268
300
|
}
|
|
269
301
|
exports.createBackportBranch = createBackportBranch;
|
|
270
302
|
async function deleteBackportBranch({ options, backportBranch, }) {
|
|
271
|
-
const spinner = ora_1.default().start();
|
|
272
|
-
await child_process_promisified_1.exec(`git reset --hard && git checkout ${options.sourceBranch} && git branch -D ${backportBranch}`, { cwd: env_1.getRepoPath(options) });
|
|
303
|
+
const spinner = (0, ora_1.default)().start();
|
|
304
|
+
await (0, child_process_promisified_1.exec)(`git reset --hard && git checkout ${options.sourceBranch} && git branch -D ${backportBranch}`, { cwd: (0, env_1.getRepoPath)(options) });
|
|
273
305
|
spinner.stop();
|
|
274
306
|
}
|
|
275
307
|
exports.deleteBackportBranch = deleteBackportBranch;
|
|
@@ -277,27 +309,21 @@ exports.deleteBackportBranch = deleteBackportBranch;
|
|
|
277
309
|
* Returns the repo owner of the forked repo or the source repo
|
|
278
310
|
*/
|
|
279
311
|
function getRepoForkOwner(options) {
|
|
280
|
-
return options.fork ? options.
|
|
312
|
+
return options.fork ? options.authenticatedUsername : options.repoOwner;
|
|
281
313
|
}
|
|
282
314
|
exports.getRepoForkOwner = getRepoForkOwner;
|
|
283
315
|
async function pushBackportBranch({ options, backportBranch, }) {
|
|
284
|
-
var _a;
|
|
285
316
|
const repoForkOwner = getRepoForkOwner(options);
|
|
286
|
-
const
|
|
287
|
-
const spinner = ora_1.default(spinnerText).start();
|
|
288
|
-
if (options.dryRun) {
|
|
289
|
-
spinner.succeed(`Dry run: ${spinnerText}`);
|
|
290
|
-
return;
|
|
291
|
-
}
|
|
317
|
+
const spinner = (0, ora_1.default)(`Pushing branch "${repoForkOwner}:${backportBranch}"`).start();
|
|
292
318
|
try {
|
|
293
|
-
const res = await child_process_promisified_1.exec(`git push ${repoForkOwner} ${backportBranch}:${backportBranch} --force`, { cwd: env_1.getRepoPath(options) });
|
|
319
|
+
const res = await (0, child_process_promisified_1.exec)(`git push ${repoForkOwner} ${backportBranch}:${backportBranch} --force`, { cwd: (0, env_1.getRepoPath)(options) });
|
|
294
320
|
spinner.succeed();
|
|
295
321
|
return res;
|
|
296
322
|
}
|
|
297
323
|
catch (e) {
|
|
298
324
|
spinner.fail();
|
|
299
|
-
if (
|
|
300
|
-
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
|
|
325
|
+
if (e.stderr?.toLowerCase().includes(`repository not found`)) {
|
|
326
|
+
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`);
|
|
301
327
|
}
|
|
302
328
|
throw e;
|
|
303
329
|
}
|