next-issue 8.2.2 → 8.2.4

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 CHANGED
@@ -70,7 +70,10 @@ the run handles one issue. For each issue:
70
70
  no commits of its own starts again from the remote base. An issue with no
71
71
  saved state does not reuse a local `<n>` branch: it resets that branch,
72
72
  and any worktree that holds it, to the remote branch, or to the remote
73
- base when there is none. The main worktree of the repository is never
73
+ base when there is none. A worktree at `.worktrees/<n>` left on a
74
+ detached HEAD, for example by a crash, is removed, but its uncommitted
75
+ files are first committed on a `<n>-detached-<sha>` branch, so they are
76
+ kept. The main worktree of the repository is never
74
77
  used, reset or cleaned: when it has the branch of the issue checked out,
75
78
  the issue fails and is handed over, and the reason asks you to check out
76
79
  another branch there. A fast-forward of the base that is not safe
package/dist/git-land.mjs CHANGED
@@ -21,18 +21,23 @@ export async function pushToBase(cwd, remote, base) {
21
21
  return oneFetchAtATime(() => succeeds(cwd, ['push', remote, `HEAD:refs/heads/${base}`]));
22
22
  }
23
23
  export async function revertOnBase(cwd, revert) {
24
- const { branch } = revert;
25
- let moved = false;
26
24
  try {
27
- moved = await pushRevert(cwd, revert);
28
- return moved;
29
- }
30
- finally {
31
- if (!moved) {
32
- await succeeds(cwd, ['revert', '--abort']);
33
- await git(cwd, ['checkout', '--force', branch]);
25
+ if (await pushRevert(cwd, revert)) {
26
+ return true;
34
27
  }
35
28
  }
29
+ catch (error) {
30
+ await putBranchBack(cwd, revert.branch).catch(() => undefined);
31
+ throw error;
32
+ }
33
+ await putBranchBack(cwd, revert.branch);
34
+ return false;
35
+ }
36
+ function putBranchBack(cwd, branch) {
37
+ return evenWhenStopped(async () => {
38
+ await succeeds(cwd, ['revert', '--abort']);
39
+ await git(cwd, ['checkout', '--force', branch]);
40
+ });
36
41
  }
37
42
  export async function reapplyRevert(cwd, reapply) {
38
43
  const { base, remote, branch, reverted } = reapply;
package/dist/land.mjs CHANGED
@@ -5,7 +5,6 @@ import { PUSH_TRIES } from './git-land.mjs';
5
5
  import { localChecks } from './local-checks.mjs';
6
6
  import { escalateAndFinish, finishDone, stop } from './handover.mjs';
7
7
  import { oneAtATime } from './lock.mjs';
8
- import { revertFailedFix } from './revert.mjs';
9
8
  import { readState, savedIssues, writeState } from './state.mjs';
10
9
  import { beforeBaseSettled, blocksLanding, HALT_NOTE, releaseSettled } from './unsettled.mjs';
11
10
  export function landApproved(job) {
@@ -86,7 +85,6 @@ async function landLoop(job) {
86
85
  for (;;) {
87
86
  const pushed = await pushChange(job).catch(async (error) => {
88
87
  if (!job.repairing || runStopped()) {
89
- await revertFailedFix(job);
90
88
  throw error;
91
89
  }
92
90
  job.repairing = false;
package/dist/worktree.mjs CHANGED
@@ -1,6 +1,7 @@
1
+ import { existsSync } from 'node:fs';
1
2
  import { realpath } from 'node:fs/promises';
2
3
  import { join } from 'node:path';
3
- import { currentBranch, discardChanges, git, gitFetch, isAncestor, oneFetchAtATime, remoteRef, succeeds, } from './git.mjs';
4
+ import { currentBranch, discardChanges, git, gitFetch, isAncestor, oneFetchAtATime, remoteRef, revision, saveEdits, succeeds, } from './git.mjs';
4
5
  export const WORKTREE_DIR = '.worktrees';
5
6
  export function huntPath(repo) {
6
7
  return join(repo.root, WORKTREE_DIR, 'hunt');
@@ -20,6 +21,7 @@ export async function addWorktree(repo, issue, branch, base, remote, start) {
20
21
  const path = existing ?? worktreePath(repo, issue);
21
22
  const target = pushed ? upstream : remoteBase;
22
23
  if (existing === undefined) {
24
+ await keepDetachedEdits(path, branch);
23
25
  await succeeds(repo.root, ['worktree', 'remove', '--force', path]);
24
26
  const args = !start && (await hasWork(repo, branch, pushed, remoteBase))
25
27
  ? ['worktree', 'add', path, branch]
@@ -34,6 +36,14 @@ export async function addWorktree(repo, issue, branch, base, remote, start) {
34
36
  }
35
37
  return { path, baseUpdated };
36
38
  }
39
+ async function keepDetachedEdits(path, branch) {
40
+ if (!existsSync(join(path, '.git')) ||
41
+ (await currentBranch(path)) !== undefined ||
42
+ !(await saveEdits(path, 'chore: edits left on a detached HEAD'))) {
43
+ return;
44
+ }
45
+ await git(path, ['branch', `${branch}-detached-${(await revision(path)).slice(0, 7)}`]);
46
+ }
37
47
  async function hasWork(repo, branch, pushed, base) {
38
48
  if (!(await hasBranch(repo, branch))) {
39
49
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-issue",
3
- "version": "8.2.2",
3
+ "version": "8.2.4",
4
4
  "description": "Autonomous issue harness driven by the pi SDK",
5
5
  "keywords": [
6
6
  "github",