dsh-gufa-code 1.3.187 → 1.3.188
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/client.js +30 -2
- package/host/git.js +16 -0
- package/package.json +1 -1
- package/src/client/50-panels.js +10 -1
- package/src/client/90-app.js +19 -0
package/client.js
CHANGED
|
@@ -16,7 +16,7 @@ const GUFA_NS = 'gufa-code'
|
|
|
16
16
|
const G = {}
|
|
17
17
|
G.NS = GUFA_NS
|
|
18
18
|
/** 客户端构建标记(排查页面是否加载了新代码时看标题栏) */
|
|
19
|
-
G.BUILD = '1.3.
|
|
19
|
+
G.BUILD = '1.3.188'
|
|
20
20
|
G.PANEL_ID = 'gufa-code'
|
|
21
21
|
/** 从哪个工作区点进来的(工作区菜单/节点按钮写入,App 启动时消费)。 */
|
|
22
22
|
G.pendingEntryWorkspace = null
|
|
@@ -9037,6 +9037,15 @@ G.GitPanel = function GitPanel(props) {
|
|
|
9037
9037
|
}
|
|
9038
9038
|
}, [])
|
|
9039
9039
|
|
|
9040
|
+
/* 手动刷新:先 fetch 远端,再读 status(否则 behind 可能是 0) */
|
|
9041
|
+
const refreshRemote = useCallback(async () => {
|
|
9042
|
+
const target = rootRef.current
|
|
9043
|
+
if (target) {
|
|
9044
|
+
try { await G.api('git.fetch', { root: target }) } catch { /* 离线等失败不打扰 */ }
|
|
9045
|
+
}
|
|
9046
|
+
await refresh()
|
|
9047
|
+
}, [refresh])
|
|
9048
|
+
|
|
9040
9049
|
/* 项目变化:清空并重新拉取 */
|
|
9041
9050
|
useEffect(() => {
|
|
9042
9051
|
setStatus(null)
|
|
@@ -9226,7 +9235,7 @@ G.GitPanel = function GitPanel(props) {
|
|
|
9226
9235
|
)
|
|
9227
9236
|
: null,
|
|
9228
9237
|
h(G.IconButton, { title: t('graph.open'), onClick: () => props.onOpenGraph?.() }, h(G.Icon, { name: 'graph', size: 13 })),
|
|
9229
|
-
h(G.IconButton, { title: t('git.refresh'), disabled: pending, onClick: () => void
|
|
9238
|
+
h(G.IconButton, { title: t('git.refresh'), disabled: pending, onClick: () => void refreshRemote() }, h(G.Icon, { name: 'refresh', size: 13 })),
|
|
9230
9239
|
h(G.IconButton, {
|
|
9231
9240
|
title: t('git.more'),
|
|
9232
9241
|
onClick: (event) => {
|
|
@@ -12920,6 +12929,7 @@ G.GufaApp = function GufaApp(props) {
|
|
|
12920
12929
|
const [gitStatus, setGitStatus] = useState(null)
|
|
12921
12930
|
const gitSignatureRef = useRef('')
|
|
12922
12931
|
const gitInFlightRef = useRef(false)
|
|
12932
|
+
const gitFetchRef = useRef({ root: '', at: 0 })
|
|
12923
12933
|
const [modal, setModal] = useState(null)
|
|
12924
12934
|
const [shortcutsOpen, setShortcutsOpen] = useState(false)
|
|
12925
12935
|
const [definitionPicker, setDefinitionPicker] = useState(null)
|
|
@@ -13105,6 +13115,24 @@ G.GufaApp = function GufaApp(props) {
|
|
|
13105
13115
|
}
|
|
13106
13116
|
}, [project, refreshGit])
|
|
13107
13117
|
|
|
13118
|
+
/* 进入 Git 面板时主动 fetch 一次(限流 15s):否则 behind 只看本地 remote-tracking ref,
|
|
13119
|
+
远端新提交在 fetch 之前永远显示 0。 */
|
|
13120
|
+
useEffect(() => {
|
|
13121
|
+
if (project === null || project.isGit !== true) return undefined
|
|
13122
|
+
if (ui.sidebarOpen !== true || ui.view !== 'git') return undefined
|
|
13123
|
+
const now = Date.now()
|
|
13124
|
+
const last = gitFetchRef.current
|
|
13125
|
+
if (last.root === project.root && now - last.at < 15000) return undefined
|
|
13126
|
+
gitFetchRef.current = { root: project.root, at: now }
|
|
13127
|
+
let cancelled = false
|
|
13128
|
+
void G.api('git.fetch', { root: project.root }).then((value) => {
|
|
13129
|
+
if (cancelled || value?.ok !== true) return
|
|
13130
|
+
setGitRefreshToken((token) => token + 1)
|
|
13131
|
+
setRefreshToken((token) => token + 1)
|
|
13132
|
+
}).catch(() => {})
|
|
13133
|
+
return () => { cancelled = true }
|
|
13134
|
+
}, [project, ui.sidebarOpen, ui.view])
|
|
13135
|
+
|
|
13108
13136
|
const gitStatuses = useMemo(() => {
|
|
13109
13137
|
const map = {}
|
|
13110
13138
|
for (const change of gitStatus?.changes ?? []) map[change.path] = change.status
|
package/host/git.js
CHANGED
|
@@ -148,6 +148,22 @@ export function register(router, env) {
|
|
|
148
148
|
return { isGit: true, ...parseStatus(await git(project.root, ['status', '--porcelain=v1', '--branch', '--untracked-files=all'])) }
|
|
149
149
|
})
|
|
150
150
|
|
|
151
|
+
/* 主动 fetch:git.status 的 behind 只反映本地已知的 remote-tracking ref,
|
|
152
|
+
远端有新提交但没 fetch 时箭头永远是 0。进 Git 面板/点刷新时先 fetch。 */
|
|
153
|
+
router.method('git.fetch', async (body) => {
|
|
154
|
+
const project = await ensureRepo(env, body)
|
|
155
|
+
if (project.isGit !== true) return { ok: false, reason: 'not-git' }
|
|
156
|
+
try {
|
|
157
|
+
const remotes = (await git(project.root, ['remote']).catch(() => '')).trim()
|
|
158
|
+
.split('\n').map((line) => line.trim()).filter(Boolean)
|
|
159
|
+
const args = remotes.length > 0 ? ['fetch', '--prune', '--quiet', remotes[0]] : ['fetch', '--prune', '--quiet']
|
|
160
|
+
await git(project.root, args, 60_000)
|
|
161
|
+
return { ok: true, remote: remotes[0] ?? '' }
|
|
162
|
+
} catch (error) {
|
|
163
|
+
return { ok: false, reason: String(error?.message ?? error).slice(0, 800) }
|
|
164
|
+
}
|
|
165
|
+
})
|
|
166
|
+
|
|
151
167
|
router.method('git.stage', async (body) => {
|
|
152
168
|
const project = await projectOf(env, body)
|
|
153
169
|
const paths = Array.isArray(body.paths) ? body.paths.filter((item) => typeof item === 'string' && item !== '') : []
|
package/package.json
CHANGED
package/src/client/50-panels.js
CHANGED
|
@@ -1083,6 +1083,15 @@ G.GitPanel = function GitPanel(props) {
|
|
|
1083
1083
|
}
|
|
1084
1084
|
}, [])
|
|
1085
1085
|
|
|
1086
|
+
/* 手动刷新:先 fetch 远端,再读 status(否则 behind 可能是 0) */
|
|
1087
|
+
const refreshRemote = useCallback(async () => {
|
|
1088
|
+
const target = rootRef.current
|
|
1089
|
+
if (target) {
|
|
1090
|
+
try { await G.api('git.fetch', { root: target }) } catch { /* 离线等失败不打扰 */ }
|
|
1091
|
+
}
|
|
1092
|
+
await refresh()
|
|
1093
|
+
}, [refresh])
|
|
1094
|
+
|
|
1086
1095
|
/* 项目变化:清空并重新拉取 */
|
|
1087
1096
|
useEffect(() => {
|
|
1088
1097
|
setStatus(null)
|
|
@@ -1272,7 +1281,7 @@ G.GitPanel = function GitPanel(props) {
|
|
|
1272
1281
|
)
|
|
1273
1282
|
: null,
|
|
1274
1283
|
h(G.IconButton, { title: t('graph.open'), onClick: () => props.onOpenGraph?.() }, h(G.Icon, { name: 'graph', size: 13 })),
|
|
1275
|
-
h(G.IconButton, { title: t('git.refresh'), disabled: pending, onClick: () => void
|
|
1284
|
+
h(G.IconButton, { title: t('git.refresh'), disabled: pending, onClick: () => void refreshRemote() }, h(G.Icon, { name: 'refresh', size: 13 })),
|
|
1276
1285
|
h(G.IconButton, {
|
|
1277
1286
|
title: t('git.more'),
|
|
1278
1287
|
onClick: (event) => {
|
package/src/client/90-app.js
CHANGED
|
@@ -366,6 +366,7 @@ G.GufaApp = function GufaApp(props) {
|
|
|
366
366
|
const [gitStatus, setGitStatus] = useState(null)
|
|
367
367
|
const gitSignatureRef = useRef('')
|
|
368
368
|
const gitInFlightRef = useRef(false)
|
|
369
|
+
const gitFetchRef = useRef({ root: '', at: 0 })
|
|
369
370
|
const [modal, setModal] = useState(null)
|
|
370
371
|
const [shortcutsOpen, setShortcutsOpen] = useState(false)
|
|
371
372
|
const [definitionPicker, setDefinitionPicker] = useState(null)
|
|
@@ -551,6 +552,24 @@ G.GufaApp = function GufaApp(props) {
|
|
|
551
552
|
}
|
|
552
553
|
}, [project, refreshGit])
|
|
553
554
|
|
|
555
|
+
/* 进入 Git 面板时主动 fetch 一次(限流 15s):否则 behind 只看本地 remote-tracking ref,
|
|
556
|
+
远端新提交在 fetch 之前永远显示 0。 */
|
|
557
|
+
useEffect(() => {
|
|
558
|
+
if (project === null || project.isGit !== true) return undefined
|
|
559
|
+
if (ui.sidebarOpen !== true || ui.view !== 'git') return undefined
|
|
560
|
+
const now = Date.now()
|
|
561
|
+
const last = gitFetchRef.current
|
|
562
|
+
if (last.root === project.root && now - last.at < 15000) return undefined
|
|
563
|
+
gitFetchRef.current = { root: project.root, at: now }
|
|
564
|
+
let cancelled = false
|
|
565
|
+
void G.api('git.fetch', { root: project.root }).then((value) => {
|
|
566
|
+
if (cancelled || value?.ok !== true) return
|
|
567
|
+
setGitRefreshToken((token) => token + 1)
|
|
568
|
+
setRefreshToken((token) => token + 1)
|
|
569
|
+
}).catch(() => {})
|
|
570
|
+
return () => { cancelled = true }
|
|
571
|
+
}, [project, ui.sidebarOpen, ui.view])
|
|
572
|
+
|
|
554
573
|
const gitStatuses = useMemo(() => {
|
|
555
574
|
const map = {}
|
|
556
575
|
for (const change of gitStatus?.changes ?? []) map[change.path] = change.status
|