@ricsam/r5d-worker 0.0.62 → 0.0.63

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/cjs/main.cjs CHANGED
@@ -1032,6 +1032,19 @@ function checkoutVisibleBranch(input) {
1032
1032
  }
1033
1033
  runGit(["checkout", "--no-recurse-submodules", "-B", input.branchName], { cwd: input.branchPath });
1034
1034
  }
1035
+ function reconcileRewrittenCanonicalHistory(input) {
1036
+ const remoteRef = `refs/remotes/origin/${input.branchName}`;
1037
+ if (!tryGit(["rev-parse", "--verify", "HEAD"], { cwd: input.branchPath })) return;
1038
+ if (!tryGit(["show-ref", "--verify", "--quiet", remoteRef], { cwd: input.branchPath })) return;
1039
+ if (tryGit(["merge-base", "HEAD", remoteRef], { cwd: input.branchPath })) return;
1040
+ if (hasWorktreeChanges(input.branchPath)) return;
1041
+ const localTree = runGit(["rev-parse", "HEAD^{tree}"], { cwd: input.branchPath });
1042
+ const remoteTree = runGit(["rev-parse", `${remoteRef}^{tree}`], { cwd: input.branchPath });
1043
+ if (localTree !== remoteTree) return;
1044
+ const previousHead = runGit(["rev-parse", "HEAD"], { cwd: input.branchPath });
1045
+ runGit(["update-ref", `refs/r5d/pre-canonical-checkout/${previousHead}`, previousHead], { cwd: input.branchPath });
1046
+ runGit(["checkout", "--no-recurse-submodules", "-B", input.branchName, remoteRef], { cwd: input.branchPath });
1047
+ }
1035
1048
  function migrateExistingCheckoutToRequiredRemote(input) {
1036
1049
  if (originRemoteUrl(input.branchPath) === input.remoteUrl) return;
1037
1050
  const dirtyWorkingTree = hasWorktreeChanges(input.branchPath);
@@ -1139,6 +1152,9 @@ function ensureVisibleGitCheckout(input) {
1139
1152
  if (input.requireRemoteBranch && !tryGit(["show-ref", "--verify", "--quiet", `refs/remotes/origin/${input.branchName}`], { cwd: branchPath })) {
1140
1153
  throw new Error(`Existing checkout for ${input.branchName} does not contain its canonical remote branch`);
1141
1154
  }
1155
+ if (input.requireRemoteBranch) {
1156
+ reconcileRewrittenCanonicalHistory({ branchPath, branchName: input.branchName });
1157
+ }
1142
1158
  if (input.requiredBaseCommit) {
1143
1159
  assertCheckoutDerivedFromRequiredBase({
1144
1160
  branchPath,
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@ricsam/r5d-worker",
3
- "version": "0.0.62",
3
+ "version": "0.0.63",
4
4
  "type": "commonjs"
5
5
  }
package/dist/mjs/main.mjs CHANGED
@@ -1003,6 +1003,19 @@ function checkoutVisibleBranch(input) {
1003
1003
  }
1004
1004
  runGit(["checkout", "--no-recurse-submodules", "-B", input.branchName], { cwd: input.branchPath });
1005
1005
  }
1006
+ function reconcileRewrittenCanonicalHistory(input) {
1007
+ const remoteRef = `refs/remotes/origin/${input.branchName}`;
1008
+ if (!tryGit(["rev-parse", "--verify", "HEAD"], { cwd: input.branchPath })) return;
1009
+ if (!tryGit(["show-ref", "--verify", "--quiet", remoteRef], { cwd: input.branchPath })) return;
1010
+ if (tryGit(["merge-base", "HEAD", remoteRef], { cwd: input.branchPath })) return;
1011
+ if (hasWorktreeChanges(input.branchPath)) return;
1012
+ const localTree = runGit(["rev-parse", "HEAD^{tree}"], { cwd: input.branchPath });
1013
+ const remoteTree = runGit(["rev-parse", `${remoteRef}^{tree}`], { cwd: input.branchPath });
1014
+ if (localTree !== remoteTree) return;
1015
+ const previousHead = runGit(["rev-parse", "HEAD"], { cwd: input.branchPath });
1016
+ runGit(["update-ref", `refs/r5d/pre-canonical-checkout/${previousHead}`, previousHead], { cwd: input.branchPath });
1017
+ runGit(["checkout", "--no-recurse-submodules", "-B", input.branchName, remoteRef], { cwd: input.branchPath });
1018
+ }
1006
1019
  function migrateExistingCheckoutToRequiredRemote(input) {
1007
1020
  if (originRemoteUrl(input.branchPath) === input.remoteUrl) return;
1008
1021
  const dirtyWorkingTree = hasWorktreeChanges(input.branchPath);
@@ -1110,6 +1123,9 @@ function ensureVisibleGitCheckout(input) {
1110
1123
  if (input.requireRemoteBranch && !tryGit(["show-ref", "--verify", "--quiet", `refs/remotes/origin/${input.branchName}`], { cwd: branchPath })) {
1111
1124
  throw new Error(`Existing checkout for ${input.branchName} does not contain its canonical remote branch`);
1112
1125
  }
1126
+ if (input.requireRemoteBranch) {
1127
+ reconcileRewrittenCanonicalHistory({ branchPath, branchName: input.branchName });
1128
+ }
1113
1129
  if (input.requiredBaseCommit) {
1114
1130
  assertCheckoutDerivedFromRequiredBase({
1115
1131
  branchPath,
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@ricsam/r5d-worker",
3
- "version": "0.0.62",
3
+ "version": "0.0.63",
4
4
  "type": "module"
5
5
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ricsam/r5d-worker",
3
- "version": "0.0.62",
3
+ "version": "0.0.63",
4
4
  "type": "module",
5
5
  "main": "./dist/cjs/main.cjs",
6
6
  "module": "./dist/mjs/main.mjs",