@ygrishajev/jig 1.0.3 → 1.0.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/dist/{git → adapters/git}/branch.js +3 -6
- package/dist/adapters/git/git-workspace.js +3 -11
- package/dist/{git → adapters/git}/merge.js +2 -2
- package/dist/{git → adapters/git}/repository.js +18 -1
- package/dist/adapters/run-store/git-remote-run-store.js +18 -17
- package/dist/adapters/sandcastle/private-clone-docker.js +1 -1
- package/dist/app/run-jig.js +1 -1
- package/dist/app/throwaway-sandbox.js +2 -2
- package/dist/cli/with-app.js +1 -1
- package/package.json +1 -1
- /package/dist/{git → adapters/git}/throwaway-branch.js +0 -0
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import { Result } from 'better-result';
|
|
2
|
-
import { ConfigInvalid } from '
|
|
2
|
+
import { ConfigInvalid } from '../../domain/errors.js';
|
|
3
3
|
import { gitCommand, openRepo } from './repository.js';
|
|
4
4
|
export async function getCurrentBranch(cwd) {
|
|
5
5
|
const status = await gitCommand('status', () => openRepo(cwd).status());
|
|
6
|
-
if (status.isErr())
|
|
7
|
-
return
|
|
8
|
-
message: `Cannot tell which branch is checked out in ${cwd}: ${status.error.output}`,
|
|
9
|
-
}));
|
|
10
|
-
}
|
|
6
|
+
if (status.isErr())
|
|
7
|
+
return status;
|
|
11
8
|
if (!status.value.current || status.value.detached) {
|
|
12
9
|
return Result.err(new ConfigInvalid({
|
|
13
10
|
message: `${cwd} has no branch checked out — check out the branch the run should start from.`,
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { Result } from 'better-result';
|
|
2
|
-
import { execa } from 'execa';
|
|
3
2
|
import { mkdtemp, readFile, rm } from 'node:fs/promises';
|
|
4
3
|
import { tmpdir } from 'node:os';
|
|
5
4
|
import path from 'node:path';
|
|
6
5
|
import { CommitImportRefused, CommitRejected, GitCommandFailed, LocalStateUnwritable, MergeFailed, messageOf, } from '../../domain/errors.js';
|
|
7
6
|
import { runBranchFor } from '../../domain/run-state.js';
|
|
8
|
-
import { isBranchMergedInto, mergeBranchInto } from '
|
|
9
|
-
import { gitCommand, isWorkingTreeClean, openRepo, openRepoWithoutHooks, } from '
|
|
7
|
+
import { isBranchMergedInto, mergeBranchInto } from './merge.js';
|
|
8
|
+
import { gitCommand, isAncestor, isWorkingTreeClean, openRepo, openRepoWithoutHooks, } from './repository.js';
|
|
10
9
|
export class GitWorkspace {
|
|
11
10
|
options;
|
|
12
11
|
runBranch;
|
|
@@ -69,7 +68,7 @@ export class GitWorkspace {
|
|
|
69
68
|
message: `The sandbox reported ${head} as its head, but its bundle holds ${fetched}.`,
|
|
70
69
|
}));
|
|
71
70
|
}
|
|
72
|
-
if (!(await
|
|
71
|
+
if (!(yield* Result.await(isAncestor(this.options.repoRoot, approved, fetched)))) {
|
|
73
72
|
return Result.err(new CommitImportRefused({
|
|
74
73
|
message: `The sandbox rewrote approved commit ${approved}, so its work was not taken.`,
|
|
75
74
|
}));
|
|
@@ -114,13 +113,6 @@ export class GitWorkspace {
|
|
|
114
113
|
}
|
|
115
114
|
}, this);
|
|
116
115
|
}
|
|
117
|
-
async descendsFrom(commit, ancestor) {
|
|
118
|
-
const { exitCode } = await execa('git', ['merge-base', '--is-ancestor', ancestor, commit], {
|
|
119
|
-
cwd: this.options.repoRoot,
|
|
120
|
-
reject: false,
|
|
121
|
-
});
|
|
122
|
-
return exitCode === 0;
|
|
123
|
-
}
|
|
124
116
|
headCommit() {
|
|
125
117
|
return gitCommand('rev-parse', async () => (await openRepo(this.options.repoRoot).revparse([this.runBranch])).trim());
|
|
126
118
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Result } from 'better-result';
|
|
2
2
|
import { execa } from 'execa';
|
|
3
|
-
import { GitCommandFailed, MergeFailed, messageOf, RemoteUnavailable } from '
|
|
3
|
+
import { GitCommandFailed, MergeFailed, messageOf, RemoteUnavailable, } from '../../domain/errors.js';
|
|
4
4
|
import { getCurrentBranch } from './branch.js';
|
|
5
5
|
import { gitCommand, isWorkingTreeClean, openRepoWithoutHooks } from './repository.js';
|
|
6
6
|
/**
|
|
@@ -88,5 +88,5 @@ export async function mergeBranchInto(repoRoot, branchName, intoBranch, { sign =
|
|
|
88
88
|
});
|
|
89
89
|
}
|
|
90
90
|
function asMergeFailed(error) {
|
|
91
|
-
return new MergeFailed({ message: error.message });
|
|
91
|
+
return GitCommandFailed.is(error) ? error : new MergeFailed({ message: error.message });
|
|
92
92
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Result } from 'better-result';
|
|
2
|
+
import { execa } from 'execa';
|
|
2
3
|
import { realpath } from 'node:fs/promises';
|
|
3
4
|
import { simpleGit } from 'simple-git';
|
|
4
|
-
import { ConfigInvalid, GitCommandFailed, messageOf } from '
|
|
5
|
+
import { ConfigInvalid, GitCommandFailed, messageOf } from '../../domain/errors.js';
|
|
5
6
|
/**
|
|
6
7
|
* For a merge on the host: a hook can run what the branch just brought in, before anyone read it,
|
|
7
8
|
* whether a tracked `post-merge` script or an install that runs a new `postinstall`. simple-git
|
|
@@ -46,3 +47,19 @@ export async function ensureRepositoryRoot(cwd) {
|
|
|
46
47
|
message: `Run jig from the repository's root, ${root} — not from ${cwd}.`,
|
|
47
48
|
}));
|
|
48
49
|
}
|
|
50
|
+
export function isAncestor(cwd, ancestor, descendant) {
|
|
51
|
+
const args = ['merge-base', '--is-ancestor', ancestor, descendant];
|
|
52
|
+
const command = `git ${args.join(' ')}`;
|
|
53
|
+
const failure = (output) => new GitCommandFailed({ message: `${command} failed: ${output}`, command, output });
|
|
54
|
+
return Result.gen(async function* () {
|
|
55
|
+
const checked = yield* Result.await(Result.tryPromise({
|
|
56
|
+
try: () => execa('git', args, { cwd, reject: false }),
|
|
57
|
+
catch: (cause) => failure(messageOf(cause)),
|
|
58
|
+
}));
|
|
59
|
+
if (checked.exitCode === 0)
|
|
60
|
+
return Result.ok(true);
|
|
61
|
+
if (checked.exitCode === 1)
|
|
62
|
+
return Result.ok(false);
|
|
63
|
+
return Result.err(failure(checked.stderr));
|
|
64
|
+
});
|
|
65
|
+
}
|
|
@@ -3,6 +3,7 @@ import { execa } from 'execa';
|
|
|
3
3
|
import { ConfigInvalid, GitCommandFailed, messageOf, RemoteUnavailable, RunStateConflict, } from '../../domain/errors.js';
|
|
4
4
|
import { retryResult } from '../../domain/retry.js';
|
|
5
5
|
import { runBranchFor, runStateSchema } from '../../domain/run-state.js';
|
|
6
|
+
import { isAncestor } from '../git/repository.js';
|
|
6
7
|
/**
|
|
7
8
|
* Keeps each run's state as a commit on a hidden `refs/jig/<runId>` ref and pushes it, with the
|
|
8
9
|
* run branch, to a remote — so another machine, such as a retried CI job, can resume the run.
|
|
@@ -102,19 +103,23 @@ export class GitRemoteRunStore {
|
|
|
102
103
|
* Moves the local run branch to the remote's when it is behind, keeps it when it is ahead with
|
|
103
104
|
* commits not pushed yet, and refuses when the two have diverged.
|
|
104
105
|
*/
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
106
|
+
catchUpRunBranch(runId, remoteHead) {
|
|
107
|
+
return Result.gen(async function* () {
|
|
108
|
+
const local = await this.revision(branchRef(runId));
|
|
109
|
+
if (!local) {
|
|
110
|
+
return (await this.required(['update-ref', branchRef(runId), remoteHead, ''])).map(() => undefined);
|
|
111
|
+
}
|
|
112
|
+
const remoteIsAncestor = yield* Result.await(isAncestor(this.repoRoot, remoteHead, local));
|
|
113
|
+
if (remoteIsAncestor)
|
|
114
|
+
return Result.ok();
|
|
115
|
+
const localIsAncestor = yield* Result.await(isAncestor(this.repoRoot, local, remoteHead));
|
|
116
|
+
if (!localIsAncestor) {
|
|
117
|
+
return Result.err(new RunStateConflict({
|
|
118
|
+
message: `The run branch "${runBranchFor(runId)}" here and on ${this.remote} have diverged.`,
|
|
119
|
+
}));
|
|
120
|
+
}
|
|
121
|
+
return this.fastForward(runId, local, remoteHead);
|
|
122
|
+
}, this);
|
|
118
123
|
}
|
|
119
124
|
async required(args, input) {
|
|
120
125
|
const result = await this.git(args, input);
|
|
@@ -126,10 +131,6 @@ export class GitRemoteRunStore {
|
|
|
126
131
|
output: result.stderr,
|
|
127
132
|
}));
|
|
128
133
|
}
|
|
129
|
-
async isAncestor(ancestor, descendant) {
|
|
130
|
-
const checked = await this.git(['merge-base', '--is-ancestor', ancestor, descendant]);
|
|
131
|
-
return checked.exitCode === 0;
|
|
132
|
-
}
|
|
133
134
|
/** Git refuses to move a branch a worktree has checked out, so that worktree is moved instead. */
|
|
134
135
|
async fastForward(runId, from, to) {
|
|
135
136
|
const worktree = await this.worktreeWithCheckedOut(branchRef(runId));
|
|
@@ -9,7 +9,7 @@ import path from 'node:path';
|
|
|
9
9
|
import { Transform } from 'node:stream';
|
|
10
10
|
import { pipeline } from 'node:stream/promises';
|
|
11
11
|
import { GitCommandFailed, messageOf } from '../../domain/errors.js';
|
|
12
|
-
import { openRepo } from '
|
|
12
|
+
import { openRepo } from '../git/repository.js';
|
|
13
13
|
/**
|
|
14
14
|
* A docker sandbox that shares nothing of the repository with the host. Sandcastle offers the
|
|
15
15
|
* worktree and `.git` as mounts and they are ignored: the container gets its own clone of the run
|
package/dist/app/run-jig.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Result } from 'better-result';
|
|
2
|
+
import { getCurrentBranch } from '../adapters/git/branch.js';
|
|
2
3
|
import { MetricsLog } from '../adapters/local-store/metrics-log.js';
|
|
3
4
|
import { lockRun } from '../adapters/local-store/run-lock.js';
|
|
4
5
|
import { stepCredentials } from '../adapters/sandcastle/open-session.js';
|
|
@@ -10,7 +11,6 @@ import { startRun } from '../domain/run-state.js';
|
|
|
10
11
|
import { finalStatus } from '../flow/define-flow.js';
|
|
11
12
|
import { runEngine } from '../flow/engine.js';
|
|
12
13
|
import { runFlow } from '../flow/run-flow.js';
|
|
13
|
-
import { getCurrentBranch } from '../git/branch.js';
|
|
14
14
|
import { withRunScope } from './container.js';
|
|
15
15
|
import { openRunStore } from './run-stores.js';
|
|
16
16
|
import { ensureSandboxImage } from './sandbox-image.js';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Result } from 'better-result';
|
|
2
2
|
import { randomBytes } from 'node:crypto';
|
|
3
|
+
import { getCurrentBranch } from '../adapters/git/branch.js';
|
|
4
|
+
import { discardBranch, discardBranchOnExit } from '../adapters/git/throwaway-branch.js';
|
|
3
5
|
import { runIdSchema } from '../domain/run-id.js';
|
|
4
6
|
import { runBranchFor } from '../domain/run-state.js';
|
|
5
|
-
import { getCurrentBranch } from '../git/branch.js';
|
|
6
|
-
import { discardBranch, discardBranchOnExit } from '../git/throwaway-branch.js';
|
|
7
7
|
import { LoggingObserver } from '../observers/logging-observer.js';
|
|
8
8
|
import { observedEvents } from './observed-events.js';
|
|
9
9
|
import { reportCleanup } from './report-cleanup.js';
|
package/dist/cli/with-app.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Result } from 'better-result';
|
|
2
|
+
import { ensureRepositoryRoot } from '../adapters/git/repository.js';
|
|
2
3
|
import { readCredentialsFile } from '../adapters/local-store/credentials-file.js';
|
|
3
4
|
import { askForPreset } from '../adapters/terminal/ask-for-preset.js';
|
|
4
5
|
import { processStandardInput } from '../adapters/terminal/standard-input.js';
|
|
@@ -7,7 +8,6 @@ import { parseEnvironment, withCredentials } from '../config/environment.js';
|
|
|
7
8
|
import { configFileFor, loadConfig } from '../config/load-config.js';
|
|
8
9
|
import { configWithPreset, discoverPresets, } from '../config/presets.js';
|
|
9
10
|
import { ConfigInvalid } from '../domain/errors.js';
|
|
10
|
-
import { ensureRepositoryRoot } from '../git/repository.js';
|
|
11
11
|
/** Runs a command against the repository in the working directory, then releases what it opened. */
|
|
12
12
|
export async function withApp(options, command, invocation = processInvocation()) {
|
|
13
13
|
const app = await openApp(options, invocation);
|
package/package.json
CHANGED
|
File without changes
|