@biffo/cli 0.198.2 → 0.198.3
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/dist/index.js +45 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1070,6 +1070,15 @@ var GitAdapter = class {
|
|
|
1070
1070
|
async createBranch(cwd, branch) {
|
|
1071
1071
|
await execa2("git", ["switch", "-c", branch], { cwd });
|
|
1072
1072
|
}
|
|
1073
|
+
/**
|
|
1074
|
+
* Switch to an existing branch. Fails if it does not exist, and — deliberately
|
|
1075
|
+
* — if the switch would discard uncommitted work: this is the undo half of
|
|
1076
|
+
* `createBranch` (#984), so it must never be able to destroy the tree it is
|
|
1077
|
+
* putting back.
|
|
1078
|
+
*/
|
|
1079
|
+
async switchBranch(cwd, branch) {
|
|
1080
|
+
await execa2("git", ["switch", branch], { cwd });
|
|
1081
|
+
}
|
|
1073
1082
|
/**
|
|
1074
1083
|
* Push the current HEAD to `branch` on the remote. When `token` is given and
|
|
1075
1084
|
* the remote is HTTPS, it's embedded in the push URL for auth (SSH/file
|
|
@@ -2937,8 +2946,44 @@ async function applyAndOpenPr(options, deps, plan, migrations, fromVersion, toVe
|
|
|
2937
2946
|
throw new Error(`${options.cwd} is not a git repository.`);
|
|
2938
2947
|
}
|
|
2939
2948
|
const branch = upgradeBranchName(fromVersion, toVersion);
|
|
2949
|
+
const callerBranch = await git.currentBranch(options.cwd);
|
|
2940
2950
|
log.step(1, 4, `Creating branch ${branch}`);
|
|
2941
2951
|
await git.createBranch(options.cwd, branch);
|
|
2952
|
+
try {
|
|
2953
|
+
await buildCommitAndOpenPr(
|
|
2954
|
+
options,
|
|
2955
|
+
deps,
|
|
2956
|
+
plan,
|
|
2957
|
+
migrations,
|
|
2958
|
+
fromVersion,
|
|
2959
|
+
toVersion,
|
|
2960
|
+
breaking,
|
|
2961
|
+
theirsDir,
|
|
2962
|
+
coreVersionCleanup,
|
|
2963
|
+
branch,
|
|
2964
|
+
token
|
|
2965
|
+
);
|
|
2966
|
+
} finally {
|
|
2967
|
+
await restoreCallerBranch(git, options.cwd, callerBranch, branch);
|
|
2968
|
+
}
|
|
2969
|
+
}
|
|
2970
|
+
async function restoreCallerBranch(git, cwd, callerBranch, upgradeBranch) {
|
|
2971
|
+
if (callerBranch === "HEAD" || callerBranch === "") {
|
|
2972
|
+
log.warn(
|
|
2973
|
+
`Left ${cwd} on ${upgradeBranch}: HEAD was detached on entry, so there is no branch to restore (#984).`
|
|
2974
|
+
);
|
|
2975
|
+
return;
|
|
2976
|
+
}
|
|
2977
|
+
try {
|
|
2978
|
+
await git.switchBranch(cwd, callerBranch);
|
|
2979
|
+
} catch {
|
|
2980
|
+
log.warn(
|
|
2981
|
+
`Could not switch ${cwd} back to ${callerBranch} \u2014 it is still on ${upgradeBranch}. Restore it with \`git switch ${callerBranch}\` (#984).`
|
|
2982
|
+
);
|
|
2983
|
+
}
|
|
2984
|
+
}
|
|
2985
|
+
async function buildCommitAndOpenPr(options, deps, plan, migrations, fromVersion, toVersion, breaking, theirsDir, coreVersionCleanup, branch, token) {
|
|
2986
|
+
const { git } = deps;
|
|
2942
2987
|
const applied = applyUpgradePlan(options.cwd, plan, theirsDir);
|
|
2943
2988
|
const carried = applyMigrationCarry(options.cwd, migrations);
|
|
2944
2989
|
writeInstanceCoreVersion(options.cwd, toVersion);
|