next-issue 2.21.1 → 3.0.0
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 +89 -124
- package/dist/agent-reply.mjs +13 -0
- package/dist/agent-session.mjs +56 -0
- package/dist/agents.mjs +47 -88
- package/dist/args.mjs +26 -31
- package/dist/base-checks.mjs +37 -0
- package/dist/budget.mjs +16 -0
- package/dist/check-poll.mjs +73 -0
- package/dist/checks.mjs +67 -0
- package/dist/children.mjs +52 -0
- package/dist/cli.mjs +25 -15
- package/dist/command-records.mjs +15 -0
- package/dist/config-fields.mjs +32 -0
- package/dist/config.mjs +36 -71
- package/dist/conflict.mjs +43 -42
- package/dist/durations.mjs +37 -0
- package/dist/enter-review.mjs +13 -0
- package/dist/errors.mjs +20 -0
- package/dist/exec.mjs +71 -107
- package/dist/files.mjs +28 -0
- package/dist/fix.mjs +61 -50
- package/dist/gate.mjs +31 -43
- package/dist/gh.mjs +55 -0
- package/dist/git-commit.mjs +36 -0
- package/dist/git-land.mjs +30 -0
- package/dist/git-merge.mjs +42 -0
- package/dist/git.mjs +42 -166
- package/dist/github.mjs +32 -386
- package/dist/gitignore.mjs +13 -0
- package/dist/hand-over-comments.mjs +81 -0
- package/dist/handover.mjs +62 -103
- package/dist/implement.mjs +32 -0
- package/dist/interrupt.mjs +6 -19
- package/dist/job.mjs +28 -17
- package/dist/labels.mjs +65 -0
- package/dist/land.mjs +66 -0
- package/dist/lock.mjs +54 -0
- package/dist/logs.mjs +84 -62
- package/dist/loop.mjs +12 -37
- package/dist/observe.mjs +24 -98
- package/dist/open-job.mjs +39 -0
- package/dist/pending.mjs +46 -0
- package/dist/pipeline.mjs +34 -217
- package/dist/poll.mjs +20 -0
- package/dist/ports.mjs +18 -3
- package/dist/progress.mjs +36 -22
- package/dist/prompts.mjs +31 -36
- package/dist/protocol.mjs +17 -11
- package/dist/prune-runs.mjs +33 -0
- package/dist/pull-requests.mjs +60 -0
- package/dist/questions.mjs +45 -0
- package/dist/records.mjs +3 -0
- package/dist/render.mjs +19 -0
- package/dist/revert.mjs +27 -0
- package/dist/review.mjs +63 -83
- package/dist/run-logs.mjs +23 -0
- package/dist/run.mjs +59 -58
- package/dist/serve.mjs +46 -214
- package/dist/setup.mjs +2 -5
- package/dist/skip.mjs +54 -0
- package/dist/state.mjs +27 -39
- package/dist/summary.mjs +11 -7
- package/dist/text.mjs +15 -0
- package/dist/usage.mjs +45 -0
- package/dist/verdict.mjs +20 -13
- package/dist/watch.mjs +38 -0
- package/dist/worker-paths.mjs +16 -0
- package/dist/worker-run.mjs +56 -0
- package/dist/worker-server.mjs +56 -0
- package/dist/worktree-setup.mjs +25 -0
- package/dist/worktree.mjs +58 -0
- package/package.json +1 -1
- package/dist/merge.mjs +0 -75
package/dist/gh.mjs
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
2
|
+
import { secondsToMs } from './durations.mjs';
|
|
3
|
+
import { errorMatches } from './errors.mjs';
|
|
4
|
+
import { must, optionalFlag, run, succeeded } from './exec.mjs';
|
|
5
|
+
const NETWORK_TRIES = 3;
|
|
6
|
+
const NETWORK_FAULT = /unexpected EOF|connection reset|connection refused|i\/o timeout|TLS handshake timeout|HTTP 50[234]/i;
|
|
7
|
+
export function slug(repo) {
|
|
8
|
+
return `${repo.owner}/${repo.name}`;
|
|
9
|
+
}
|
|
10
|
+
export async function repeatable(repo, args) {
|
|
11
|
+
for (let attempt = 1;; attempt += 1) {
|
|
12
|
+
try {
|
|
13
|
+
return await must('gh', args, { cwd: repo.root });
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
if (attempt >= NETWORK_TRIES || !errorMatches(error, NETWORK_FAULT)) {
|
|
17
|
+
throw error;
|
|
18
|
+
}
|
|
19
|
+
await delay(secondsToMs(attempt));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function withRepo(repo, args) {
|
|
24
|
+
return [...args, '--repo', slug(repo)];
|
|
25
|
+
}
|
|
26
|
+
export async function gh(repo, args) {
|
|
27
|
+
return repeatable(repo, withRepo(repo, args));
|
|
28
|
+
}
|
|
29
|
+
export async function ghJson(repo, args) {
|
|
30
|
+
return JSON.parse(await gh(repo, args));
|
|
31
|
+
}
|
|
32
|
+
export async function viewJson(repo, kind, number, fields) {
|
|
33
|
+
return ghJson(repo, [kind, 'view', String(number), '--json', fields]);
|
|
34
|
+
}
|
|
35
|
+
export async function ghOnce(repo, args, input) {
|
|
36
|
+
return must('gh', withRepo(repo, args), { cwd: repo.root, input });
|
|
37
|
+
}
|
|
38
|
+
export async function ghRun(repo, args, options = {}) {
|
|
39
|
+
return run('gh', withRepo(repo, args), { ...options, cwd: repo.root });
|
|
40
|
+
}
|
|
41
|
+
export async function ghApi(repo, path, jq, { paginate = false } = {}) {
|
|
42
|
+
return repeatable(repo, [
|
|
43
|
+
'api',
|
|
44
|
+
...optionalFlag(paginate, '--paginate'),
|
|
45
|
+
`repos/${slug(repo)}/${path}`,
|
|
46
|
+
'--jq',
|
|
47
|
+
jq,
|
|
48
|
+
]);
|
|
49
|
+
}
|
|
50
|
+
export async function ghSucceeds(repo, args) {
|
|
51
|
+
return succeeded(await ghRun(repo, args));
|
|
52
|
+
}
|
|
53
|
+
export function names(items) {
|
|
54
|
+
return items.map((item) => item.name);
|
|
55
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { mkdtemp, rm, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { message } from './errors.mjs';
|
|
5
|
+
import { git, isDirty } from './git.mjs';
|
|
6
|
+
export class HookError extends Error {
|
|
7
|
+
}
|
|
8
|
+
export async function commitAll(cwd, commitMessage) {
|
|
9
|
+
if (!(await isDirty(cwd))) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
await commitEverything(cwd, commitMessage);
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
export async function commitEverything(cwd, commitMessage) {
|
|
16
|
+
await git(cwd, ['add', '-A']);
|
|
17
|
+
const folder = await mkdtemp(join(tmpdir(), 'next-issue-message-'));
|
|
18
|
+
const file = join(folder, 'COMMIT_EDITMSG');
|
|
19
|
+
try {
|
|
20
|
+
await writeFile(file, `${commitMessage}\n`);
|
|
21
|
+
await runHook(cwd, 'pre-commit');
|
|
22
|
+
await runHook(cwd, 'commit-msg', file);
|
|
23
|
+
await git(cwd, ['commit', '--no-verify', '-F', file]);
|
|
24
|
+
}
|
|
25
|
+
finally {
|
|
26
|
+
await rm(folder, { recursive: true, force: true });
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
async function runHook(cwd, name, ...args) {
|
|
30
|
+
try {
|
|
31
|
+
await git(cwd, ['hook', 'run', '--ignore-missing', name, '--', ...args]);
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
throw new HookError(message(error));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { fetchBase, git, remoteRef, revision, succeeds } from './git.mjs';
|
|
2
|
+
import { commitEverything } from './git-commit.mjs';
|
|
3
|
+
export async function squashOnto(cwd, base, remote, message) {
|
|
4
|
+
const target = remoteRef(remote, base);
|
|
5
|
+
if (await succeeds(cwd, ['diff', '--quiet', target])) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
await git(cwd, ['reset', '--soft', target]);
|
|
9
|
+
await commitEverything(cwd, message);
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
export async function pushToBase(cwd, remote, base) {
|
|
13
|
+
return succeeds(cwd, ['push', remote, `HEAD:refs/heads/${base}`]);
|
|
14
|
+
}
|
|
15
|
+
export async function revertOnBase(cwd, revert) {
|
|
16
|
+
const { base, remote, branch, shas, message, reapply } = revert;
|
|
17
|
+
const target = await fetchBase(cwd, base, remote);
|
|
18
|
+
await git(cwd, ['checkout', '--force', '--detach', target]);
|
|
19
|
+
await git(cwd, ['clean', '-fd']);
|
|
20
|
+
await git(cwd, ['revert', '--no-commit', ...shas.toReversed()]);
|
|
21
|
+
await git(cwd, ['commit', '--no-verify', '-m', message]);
|
|
22
|
+
if (!(await pushToBase(cwd, remote, base))) {
|
|
23
|
+
await git(cwd, ['checkout', '--force', branch]);
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
await git(cwd, ['revert', '--no-commit', await revision(cwd)]);
|
|
27
|
+
await git(cwd, ['commit', '--no-verify', '-m', reapply]);
|
|
28
|
+
await git(cwd, ['checkout', '-B', branch]);
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { run, succeeded } from './exec.mjs';
|
|
3
|
+
import { readTextOrEmpty } from './files.mjs';
|
|
4
|
+
import { commitEverything } from './git-commit.mjs';
|
|
5
|
+
import { fetchBase, git, resetHard, succeeds } from './git.mjs';
|
|
6
|
+
import { lines } from './text.mjs';
|
|
7
|
+
export async function startMerge(cwd, base, remote) {
|
|
8
|
+
const target = await fetchBase(cwd, base, remote);
|
|
9
|
+
const result = await run('git', ['merge', '--no-ff', '--no-commit', target], { cwd });
|
|
10
|
+
if (succeeded(result)) {
|
|
11
|
+
return (await merging(cwd)) ? [] : undefined;
|
|
12
|
+
}
|
|
13
|
+
const listed = await git(cwd, ['diff', '--name-only', '--diff-filter=U']);
|
|
14
|
+
const files = lines(listed);
|
|
15
|
+
if (files.length === 0) {
|
|
16
|
+
throw new Error(`git merge ${target} failed: ${result.stderr.trim()}`);
|
|
17
|
+
}
|
|
18
|
+
return files;
|
|
19
|
+
}
|
|
20
|
+
async function merging(cwd) {
|
|
21
|
+
return succeeds(cwd, ['rev-parse', '--quiet', '--verify', 'MERGE_HEAD']);
|
|
22
|
+
}
|
|
23
|
+
const CONFLICT_MARKER = /^(?:<{7}|>{7})(?: |$)/m;
|
|
24
|
+
export async function commitMerge(cwd, files, message) {
|
|
25
|
+
if (!(await merging(cwd)) || (await hasConflictMarkers(cwd, files))) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
await commitEverything(cwd, message);
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
async function hasConflictMarkers(cwd, files) {
|
|
32
|
+
for (const file of files) {
|
|
33
|
+
const text = await readTextOrEmpty(join(cwd, file));
|
|
34
|
+
if (CONFLICT_MARKER.test(text)) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
export async function abortMerge(cwd, target) {
|
|
41
|
+
await resetHard(cwd, target);
|
|
42
|
+
}
|
package/dist/git.mjs
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { join } from 'node:path';
|
|
4
|
-
import { must, run } from './exec.mjs';
|
|
1
|
+
import { must, optionalFlag, run, succeeded } from './exec.mjs';
|
|
2
|
+
import { lines } from './text.mjs';
|
|
5
3
|
const REMOTE_PATTERNS = [
|
|
6
4
|
/^git@[^:]+:(?<owner>[^/]+)\/(?<name>[^/]+?)(?:\.git)?$/,
|
|
7
5
|
/^ssh:\/\/[^/]+\/(?<owner>[^/]+)\/(?<name>[^/]+?)(?:\.git)?$/,
|
|
@@ -17,207 +15,85 @@ export function parseRemote(url) {
|
|
|
17
15
|
throw new Error(`Cannot parse the git remote URL: ${url}`);
|
|
18
16
|
}
|
|
19
17
|
export async function repoRoot(cwd) {
|
|
20
|
-
return
|
|
18
|
+
return git(cwd, ['rev-parse', '--show-toplevel']);
|
|
21
19
|
}
|
|
22
20
|
export async function detectRepo(cwd, remote) {
|
|
23
21
|
const root = await repoRoot(cwd);
|
|
24
|
-
const url = await
|
|
22
|
+
const url = await git(cwd, ['remote', 'get-url', remote]);
|
|
25
23
|
const { owner, name } = parseRemote(url);
|
|
26
24
|
return { owner, name, root };
|
|
27
25
|
}
|
|
28
|
-
export
|
|
29
|
-
|
|
30
|
-
return join(repo.root, WORKTREE_DIR, String(issue));
|
|
31
|
-
}
|
|
32
|
-
export async function addWorktree(repo, issue, branch, base, remote, start) {
|
|
33
|
-
const upstream = `${remote}/${branch}`;
|
|
34
|
-
await must('git', ['fetch', remote], { cwd: repo.root });
|
|
35
|
-
const baseUpdated = await updateBase(repo, base, remote);
|
|
36
|
-
await must('git', ['worktree', 'prune'], { cwd: repo.root });
|
|
37
|
-
const pushed = await hasBranch(repo, upstream, '--remotes');
|
|
38
|
-
const existing = await findWorktree(repo, branch);
|
|
39
|
-
const path = existing ?? worktreePath(repo, issue);
|
|
40
|
-
const target = pushed ? upstream : `${remote}/${base}`;
|
|
41
|
-
if (existing === undefined) {
|
|
42
|
-
const args = !start && (await hasWork(repo, branch, pushed, `${remote}/${base}`))
|
|
43
|
-
? ['worktree', 'add', path, branch]
|
|
44
|
-
: ['worktree', 'add', '-B', branch, path, target];
|
|
45
|
-
await must('git', args, { cwd: repo.root });
|
|
46
|
-
}
|
|
47
|
-
else if (start) {
|
|
48
|
-
await discardChanges(path, target);
|
|
49
|
-
}
|
|
50
|
-
if (pushed) {
|
|
51
|
-
await run('git', ['merge', '--ff-only', upstream], { cwd: path });
|
|
52
|
-
}
|
|
53
|
-
return { path, baseUpdated };
|
|
54
|
-
}
|
|
55
|
-
async function hasWork(repo, branch, pushed, base) {
|
|
56
|
-
if (!(await hasBranch(repo, branch))) {
|
|
57
|
-
return false;
|
|
58
|
-
}
|
|
59
|
-
return pushed || !(await isAncestor(repo.root, branch, base));
|
|
60
|
-
}
|
|
61
|
-
async function hasBranch(repo, name, ...flags) {
|
|
62
|
-
const list = await must('git', ['branch', '--list', ...flags, name], { cwd: repo.root });
|
|
63
|
-
return list.length > 0;
|
|
64
|
-
}
|
|
65
|
-
export async function updateBase(repo, base, remote) {
|
|
66
|
-
const head = await run('git', ['symbolic-ref', '--quiet', '--short', 'HEAD'], { cwd: repo.root });
|
|
67
|
-
const args = head.code === 0 && head.stdout.trim() === base
|
|
68
|
-
? ['merge', '--ff-only', `${remote}/${base}`]
|
|
69
|
-
: ['fetch', '.', `${remote}/${base}:${base}`];
|
|
70
|
-
const result = await run('git', args, { cwd: repo.root });
|
|
71
|
-
return result.code === 0;
|
|
72
|
-
}
|
|
73
|
-
export async function findWorktree(repo, branch) {
|
|
74
|
-
const list = await must('git', ['worktree', 'list', '--porcelain'], { cwd: repo.root });
|
|
75
|
-
const entry = list
|
|
76
|
-
.split('\n\n')
|
|
77
|
-
.map((block) => block.split('\n'))
|
|
78
|
-
.find((lines) => lines.includes(`branch refs/heads/${branch}`));
|
|
79
|
-
return entry?.find((line) => line.startsWith('worktree '))?.slice('worktree '.length);
|
|
80
|
-
}
|
|
81
|
-
export async function removeWorktree(repo, path) {
|
|
82
|
-
const result = await run('git', ['worktree', 'remove', path], { cwd: repo.root });
|
|
83
|
-
return result.code === 0;
|
|
84
|
-
}
|
|
85
|
-
export async function ensureIgnored(root, entry) {
|
|
86
|
-
const path = join(root, '.gitignore');
|
|
87
|
-
let current = '';
|
|
88
|
-
try {
|
|
89
|
-
current = await readFile(path, 'utf8');
|
|
90
|
-
}
|
|
91
|
-
catch {
|
|
92
|
-
current = '';
|
|
93
|
-
}
|
|
94
|
-
if (current.split('\n').some((line) => line.trim() === entry)) {
|
|
95
|
-
return false;
|
|
96
|
-
}
|
|
97
|
-
const gap = current.length === 0 || current.endsWith('\n') ? '' : '\n';
|
|
98
|
-
await appendFile(path, `${gap}${entry}\n`);
|
|
99
|
-
return true;
|
|
26
|
+
export function remoteRef(remote, branch) {
|
|
27
|
+
return `${remote}/${branch}`;
|
|
100
28
|
}
|
|
101
29
|
export function branchName(issue) {
|
|
102
30
|
return String(issue);
|
|
103
31
|
}
|
|
104
32
|
export async function isDirty(cwd) {
|
|
105
|
-
const status = await
|
|
33
|
+
const status = await git(cwd, ['status', '--porcelain']);
|
|
106
34
|
return status.length > 0;
|
|
107
35
|
}
|
|
108
36
|
export async function diff(cwd, base, remote) {
|
|
109
|
-
return
|
|
110
|
-
}
|
|
111
|
-
export class HookError extends Error {
|
|
112
|
-
}
|
|
113
|
-
export async function commitAll(cwd, message) {
|
|
114
|
-
if (!(await isDirty(cwd))) {
|
|
115
|
-
return false;
|
|
116
|
-
}
|
|
117
|
-
await must('git', ['add', '-A'], { cwd });
|
|
118
|
-
await commitStaged(cwd, message);
|
|
119
|
-
return true;
|
|
120
|
-
}
|
|
121
|
-
async function commitStaged(cwd, message) {
|
|
122
|
-
const folder = await mkdtemp(join(tmpdir(), 'next-issue-message-'));
|
|
123
|
-
const file = join(folder, 'COMMIT_EDITMSG');
|
|
124
|
-
try {
|
|
125
|
-
await writeFile(file, `${message}\n`);
|
|
126
|
-
await runHook(cwd, 'pre-commit');
|
|
127
|
-
await runHook(cwd, 'commit-msg', file);
|
|
128
|
-
await must('git', ['commit', '--no-verify', '-F', file], { cwd });
|
|
129
|
-
}
|
|
130
|
-
finally {
|
|
131
|
-
await rm(folder, { recursive: true, force: true });
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
async function runHook(cwd, name, ...args) {
|
|
135
|
-
try {
|
|
136
|
-
await must('git', ['hook', 'run', '--ignore-missing', name, '--', ...args], { cwd });
|
|
137
|
-
}
|
|
138
|
-
catch (error) {
|
|
139
|
-
throw new HookError(error instanceof Error ? error.message : String(error));
|
|
140
|
-
}
|
|
37
|
+
return git(cwd, ['diff', `${remoteRef(remote, base)}...HEAD`]);
|
|
141
38
|
}
|
|
142
39
|
export async function discardChanges(cwd, target) {
|
|
143
40
|
if (!(await isDirty(cwd)) && (await revision(cwd)) === target) {
|
|
144
41
|
return false;
|
|
145
42
|
}
|
|
146
|
-
await
|
|
147
|
-
await must('git', ['clean', '-fd'], { cwd });
|
|
43
|
+
await resetHard(cwd, target);
|
|
148
44
|
return true;
|
|
149
45
|
}
|
|
46
|
+
export async function resetHard(cwd, target) {
|
|
47
|
+
await git(cwd, ['reset', '--hard', target]);
|
|
48
|
+
await git(cwd, ['clean', '-fd']);
|
|
49
|
+
}
|
|
150
50
|
export async function setAside(cwd, target, branch) {
|
|
151
|
-
await
|
|
51
|
+
await git(cwd, ['branch', branch]);
|
|
152
52
|
if (await isDirty(cwd)) {
|
|
153
|
-
await
|
|
53
|
+
await git(cwd, ['reset', '--soft', target]);
|
|
154
54
|
return;
|
|
155
55
|
}
|
|
156
56
|
await discardChanges(cwd, target);
|
|
157
57
|
}
|
|
158
58
|
export async function disputeBranches(repo, branch) {
|
|
159
|
-
const list = await
|
|
160
|
-
|
|
59
|
+
const list = await git(repo.root, [
|
|
60
|
+
'for-each-ref',
|
|
61
|
+
'--format=%(refname:short)',
|
|
62
|
+
`refs/heads/${branch}-dispute-*`,
|
|
63
|
+
]);
|
|
64
|
+
return lines(list);
|
|
161
65
|
}
|
|
162
66
|
export async function push(cwd, remote, branch, force = false) {
|
|
163
|
-
await
|
|
164
|
-
}
|
|
165
|
-
export async function resetToBase(cwd, base, remote) {
|
|
166
|
-
await must('git', ['fetch', remote, base], { cwd });
|
|
167
|
-
await must('git', ['reset', '--hard', `${remote}/${base}`], { cwd });
|
|
168
|
-
}
|
|
169
|
-
export async function startMerge(cwd, base, remote) {
|
|
170
|
-
await must('git', ['fetch', remote, base], { cwd });
|
|
171
|
-
const result = await run('git', ['merge', '--no-ff', '--no-commit', `${remote}/${base}`], {
|
|
172
|
-
cwd,
|
|
173
|
-
});
|
|
174
|
-
if (result.code === 0) {
|
|
175
|
-
return (await merging(cwd)) ? [] : undefined;
|
|
176
|
-
}
|
|
177
|
-
const listed = await must('git', ['diff', '--name-only', '--diff-filter=U'], { cwd });
|
|
178
|
-
const files = listed.split('\n').filter((line) => line.length > 0);
|
|
179
|
-
if (files.length === 0) {
|
|
180
|
-
throw new Error(`git merge ${remote}/${base} failed: ${result.stderr.trim()}`);
|
|
181
|
-
}
|
|
182
|
-
return files;
|
|
183
|
-
}
|
|
184
|
-
async function merging(cwd) {
|
|
185
|
-
const result = await run('git', ['rev-parse', '--quiet', '--verify', 'MERGE_HEAD'], { cwd });
|
|
186
|
-
return result.code === 0;
|
|
67
|
+
await git(cwd, ['push', '-u', ...optionalFlag(force, '--force'), remote, branch]);
|
|
187
68
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
return false;
|
|
192
|
-
}
|
|
193
|
-
for (const file of files) {
|
|
194
|
-
const text = await readFile(join(cwd, file), 'utf8').catch(() => '');
|
|
195
|
-
if (CONFLICT_MARKER.test(text)) {
|
|
196
|
-
return false;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
await must('git', ['add', '-A'], { cwd });
|
|
200
|
-
await commitStaged(cwd, message);
|
|
201
|
-
return true;
|
|
69
|
+
export async function fetchBase(cwd, base, remote) {
|
|
70
|
+
await git(cwd, ['fetch', remote, base]);
|
|
71
|
+
return remoteRef(remote, base);
|
|
202
72
|
}
|
|
203
|
-
export async function
|
|
204
|
-
await
|
|
205
|
-
await
|
|
73
|
+
export async function resetToBase(cwd, base, remote) {
|
|
74
|
+
const target = await fetchBase(cwd, base, remote);
|
|
75
|
+
await git(cwd, ['reset', '--hard', target]);
|
|
206
76
|
}
|
|
207
77
|
export async function latestSubject(cwd, base, remote) {
|
|
208
|
-
const subject = await
|
|
209
|
-
cwd,
|
|
210
|
-
});
|
|
78
|
+
const subject = await git(cwd, ['log', '-1', '--format=%s', `${remoteRef(remote, base)}..HEAD`]);
|
|
211
79
|
return subject === '' ? undefined : subject;
|
|
212
80
|
}
|
|
213
81
|
export async function revision(cwd) {
|
|
214
|
-
return
|
|
82
|
+
return git(cwd, ['rev-parse', 'HEAD']);
|
|
83
|
+
}
|
|
84
|
+
export async function currentBranch(cwd) {
|
|
85
|
+
const result = await run('git', ['symbolic-ref', '--quiet', '--short', 'HEAD'], { cwd });
|
|
86
|
+
return succeeded(result) ? result.stdout.trim() : undefined;
|
|
215
87
|
}
|
|
216
88
|
export async function isAncestor(cwd, ancestor, descendant) {
|
|
217
|
-
|
|
218
|
-
return result.code === 0;
|
|
89
|
+
return succeeds(cwd, ['merge-base', '--is-ancestor', ancestor, descendant]);
|
|
219
90
|
}
|
|
220
91
|
export async function deleteBranch(repo, branch) {
|
|
221
|
-
|
|
222
|
-
|
|
92
|
+
return succeeds(repo.root, ['branch', '-D', branch]);
|
|
93
|
+
}
|
|
94
|
+
export async function succeeds(cwd, args) {
|
|
95
|
+
return succeeded(await run('git', args, { cwd }));
|
|
96
|
+
}
|
|
97
|
+
export async function git(cwd, args) {
|
|
98
|
+
return must('git', args, { cwd });
|
|
223
99
|
}
|