dsh-git-push 2.9.3 → 2.9.9
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 +22 -25
- package/lib/app/apply.js +8 -1
- package/lib/app/audit-api.js +4 -1
- package/lib/app/command-registry.js +17 -11
- package/lib/app/handlers/meta.js +38 -0
- package/lib/app/handlers/repo-actions.js +3 -1
- package/lib/app/handlers/settings.js +0 -0
- package/lib/app/http-handlers.js +3 -1
- package/lib/app/schema.js +0 -0
- package/lib/app/settings-bridge.js +0 -0
- package/lib/app/tool-call.js +26 -21
- package/lib/ast/control-flow.js +12 -3
- package/lib/ast/size.js +5 -2
- package/lib/audit/audit-file.js +4 -2
- package/lib/audit/file-context.js +89 -0
- package/lib/audit/finding.js +45 -2
- package/lib/audit/index.js +2 -2
- package/lib/audit/orchestrate.js +6 -1
- package/lib/checks/button-bind.js +25 -2
- package/lib/checks/regex.js +7 -3
- package/lib/commit-push.js +20 -2
- package/lib/core/exec.js +6 -4
- package/lib/exempt/index.js +72 -26
- package/lib/exempt/tool.js +198 -0
- package/lib/git/clone-history-mode.js +24 -5
- package/lib/git/push.js +28 -13
- package/lib/git/transport.js +49 -17
- package/lib/git/visibility.js +93 -9
- package/lib/npm/publish.js +27 -0
- package/lib/npm/registry.js +5 -2
- package/lib/self/index.js +1 -1
- package/package.json +2 -4
- package/skills/dev/dsh-git-push.md +1 -2
- package/skills/guide/guide-cli-scripts.md +3 -3
- package/skills/guide/guide-inject-ui.md +4 -4
- package/assets/minihost.sh +0 -35
- package/assets/preview.html +0 -36703
- package/lib/fs/edit-after-read.js +0 -142
- package/scripts/frontend-preview-check.mjs +0 -124
- package/scripts/preview-gen.mjs +0 -489
- package/scripts/preview-local-runner.mjs +0 -55
- package/scripts/preview-server-direct.mjs +0 -116
- package/scripts/preview-server.mjs +0 -305
- package/scripts/preview-slot-data.mjs +0 -123
- package/scripts/sync-plugin-install.mjs +0 -286
- package/scripts/sync-plugin.mjs +0 -284
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 注释豁免工具(exempt):把「手写 dsh-skip-* 注释」变成工具操作。
|
|
3
|
+
*
|
|
4
|
+
* 解决的问题(历史痛点):
|
|
5
|
+
* ① 记不住哪个 finding 该写哪个标记、写文件头还是行尾;
|
|
6
|
+
* ② 写了标记却不生效(提示与实际行为不符,曾一次查出 24 种组合);
|
|
7
|
+
* ③ 标记散落各文件,无法盘点/清理。
|
|
8
|
+
*
|
|
9
|
+
* 动作:add(加)/ remove(删)/ list(盘点)/ check(校验真生效)。
|
|
10
|
+
* 标记映射单一真源:直接读同进程 lib/exempt/index.js 的 EXEMPT_MARKERS,不复制。
|
|
11
|
+
*
|
|
12
|
+
* 写入格式与手写完全一致(审计侧零改动):
|
|
13
|
+
* header → 文件头前 3 行内追加 `// dsh-skip-<x>: <reason>`
|
|
14
|
+
* line → 该行行尾追加 ` // dsh-skip-<x>`
|
|
15
|
+
*/
|
|
16
|
+
import { existsSync, readFileSync, writeFileSync, readdirSync, statSync } from 'node:fs';
|
|
17
|
+
import { join, relative, resolve, sep, dirname } from 'node:path';
|
|
18
|
+
|
|
19
|
+
import { EXEMPT_MARKERS, exemptHintForFinding, exemptMarkerCovers } from './index.js';
|
|
20
|
+
import { auditFull } from '../audit/orchestrate.js';
|
|
21
|
+
|
|
22
|
+
/** 跑一次审计找 rule 对应的 finding kind(豁免判定按 kind,如 max-nesting-depth → max-depth)。 */
|
|
23
|
+
async function findRuleKind(repoPath, ruleId) {
|
|
24
|
+
try {
|
|
25
|
+
const full = await auditFull(repoPath, { scope: 'full', maxScanFiles: 2000 });
|
|
26
|
+
const hit = (full.findings || []).find((f) => f.rule === ruleId);
|
|
27
|
+
return hit ? String(hit.kind || '') : '';
|
|
28
|
+
} catch {
|
|
29
|
+
return '';
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** 读文件(UTF-8);不存在返回 null。 */
|
|
34
|
+
function readText(file) {
|
|
35
|
+
try { return existsSync(file) ? readFileSync(file, 'utf8') : null; } catch { return null; }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** 路径归一:相对仓库根、去 ./、防越界。返回 { ok, abs?, rel?, error? }。 */
|
|
39
|
+
function resolveTarget(repoPath, p) {
|
|
40
|
+
const root = resolve(repoPath);
|
|
41
|
+
const rel = String(p || '').replace(/\\/g, '/').replace(/^\.\//, '').trim();
|
|
42
|
+
if (!rel) return { ok: false, error: '缺少 path' };
|
|
43
|
+
if (rel.startsWith('/') || /^[A-Za-z]:/.test(rel)) return { ok: false, error: `path 必须是相对仓库根(收到绝对路径:${rel})` };
|
|
44
|
+
const abs = resolve(root, rel);
|
|
45
|
+
if (abs !== root && !abs.startsWith(root + sep)) return { ok: false, error: `path 越界(解析后不在仓库内:${rel})` };
|
|
46
|
+
return { ok: true, abs, rel };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** 由 rule/marker 推导写入参数;返回 { ok, marker?, scope?, reason?, error? }。 */
|
|
50
|
+
function resolveMarker({ rule = '', marker = '', scope = '', kind = '' }) {
|
|
51
|
+
const wantMarker = String(marker || '').trim();
|
|
52
|
+
const wantRule = String(rule || '').trim();
|
|
53
|
+
if (!wantMarker && !wantRule) return { ok: false, error: '需要 rule(用于推导标记)或显式 marker' };
|
|
54
|
+
// 反查「真能豁免该 rule 的标记」(与豁免判定同一口径)
|
|
55
|
+
// 豁免判定按 finding 的 kind(如 max-nesting-depth → max-depth)——kind 由 addExempt 跑审计拿到;
|
|
56
|
+
// 拿不到时退回 id 最后一段(仅兜底,可能对不上,会如实报「没有标记能豁免」)。
|
|
57
|
+
const kindUsed = kind || (wantRule ? String(wantRule).split('/').pop() : '');
|
|
58
|
+
const hint = wantRule ? exemptHintForFinding({ rule: wantRule, kind: kindUsed }) : null;
|
|
59
|
+
const resolved = wantMarker || (hint && hint.marker) || '';
|
|
60
|
+
if (!resolved) return { ok: false, error: `没有任何标记能豁免 rule「${wantRule}」(应改代码,或走 .auditignore / 豁免槽位)` };
|
|
61
|
+
const meta = EXEMPT_MARKERS[resolved];
|
|
62
|
+
if (!meta) return { ok: false, error: `未知标记「${resolved}」;可用:${Object.keys(EXEMPT_MARKERS).join(', ')}` };
|
|
63
|
+
// 显式 marker 与 rule 推导冲突 ⇒ 以推导为准并报错(防写错标记)
|
|
64
|
+
if (wantMarker && hint && hint.marker !== wantMarker) {
|
|
65
|
+
return { ok: false, error: `标记「${wantMarker}」不能豁免 rule「${wantRule}」,正确标记是「${hint.marker}」` };
|
|
66
|
+
}
|
|
67
|
+
// 显式 marker 但没给 rule:用 marker 的元数据判定范围
|
|
68
|
+
const finalScope = String(scope || '').trim() || (meta.lineLevel ? 'header' : 'header');
|
|
69
|
+
if (finalScope === 'line' && meta.lineLevel !== true) {
|
|
70
|
+
return { ok: false, error: `标记「${resolved}」不支持行级(lineLevel=false),只能用 scope=header` };
|
|
71
|
+
}
|
|
72
|
+
if (finalScope !== 'header' && finalScope !== 'line') {
|
|
73
|
+
return { ok: false, error: `scope 只能是 header 或 line(收到 ${finalScope})` };
|
|
74
|
+
}
|
|
75
|
+
return { ok: true, marker: resolved, scope: finalScope, hint: hint ? hint.hint : (meta.hint || '') };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** 是否已有同一标记(header:前 3 行;line:指定行)。 */
|
|
79
|
+
function hasMarker(lines, marker, scope, line) {
|
|
80
|
+
const re = new RegExp(`dsh-skip-${marker.replace(/^dsh-skip-/, '')}\\b`);
|
|
81
|
+
if (scope === 'header') return lines.slice(0, 3).some((l) => re.test(l));
|
|
82
|
+
const idx = Number(line) - 1;
|
|
83
|
+
return idx >= 0 && idx < lines.length && re.test(lines[idx]);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** 生成 header 注释行。 */
|
|
87
|
+
function headerComment(marker, reason) {
|
|
88
|
+
return `// ${marker}${reason ? `: ${String(reason).replace(/\s+/g, ' ').trim()}` : ''}`;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* add:给指定文件(或行)加豁免注释。
|
|
93
|
+
* @returns {{ok, results?:Array, error?}}
|
|
94
|
+
*/
|
|
95
|
+
export async function addExempt({ repoPath = '', path: p, line, scope = '', rule = '', marker = '', reason = '', dryRun = false } = {}) {
|
|
96
|
+
const paths = Array.isArray(p) ? p : [p];
|
|
97
|
+
if (!paths.length) return { ok: false, error: '缺少 path' };
|
|
98
|
+
if (paths.length > 1 && line !== undefined) return { ok: false, error: '多文件时不允许 line(行号无法跨文件对齐)——改用 scope=header 或逐个调用' };
|
|
99
|
+
// 先跑一次审计拿 rule 的 finding kind(豁免判定按 kind,如 max-nesting-depth → max-depth)
|
|
100
|
+
const kind = String(rule || '').trim() ? await findRuleKind(repoPath, String(rule).trim()) : '';
|
|
101
|
+
const m = resolveMarker({ rule, marker, scope, kind });
|
|
102
|
+
if (!m.ok) return { ok: false, error: m.error };
|
|
103
|
+
if (m.scope === 'line' && line === undefined) return { ok: false, error: 'scope=line 时必须给 line(1-based 行号)' };
|
|
104
|
+
|
|
105
|
+
// ① 先全部校验(原子:任一失败则一个都不写)
|
|
106
|
+
const plans = [];
|
|
107
|
+
const results = [];
|
|
108
|
+
for (const one of paths) {
|
|
109
|
+
const t = resolveTarget(repoPath, one);
|
|
110
|
+
if (!t.ok) { results.push({ path: String(one), ok: false, error: t.error }); continue; }
|
|
111
|
+
const text = readText(t.abs);
|
|
112
|
+
if (text === null) { results.push({ path: t.rel, ok: false, error: '文件不存在' }); continue; }
|
|
113
|
+
const lines = text.split('\n');
|
|
114
|
+
if (m.scope === 'line') {
|
|
115
|
+
const idx = Number(line) - 1;
|
|
116
|
+
if (!Number.isInteger(idx) || idx < 0 || idx >= lines.length) { results.push({ path: t.rel, ok: false, error: `line ${line} 越界(文件共 ${lines.length} 行)` }); continue; }
|
|
117
|
+
const row = lines[idx];
|
|
118
|
+
if (/\/\*/.test(row) && !/\*\//.test(row)) { results.push({ path: t.rel, ok: false, error: '该行在块注释内,建议 scope=header' }); continue; }
|
|
119
|
+
if (/^\s*(\/\/|\*)/.test(row)) { results.push({ path: t.rel, ok: false, error: '该行是注释行,无法行尾追加,建议 scope=header' }); continue; }
|
|
120
|
+
if (hasMarker(lines, m.marker, 'line', line)) { results.push({ path: t.rel, ok: true, unchanged: true }); continue; }
|
|
121
|
+
const next = [...lines];
|
|
122
|
+
next[idx] = `${row} // ${m.marker}`;
|
|
123
|
+
plans.push({ abs: t.abs, rel: t.rel, next: next.join('\n') });
|
|
124
|
+
results.push({ path: t.rel, ok: true, changed: true, line: Number(line), marker: m.marker });
|
|
125
|
+
} else {
|
|
126
|
+
if (hasMarker(lines, m.marker, 'header')) { results.push({ path: t.rel, ok: true, unchanged: true }); continue; }
|
|
127
|
+
const next = [headerComment(m.marker, reason), ...lines];
|
|
128
|
+
plans.push({ abs: t.abs, rel: t.rel, next: next.join('\n') });
|
|
129
|
+
results.push({ path: t.rel, ok: true, changed: true, marker: m.marker, scope: 'header' });
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
const failed = results.filter((r) => r.ok === false);
|
|
133
|
+
if (failed.length) return { ok: false, error: `校验失败(${failed.length} 个文件),未写入任何文件`, results };
|
|
134
|
+
// ② 统一写盘
|
|
135
|
+
if (dryRun) return { ok: true, dryRun: true, results };
|
|
136
|
+
for (const plan of plans) writeFileSync(plan.abs, plan.next, 'utf8');
|
|
137
|
+
return { ok: true, results };
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** remove:移除指定文件的豁免(指定 marker 或该文件全部 dsh-skip)。 */
|
|
141
|
+
export function removeExempt({ repoPath = '', path: p, marker = '', dryRun = false } = {}) {
|
|
142
|
+
const paths = Array.isArray(p) ? p : [p];
|
|
143
|
+
const results = [];
|
|
144
|
+
for (const one of paths) {
|
|
145
|
+
const t = resolveTarget(repoPath, one);
|
|
146
|
+
if (!t.ok) { results.push({ path: String(one), ok: false, error: t.error }); continue; }
|
|
147
|
+
const text = readText(t.abs);
|
|
148
|
+
if (text === null) { results.push({ path: t.rel, ok: false, error: '文件不存在' }); continue; }
|
|
149
|
+
const re = marker ? new RegExp(`\\s*//\\s*dsh-skip-${marker.replace(/^dsh-skip-/, '')}(?::[^\\n]*)?`, 'g') : /\s*\/\/\s*dsh-skip-[a-z]+(?::[^\n]*)?/g;
|
|
150
|
+
const next = text.replace(re, '');
|
|
151
|
+
if (next === text) { results.push({ path: t.rel, ok: true, unchanged: true }); continue; }
|
|
152
|
+
if (!dryRun) writeFileSync(t.abs, next, 'utf8');
|
|
153
|
+
results.push({ path: t.rel, ok: true, changed: true });
|
|
154
|
+
}
|
|
155
|
+
const failed = results.filter((r) => r.ok === false);
|
|
156
|
+
if (failed.length) return { ok: false, error: `校验失败(${failed.length} 个文件)`, results };
|
|
157
|
+
return { ok: true, dryRun, results };
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** list:盘点仓库内所有 dsh-skip 标记(按文件 × 标记 × 位置)。 */
|
|
161
|
+
export function listExempt({ repoPath = '', root = '' } = {}) {
|
|
162
|
+
const base = resolve(root || repoPath);
|
|
163
|
+
const out = [];
|
|
164
|
+
const walk = (dir, depth) => {
|
|
165
|
+
if (depth > 8) return;
|
|
166
|
+
let entries = [];
|
|
167
|
+
try { entries = readdirSync(dir, { withFileTypes: true }); } catch { return; }
|
|
168
|
+
for (const e of entries) {
|
|
169
|
+
if (e.name === 'node_modules' || e.name === '.git' || e.name === '.trash') continue;
|
|
170
|
+
const full = join(dir, e.name);
|
|
171
|
+
if (e.isDirectory()) { walk(full, depth + 1); continue; }
|
|
172
|
+
if (!/\.(js|mjs|cjs|ts|tsx|jsx|py|md)$/.test(e.name)) continue;
|
|
173
|
+
const text = readText(full);
|
|
174
|
+
if (!text) continue;
|
|
175
|
+
const lines = text.split('\n');
|
|
176
|
+
lines.forEach((row, i) => {
|
|
177
|
+
const m = row.match(/dsh-skip-([a-z]+)/);
|
|
178
|
+
if (!m) return;
|
|
179
|
+
out.push({ file: relative(base, full).split(sep).join('/'), line: i + 1, marker: `dsh-skip-${m[1]}`, scope: i < 3 ? 'header' : 'line' });
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
walk(base, 0);
|
|
184
|
+
return { ok: true, total: out.length, items: out };
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** check:校验每条标记是否真的能豁免(用同一判定器对 rule 反查,识别死标记/写错标记)。 */
|
|
188
|
+
export function checkExempt({ repoPath = '', root = '' } = {}) {
|
|
189
|
+
const listed = listExempt({ repoPath, root });
|
|
190
|
+
const issues = [];
|
|
191
|
+
for (const it of listed.items) {
|
|
192
|
+
const meta = EXEMPT_MARKERS[it.marker];
|
|
193
|
+
if (!meta) { issues.push({ ...it, issue: 'unknown-marker', hint: '标记不在注册表里(拼写错误?)' }); continue; }
|
|
194
|
+
// 用标记的 blocked 反查:该标记能豁免哪些 rule 前缀——至少应有一个(否则标记形同虚设)
|
|
195
|
+
if (!Array.isArray(meta.blocked) || !meta.blocked.length) issues.push({ ...it, issue: 'dead-marker', hint: '该标记没有可豁免的 blocked 类型' });
|
|
196
|
+
}
|
|
197
|
+
return { ok: issues.length === 0, total: listed.total, issues };
|
|
198
|
+
}
|
|
@@ -16,6 +16,8 @@ import { fetchCommitChain } from './clone-history.js';
|
|
|
16
16
|
import { replayHistory } from './clone-replay.js';
|
|
17
17
|
import { createReplayIo } from './clone-replay-io.js';
|
|
18
18
|
import { runGit } from './exec.js';
|
|
19
|
+
import { resolveOwnerVisibility, accessPlan, sshGitUrl } from './visibility.js';
|
|
20
|
+
import { resolveSshKeys } from './credentials.js';
|
|
19
21
|
|
|
20
22
|
/**
|
|
21
23
|
* 取某分支的 HEAD sha。
|
|
@@ -105,12 +107,26 @@ export async function cloneWithHistory({
|
|
|
105
107
|
* @returns {Promise<{ok:boolean,headSha:string,depth:number,truncated:boolean,steps:Array<object>,error?:string}>}
|
|
106
108
|
*/
|
|
107
109
|
export async function cloneWithGitFetch({
|
|
108
|
-
owner = '', repo = '', branch = '', repoPath = '', depth, deps = {},
|
|
110
|
+
owner = '', repo = '', branch = '', repoPath = '', depth, deps = {}, token = '',
|
|
109
111
|
} = {}) {
|
|
110
112
|
const git = deps.runGit || runGit;
|
|
111
|
-
|
|
113
|
+
// 统一前置判断:私有/未知仓库不走第三方镜像——镜像看不到私有库,经它 fetch 必然认证失败。
|
|
114
|
+
// deps.visibility 供离线测试直接指定结果('public' | 'private' | 'unknown')。
|
|
115
|
+
const vis = deps.visibility ? { visibility: deps.visibility } : await resolveOwnerVisibility({ owner, repo, token });
|
|
116
|
+
const plan = accessPlan(vis.visibility);
|
|
117
|
+
// 私有/未知:远端用 SSH 形态(ssh.github.com:443),并注入插件 SSH 密钥;
|
|
118
|
+
// 公开:维持 https + 镜像加速(本机 github.com:443 直连不通,公开库靠镜像)。
|
|
119
|
+
const remoteUrl = plan.transport === 'ssh' ? sshGitUrl(owner, repo) : `https://github.com/${owner}/${repo}.git`;
|
|
120
|
+
const sshEnv = {};
|
|
121
|
+
if (plan.transport === 'ssh') {
|
|
122
|
+
const keyPath = (deps.sshKeyPath || resolveSshKeys()[0]?.keyPath || '');
|
|
123
|
+
if (keyPath) {
|
|
124
|
+
sshEnv.GIT_SSH_COMMAND = `ssh -i "${keyPath}" -p 443 -o IdentitiesOnly=yes -o StrictHostKeyChecking=accept-new -o BatchMode=yes -o ConnectTimeout=8`;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
const gitOpts = { cwd: repoPath, noMirror: !plan.useMirror, env: sshEnv };
|
|
112
128
|
const steps = [];
|
|
113
|
-
const fail = (error) => ({ ok: false, headSha: '', depth: Number(depth) || 0, truncated: false, steps, error });
|
|
129
|
+
const fail = (error) => ({ ok: false, headSha: '', depth: Number(depth) || 0, truncated: false, steps, error, visibility: vis.visibility, transport: plan.transport });
|
|
114
130
|
const run = (args) => {
|
|
115
131
|
const r = git(args, gitOpts);
|
|
116
132
|
steps.push({ cmd: args.join(' '), ok: !!r?.ok });
|
|
@@ -123,7 +139,10 @@ export async function cloneWithGitFetch({
|
|
|
123
139
|
// 不支持 mode 的卷(CIFS)上抑制权限噪音——与 API 路径同口径
|
|
124
140
|
run(['config', 'core.fileMode', 'false']);
|
|
125
141
|
if (!git(['remote', 'get-url', 'origin'], gitOpts)?.ok) {
|
|
126
|
-
run(['remote', 'add', 'origin',
|
|
142
|
+
run(['remote', 'add', 'origin', remoteUrl]);
|
|
143
|
+
} else {
|
|
144
|
+
// 已存在 origin(续跑):按本次判断纠正,避免上次留下的 https 形态继续走镜像
|
|
145
|
+
run(['remote', 'set-url', 'origin', remoteUrl]);
|
|
127
146
|
}
|
|
128
147
|
|
|
129
148
|
// 显式 refspec:同时写入 refs/remotes/origin/<branch>,后续可据此建本地分支并设上游
|
|
@@ -139,5 +158,5 @@ export async function cloneWithGitFetch({
|
|
|
139
158
|
if (!co?.ok) return fail(`checkout 失败:${co?.stderr || '未知'}`);
|
|
140
159
|
run(['branch', `--set-upstream-to=origin/${branch}`, branch]);
|
|
141
160
|
|
|
142
|
-
return { ok: true, headSha: sha, depth: n, truncated: n > 0, steps };
|
|
161
|
+
return { ok: true, headSha: sha, depth: n, truncated: n > 0, steps, visibility: vis.visibility, transport: plan.transport };
|
|
143
162
|
}
|
package/lib/git/push.js
CHANGED
|
@@ -10,7 +10,7 @@ import { existsSync } from 'node:fs';
|
|
|
10
10
|
import { join } from 'node:path';
|
|
11
11
|
import { autoTagDSHProject, ensureAuxSshRemote, readPkgVersion, updateRemoteTrackingRef } from './post-push.js';
|
|
12
12
|
import { loadRequirements } from './config.js';
|
|
13
|
-
import { resolveSshKeys } from './credentials.js';
|
|
13
|
+
import { resolveSshKeys, resolveToken } from './credentials.js';
|
|
14
14
|
import { runGit } from './exec.js';
|
|
15
15
|
import { buildWrappedGitEnv } from './wrapped-git.js';
|
|
16
16
|
import { buildCommitMessage } from './commit-message.js';
|
|
@@ -44,7 +44,7 @@ function resolveRepoIdentity(repoPath) {
|
|
|
44
44
|
import { fetchRemoteHeads, dispatchPush, liveRemoteHead } from './transport.js';
|
|
45
45
|
// 推送后「远端 sha 硬校验」用(假成功防线:远端空仓/未落地时必须判失败,见 enhanceAfterPushSuccess)
|
|
46
46
|
import { githubFetch } from './api.js';
|
|
47
|
-
import { resolveRepoVisibility } from './visibility.js';
|
|
47
|
+
import { resolveRepoVisibility, cachedVisibility } from './visibility.js';
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
50
|
* 统一提交推送:预检 → 敏感文件 .gitignore → add → commit → push。
|
|
@@ -54,7 +54,7 @@ import { resolveRepoVisibility } from './visibility.js';
|
|
|
54
54
|
* customIgnorePatterns:逗号/换行分隔的 gitignore pattern,追加进 .gitignore(幂等)
|
|
55
55
|
* @returns {{ok, steps: string[], commitSha?, pushed?, push?, remoteHeads?, error?}}
|
|
56
56
|
*/
|
|
57
|
-
export async function commitAndPush({ repoPath = '', message = '', messageItems = null, push = true, dryRun = false, token = '', customIgnorePatterns = '', requirementsConfirmed = false, force = false, pushMethod = 'ssh', pushGate = false, pushConfirmed = false, paths = '' } = {}) {
|
|
57
|
+
export async function commitAndPush({ repoPath = '', message = '', messageItems = null, push = true, dryRun = false, token = '', customIgnorePatterns = '', requirementsConfirmed = false, force = false, pushMethod = 'ssh', pushGate = false, pushConfirmed = false, paths = '', remote = '' } = {}) {
|
|
58
58
|
const steps = [];
|
|
59
59
|
if (!repoPath || !existsSync(join(repoPath, '.git'))) return { ok: false, steps: ['预检'], error: `非 git 仓库: ${repoPath || '(空)'}` };
|
|
60
60
|
// message 支持三种形态(字符串 / 数组 / {subject,items}):在预检处**单点**组装成规范提交信息,
|
|
@@ -199,7 +199,7 @@ export async function commitAndPush({ repoPath = '', message = '', messageItems
|
|
|
199
199
|
steps.push('push');
|
|
200
200
|
// 通道由 dispatchPush 单点决策(默认 SSH:推本地 HEAD、远端 sha 与本地一致;无密钥才回落 API)。
|
|
201
201
|
// ⚠️ dispatchPush 是 async:必须 await(旧 bug:同步调用导致 pr.ok 恒 undefined,推送从未成功)
|
|
202
|
-
const pr = await dispatchPush({ repoPath, token, force, pushMethod });
|
|
202
|
+
const pr = await dispatchPush({ repoPath, token, force, pushMethod, remote });
|
|
203
203
|
if (pr.ok) {
|
|
204
204
|
// D24:pr.pushed=false(内容级短路「远端已是最新」)→ 如实 pushed:false(commitPushDoPush 语义)
|
|
205
205
|
// committed 必须如实带上:cleanSkipCommit 时本次**没有产生新提交**。
|
|
@@ -209,7 +209,7 @@ export async function commitAndPush({ repoPath = '', message = '', messageItems
|
|
|
209
209
|
// 原先只有 API 分支做这些,SSH 分支只拉 heads → 走 SSH 时本地 origin/<branch> 引用不更新,
|
|
210
210
|
// 下次 ahead/behind 判断就会错位。
|
|
211
211
|
steps.push(`pushed-via-${pr.method || 'unknown'}`);
|
|
212
|
-
const enhanced = await enhanceAfterPushSuccess({ repoPath, pr, token, steps, commitSha });
|
|
212
|
+
const enhanced = await enhanceAfterPushSuccess({ repoPath, pr, token, steps, commitSha, remote });
|
|
213
213
|
// 假成功防线(用户实测事故):远端为空仓时推送动作不报错,但提交根本没上去。
|
|
214
214
|
// verified===false 表示「API 查到了远端分支,但 sha 与本地提交不一致 / 查不到该分支」
|
|
215
215
|
// ⇒ 必须返回 ok:false,让调用方与用户看到真实状态,而不是「commit+push done」。
|
|
@@ -267,7 +267,7 @@ async function fetchRemoteBranchRef(repoPath, branch, owner, repo) {
|
|
|
267
267
|
* 结果记入 push.remoteRef / push.auxRemote / autoTag。
|
|
268
268
|
* @returns {Promise<{push, autoTag, heads?}>}
|
|
269
269
|
*/
|
|
270
|
-
async function enhanceAfterPushSuccess({ repoPath, pr, token, steps, commitSha }) {
|
|
270
|
+
async function enhanceAfterPushSuccess({ repoPath, pr, token, steps, commitSha, remote = '' }) {
|
|
271
271
|
const pushSlot = pr;
|
|
272
272
|
const branchRef = pr.branch;
|
|
273
273
|
const localHead = runGit(['rev-parse', 'HEAD'], { cwd: repoPath }).stdout;
|
|
@@ -289,13 +289,20 @@ async function enhanceAfterPushSuccess({ repoPath, pr, token, steps, commitSha }
|
|
|
289
289
|
} catch (e) {
|
|
290
290
|
pushSlot.auxRemote = `ensure-aux-remote 异常: ${e?.message || e}`;
|
|
291
291
|
}
|
|
292
|
+
// 核验用 token:调用方没显式传时从插件凭据兜底。
|
|
293
|
+
// 为什么必须有:pushViaSsh 成功时 pr.token 为空,若这里直接用 token(默认 ''),
|
|
294
|
+
// 后面的 API 核验会以空 token 请求 → 404/401 → 明明推成功了却报「未能核验远端」。
|
|
295
|
+
const verifyToken = String(token || '').trim() || resolveToken({ workspaceRoot: repoPath }).token;
|
|
296
|
+
// 统一前置判断:先确定仓库可见性并填缓存——后续 ls-remote 探针据此决定要不要试 origin(https):
|
|
297
|
+
// 私有库经 https/镜像必然失败,试它只会把「未核验」的原因带偏。
|
|
298
|
+
try { await resolveRepoVisibility(repoPath, verifyToken); } catch { /* 判定失败按 unknown 处理 */ }
|
|
292
299
|
let autoTag = null;
|
|
293
300
|
try {
|
|
294
|
-
autoTag = await autoTagDSHProject({ repoPath, version: readPkgVersion(repoPath), commitSha: pr.commitSha, owner: pr.owner, repo: pr.repo, token: pr.token ||
|
|
301
|
+
autoTag = await autoTagDSHProject({ repoPath, version: readPkgVersion(repoPath), commitSha: pr.commitSha, owner: pr.owner, repo: pr.repo, token: pr.token || verifyToken });
|
|
295
302
|
} catch (e) {
|
|
296
303
|
autoTag = { ok: false, skipped: 'auto-tag-error', error: String(e?.message || e) };
|
|
297
304
|
}
|
|
298
|
-
const heads = await fetchRemoteHeads({ owner: pr.owner, repo: pr.repo, branch: pr.branch, token: pr.token ||
|
|
305
|
+
const heads = await fetchRemoteHeads({ owner: pr.owner, repo: pr.repo, branch: pr.branch, token: pr.token || verifyToken }).catch(() => null);
|
|
299
306
|
// 推送成功后的**硬校验**:远端该分支的 sha 必须等于本次提交 sha。
|
|
300
307
|
// 事故(用户实测):远端仓库为空(API 409 Conflict)时插件仍回「commit+push done」——
|
|
301
308
|
// 成功判定只看「推送动作有没有报错」,没看「远端到底有没有这个提交」,属**假成功**。
|
|
@@ -321,6 +328,13 @@ async function enhanceAfterPushSuccess({ repoPath, pr, token, steps, commitSha }
|
|
|
321
328
|
*/
|
|
322
329
|
const lsRemoteProbe = () => {
|
|
323
330
|
try {
|
|
331
|
+
// 通道 1:SSH(与推送同源)。推送走 ssh:443 时核验也必须走同一条——
|
|
332
|
+
// origin 常是 https 而本机 https 通道不通,只跑 origin 会让探针永远「失明」,
|
|
333
|
+
// 于是明明推送成功却报「未能核验远端」(实测就是这个现象)。
|
|
334
|
+
const ssh = liveRemoteHead({ repoPath, branch: branchRef, remote });
|
|
335
|
+
if (ssh.ok && ssh.sha) return { ok: true, sha: ssh.sha, via: ssh.via };
|
|
336
|
+
// 通道 2:origin(https + 凭据 env)。私有库跳过——镜像/直连都看不到私有库,试了只会多一条失败。
|
|
337
|
+
if (cachedVisibility(repoPath) === 'private') return { ok: false, sha: '', err: '私有库跳过 origin(https) 通道(统一前置判断)' };
|
|
324
338
|
// ⚠️ 必须带**凭据 env**:私有库上不带凭据的 ls-remote 会静默返回空(HTTPS 下等同 404)——
|
|
325
339
|
// 那会让「第二路证据」失明。故这一路必须复用插件自己的凭据装配(SSH 私钥 / HTTPS askpass):
|
|
326
340
|
// exec.js 的 runGit 是裸 git,只有 wrapped-git.js 的 buildWrappedGitEnv 会注入凭据。
|
|
@@ -338,7 +352,7 @@ async function enhanceAfterPushSuccess({ repoPath, pr, token, steps, commitSha }
|
|
|
338
352
|
const lsRemoteSha = () => lsRemoteProbe().sha;
|
|
339
353
|
try {
|
|
340
354
|
const br = await githubFetch(`/repos/${pr.owner}/${pr.repo}/branches/${encodeURIComponent(branchRef)}`,
|
|
341
|
-
{ token: pr.token ||
|
|
355
|
+
{ token: pr.token || verifyToken, method: 'GET' });
|
|
342
356
|
const remoteSha = String(br?.json?.commit?.sha || '');
|
|
343
357
|
// 比对对象是**本次推送所报的 sha**(pr.commitSha):API 通道会在远端新建提交对象,
|
|
344
358
|
// 其 sha 与本地 HEAD 本来就不同(设计如此,见 fetchRemoteBranchRef 注释),
|
|
@@ -422,14 +436,15 @@ export function readmeCheckHint(repoPath) {
|
|
|
422
436
|
* @param {{repoPath?:string, pushMethod?:string}} opts
|
|
423
437
|
* @returns {{ok:boolean, branch?, ahead?, behind?, changed?, pushed?, push?, error?}}
|
|
424
438
|
*/
|
|
425
|
-
export async function pushCurrentBranch({ repoPath = '', pushMethod = 'ssh' } = {}) {
|
|
439
|
+
export async function pushCurrentBranch({ repoPath = '', pushMethod = 'ssh', remote = '' } = {}) {
|
|
426
440
|
if (!repoPath || !existsSync(join(repoPath, '.git'))) return { ok: false, error: `非 git 仓库: ${repoPath || '(空)'}` };
|
|
427
441
|
const branch = runGit(['rev-parse', '--abbrev-ref', 'HEAD'], { cwd: repoPath }).stdout.trim() || '';
|
|
428
442
|
const status = runGit(['status', '--porcelain'], { cwd: repoPath }).stdout;
|
|
429
443
|
const changed = status ? status.split('\n').filter(Boolean).length : 0;
|
|
430
444
|
const up = runGit(['rev-parse', '--abbrev-ref', '--symbolic-full-name', '@{u}'], { cwd: repoPath });
|
|
431
445
|
const upstream = up.ok && up.stdout.trim() ? up.stdout.trim() : '';
|
|
432
|
-
|
|
446
|
+
// 指定 remote 时以它为基准(多 remote / fork 场景);否则沿用 origin
|
|
447
|
+
const originUrl = runGit(['remote', 'get-url', remote || 'origin'], { cwd: repoPath }).stdout.trim();
|
|
433
448
|
// 放宽「必须已 -u 建立上游」——无 @{u} 但有远端同样可推
|
|
434
449
|
// (dispatchPush 走 `git push <远端> HEAD:refs/heads/<分支>`,不依赖上游跟踪)。
|
|
435
450
|
// 领先比较基准 = @{u},否则 origin/<当前分支>;本地无该 ref(未 fetch 过)时
|
|
@@ -438,7 +453,7 @@ export async function pushCurrentBranch({ repoPath = '', pushMethod = 'ssh' } =
|
|
|
438
453
|
let ahead = 0, behind = 0, remoteMissing = false, compareFailed = false;
|
|
439
454
|
// 优先 live ls-remote:origin 是 https 时本地 fetch 常失败,origin/<branch> 缓存过期
|
|
440
455
|
// 会把「远端已前走」显示成「领先 N」,点 push 才报分叉。
|
|
441
|
-
const live = originUrl ? liveRemoteHead({ repoPath, branch }) : { ok: false, sha: '' };
|
|
456
|
+
const live = originUrl ? liveRemoteHead({ repoPath, branch, remote }) : { ok: false, sha: '' };
|
|
442
457
|
if (live.ok && live.sha) {
|
|
443
458
|
const rcLive = runGit(['rev-list', '--left-right', '--count', `HEAD...${live.sha}`], { cwd: repoPath });
|
|
444
459
|
if (rcLive.ok) {
|
|
@@ -471,6 +486,6 @@ export async function pushCurrentBranch({ repoPath = '', pushMethod = 'ssh' } =
|
|
|
471
486
|
if (compareFailed) return { ok: false, ahead, behind, changed, error: '无法确认远端状态(本地未 fetch 且 ls-remote 失败)——请先 git fetch 或检查网络' };
|
|
472
487
|
if (ahead <= 0) return { ok: false, ahead, behind, changed, error: '当前分支未领先远端(没有可推送的新提交)' };
|
|
473
488
|
if (behind > 0) return { ok: false, ahead, behind, changed, error: `本地与远端分叉(本地领先 ${ahead},远端领先 ${behind})——先 pull 合并远端提交再推送` };
|
|
474
|
-
const push = await dispatchPush({ repoPath, branch, pushMethod });
|
|
489
|
+
const push = await dispatchPush({ repoPath, branch, pushMethod, remote });
|
|
475
490
|
return { ok: push.ok === true, branch, ahead, behind, changed, pushed: push.pushed, push, error: push.error || push.reason };
|
|
476
491
|
}
|
package/lib/git/transport.js
CHANGED
|
@@ -19,6 +19,7 @@ import { gitRaw, runGit, runGitAsync } from './exec.js';
|
|
|
19
19
|
import { resolveGithubRemote, parseGithubUrl } from './remote-resolve.js';
|
|
20
20
|
// 推送失败诊断(分类 + 置信度 + 下一步):把原文事实与推断分开返回
|
|
21
21
|
import { classifyPushFailure } from './push-diagnose.js';
|
|
22
|
+
import { cachedVisibility } from './visibility.js';
|
|
22
23
|
|
|
23
24
|
/* ───────── 推送通道常量 ───────── */
|
|
24
25
|
const COMMITS_FETCH_TIMEOUT_MS = 20_000; // 远端 commits 查询超时
|
|
@@ -74,12 +75,12 @@ export async function fetchRemoteHeads({ owner = '', repo = '', branch = '', tok
|
|
|
74
75
|
* @param {object} p { repoPath, branch?, token?, force?, pushMethod? }
|
|
75
76
|
* @returns {Promise<{ok, pushed, method?, reason?, fallbackReason?, key?, ...}>}
|
|
76
77
|
*/
|
|
77
|
-
export async function dispatchPush({ repoPath = '', branch = '', token = '', force = false, pushMethod = 'ssh' } = {}) {
|
|
78
|
+
export async function dispatchPush({ repoPath = '', branch = '', token = '', force = false, pushMethod = 'ssh', remote = '' } = {}) {
|
|
78
79
|
const mode = String(pushMethod || 'ssh').toLowerCase();
|
|
79
80
|
const hasKey = resolveSshKeys().length > 0;
|
|
80
81
|
|
|
81
|
-
const trySsh = () => pushViaSsh({ repoPath, branch, force });
|
|
82
|
-
const tryApi = () => pushViaApi({ repoPath, branch, token, force });
|
|
82
|
+
const trySsh = () => pushViaSsh({ repoPath, branch, force, remote });
|
|
83
|
+
const tryApi = () => pushViaApi({ repoPath, branch, token, force, remote });
|
|
83
84
|
|
|
84
85
|
if (mode === 'api') {
|
|
85
86
|
const apiRes = await tryApi();
|
|
@@ -100,7 +101,7 @@ export async function dispatchPush({ repoPath = '', branch = '', token = '', for
|
|
|
100
101
|
const localHead = runGit(['rev-parse', 'HEAD'], { cwd: repoPath }).stdout;
|
|
101
102
|
const cur = branch || runGit(['branch', '--show-current'], { cwd: repoPath }).stdout || 'master';
|
|
102
103
|
const cached = runGit(['rev-parse', `refs/remotes/origin/${cur}`], { cwd: repoPath }).stdout;
|
|
103
|
-
const live = liveRemoteHead({ repoPath, branch: cur });
|
|
104
|
+
const live = liveRemoteHead({ repoPath, branch: cur, remote });
|
|
104
105
|
const remoteHead = live.sha || cached || '';
|
|
105
106
|
return {
|
|
106
107
|
ok: false, pushed: false, method: 'ssh', diverged: true,
|
|
@@ -187,12 +188,17 @@ function buildLsRemoteSshCmd(keyPath, known, { mux = true } = {}) {
|
|
|
187
188
|
* origin 是 https 时本地 fetch 常失败,账号卡片会把「远端已前走」显示成「领先 N」。
|
|
188
189
|
* @returns {{ok:boolean, sha:string, via?:string}}
|
|
189
190
|
*/
|
|
190
|
-
export function liveRemoteHead({ repoPath = '', branch = '' } = {}) {
|
|
191
|
+
export function liveRemoteHead({ repoPath = '', branch = '', remote = '' } = {}) {
|
|
191
192
|
// 离线开关(单测/无外网)——直接失败,不触发 SSH/网络 ls-remote(防挂起)
|
|
192
193
|
if (process.env.DSH_GIT_PUSH_OFFLINE === '1') return { ok: false, sha: '', via: 'offline' };
|
|
193
|
-
// 自动指定正确的 remote(与推送同源判定:归属 + ssh:443 形态 +
|
|
194
|
+
// 自动指定正确的 remote(与推送同源判定:归属 + ssh:443 形态 + 名字优先级);
|
|
195
|
+
// 指定 remote 时以它为核验目标(与 pushViaSsh/pushViaApi 的 remote 同源)。
|
|
194
196
|
const rr = resolveGithubRemote({ repoPath });
|
|
195
|
-
|
|
197
|
+
let url = rr.ok && rr.url ? rr.url : '';
|
|
198
|
+
if (remote) {
|
|
199
|
+
url = String(runGit(['remote', 'get-url', remote], { cwd: repoPath }).stdout || '').trim() || url;
|
|
200
|
+
}
|
|
201
|
+
const pr = (url ? parseGithubUrl(url) : null)
|
|
196
202
|
|| parseGithubOwnerRepo(runGit(['remote', 'get-url', 'origin'], { cwd: repoPath }).stdout);
|
|
197
203
|
const target = branch || runGit(['branch', '--show-current'], { cwd: repoPath }).stdout;
|
|
198
204
|
if (!pr || !target) return { ok: false, sha: '' };
|
|
@@ -213,21 +219,38 @@ export function liveRemoteHead({ repoPath = '', branch = '' } = {}) {
|
|
|
213
219
|
if (sha) return { ok: true, sha, via: kind };
|
|
214
220
|
}
|
|
215
221
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
222
|
+
// 统一前置判断:私有库不试 origin(https) 回退——镜像/直连都看不到私有库,试了只会多一条失败。
|
|
223
|
+
// unknown 时保留回退(可能是公开库,https 直连/镜像仍有机会成功)。
|
|
224
|
+
if (cachedVisibility(repoPath) !== 'private') {
|
|
225
|
+
const lr = runGit(['ls-remote', rr.remote || 'origin', `${REFS_HEADS_PREFIX}${target}`], { cwd: repoPath, timeoutMs: LS_TIMEOUT });
|
|
226
|
+
if (lr.ok) {
|
|
227
|
+
const sha = (lr.stdout || '').trim().split(/\s+/)[0] || '';
|
|
228
|
+
if (sha) return { ok: true, sha, via: rr.remote || 'origin' };
|
|
229
|
+
}
|
|
220
230
|
}
|
|
221
231
|
return { ok: false, sha: '' };
|
|
222
232
|
}
|
|
223
233
|
|
|
224
234
|
/** SSH 回退:ssh.github.com:443(token 401 时)。force=true 时 --force(覆盖远端历史)。 */
|
|
225
|
-
|
|
235
|
+
/** 解析指定 remote 的目标(owner/repo);remote 不存在或不是 GitHub 地址返回 null。 */
|
|
236
|
+
export function resolveRemoteTarget(repoPath = '', remote = '') {
|
|
237
|
+
const url = String(runGit(['remote', 'get-url', remote], { cwd: repoPath }).stdout || '').trim();
|
|
238
|
+
if (!url) return null;
|
|
239
|
+
return parseGithubUrl(url) || parseGithubOwnerRepo(url) || null;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export function pushViaSsh({ repoPath = '', branch = '', force = false, remote = '' }) {
|
|
226
243
|
const keys = resolveSshKeys();
|
|
227
244
|
if (!keys.length) return { ok: false, pushed: false, reason: '无 SSH 私钥(配置目录 id_rsa/id_ed25519/id_ecdsa)' };
|
|
228
245
|
// 自动指定正确的 remote(归属 + 本机可用形态 ssh:443 + 名字优先级;必要时 set-url)——不再写死 origin
|
|
246
|
+
// 指定 remote 时以它为推送目标(多 remote / fork 场景),核验同源(liveRemoteHead 同参数)。
|
|
229
247
|
const rr = resolveGithubRemote({ repoPath });
|
|
230
|
-
|
|
248
|
+
let picked = rr.ok && rr.url ? parseGithubUrl(rr.url) : null;
|
|
249
|
+
if (remote) {
|
|
250
|
+
const byRemote = resolveRemoteTarget(repoPath, remote);
|
|
251
|
+
if (!byRemote) return { ok: false, pushed: false, reason: `指定的 remote「${remote}」不存在或不是 GitHub 地址` };
|
|
252
|
+
picked = byRemote;
|
|
253
|
+
}
|
|
231
254
|
const originUrl = runGit(['remote', 'get-url', 'origin'], { cwd: repoPath }).stdout;
|
|
232
255
|
const pr = picked || parseGithubOwnerRepo(originUrl);
|
|
233
256
|
if (!pr) {
|
|
@@ -276,10 +299,16 @@ async function apiOrFallback(api, repoPath, branch, res) {
|
|
|
276
299
|
* token 401 → pushViaSsh 回退。
|
|
277
300
|
* @returns {{ok, pushed, method?, commitSha?, reason?, branchAdjusted?}}
|
|
278
301
|
*/
|
|
279
|
-
export async function pushViaApi({ repoPath = '', branch = '', token = '', force = false } = {}) {
|
|
302
|
+
export async function pushViaApi({ repoPath = '', branch = '', token = '', force = false, remote = '' } = {}) {
|
|
280
303
|
const rr = resolveGithubRemote({ repoPath });
|
|
281
304
|
const origin = runGit(['remote', 'get-url', 'origin'], { cwd: repoPath }).stdout;
|
|
282
|
-
|
|
305
|
+
let pr = (rr.ok && rr.url ? parseGithubUrl(rr.url) : null) || parseGithubOwnerRepo(origin);
|
|
306
|
+
// 指定 remote 时以它为准(多 remote / fork 场景):推送目标与核验目标同源
|
|
307
|
+
if (remote) {
|
|
308
|
+
const remoteUrl = String(runGit(['remote', 'get-url', remote], { cwd: repoPath }).stdout || '').trim();
|
|
309
|
+
const byRemote = remoteUrl ? (parseGithubUrl(remoteUrl) || parseGithubOwnerRepo(remoteUrl)) : null;
|
|
310
|
+
if (byRemote) pr = byRemote;
|
|
311
|
+
}
|
|
283
312
|
if (!pr) {
|
|
284
313
|
return {
|
|
285
314
|
ok: false, pushed: false,
|
|
@@ -401,9 +430,12 @@ async function uploadBlobsAndBuildTree({ repoPath, entries, remoteBlobShas, api
|
|
|
401
430
|
* (ControlMaster)把 N 仓总耗时压到接近单仓。
|
|
402
431
|
* @returns {Promise<{ok:boolean, sha:string, via?:string}>}
|
|
403
432
|
*/
|
|
404
|
-
export async function liveRemoteHeadAsync({ repoPath = '', branch = '' } = {}) {
|
|
433
|
+
export async function liveRemoteHeadAsync({ repoPath = '', branch = '', remote = '' } = {}) {
|
|
405
434
|
if (process.env.DSH_GIT_PUSH_OFFLINE === '1') return { ok: false, sha: '', via: 'offline' };
|
|
406
|
-
|
|
435
|
+
// 指定 remote 时核验它(与推送同源);否则沿用 origin
|
|
436
|
+
const origin = remote
|
|
437
|
+
? (await runGitAsync(['remote', 'get-url', remote], { cwd: repoPath })).stdout
|
|
438
|
+
: (await runGitAsync(['remote', 'get-url', 'origin'], { cwd: repoPath })).stdout;
|
|
407
439
|
const pr = parseGithubOwnerRepo(origin);
|
|
408
440
|
const target = branch || (await runGitAsync(['branch', '--show-current'], { cwd: repoPath })).stdout;
|
|
409
441
|
if (!pr || !target) return { ok: false, sha: '' };
|