utopia-ia/elffuss-code public
Changesets · Branches · Tags · Compare
| Changeset | 21d6a5c0c0992dd9388ecc39733128bafa59379d16236fbfe6a8c978d1ddf568 |
|---|---|
| Author | KikoCis <kikocisneros@gmail.com> · 2026-10-10 16:38 +02:00 |
| Committer | KikoCis <kikocisneros@gmail.com> · 2026-10-11 14:15 +02:00 |
| Parents | e7ee0f72085f |
2 files changed
modified web/js/shell.js +2 −1
| @@ -278,7 +278,8 @@ | ||
| 278 | 278 | if (!info.isRepo) return DIM('no es un repositorio git (no hay .git)'); |
| 279 | 279 | if (sub === 'branch' || !sub) return '* ' + GRN(info.branch); |
| 280 | 280 | if (sub === 'status') return `En la rama ${GRN(info.branch)}\n` + (info.lastCommit ? DIM(`último commit: ${info.lastCommit.msg}`) : DIM('sin commits todavía')) + '\n' + DIM('(git de solo lectura aquí; commit/push reales no disponibles todavía)'); |
| 281 | - if (sub === 'log') return info.lastCommit ? `${YEL('commit ' + info.branch)}\nAutor: ${info.lastCommit.author}\nFecha: ${new Date(info.lastCommit.when).toLocaleString()}\n\n ${info.lastCommit.msg}` : DIM('sin commits'); | |
| 281 | + // El SHA de verdad (antes ponía «commit <rama>», que no es un commit). | |
| 282 | + if (sub === 'log') return info.lastCommit ? `${YEL('commit ' + (info.lastCommit.sha || '?'))} ${DIM('(' + info.branch + ')')}\nAutor: ${info.lastCommit.author}\nFecha: ${new Date(info.lastCommit.when).toLocaleString()}\n\n ${info.lastCommit.msg}` : DIM('sin commits'); | |
| 282 | 283 | return DIM(`git ${sub}: de solo lectura aquí (branch/status/log).`); |
| 283 | 284 | }, |
| 284 | 285 | }; |
modified web/js/tools/code.js +35 −5
| @@ -19,26 +19,56 @@ | ||
| 19 | 19 | return (await (await dir.getFileHandle(name)).getFile()).text(); |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | -// Integración git SIN dependencias: parsea el .git directamente (rama + último | |
| 23 | -// commit). Suficiente para orientar; commitear se le pide al agente/terminal. | |
| 22 | +// Integración git SIN dependencias: parsea el .git directamente (rama, último | |
| 23 | +// commit con su SHA y el remoto «origin»). Suficiente para orientar; commitear | |
| 24 | +// se le pide al agente/terminal. | |
| 24 | 25 | export async function gitInfo() { |
| 25 | 26 | if (!projectHandle) return { isRepo: false }; |
| 26 | 27 | let git; |
| 27 | 28 | try { git = await projectHandle.getDirectoryHandle('.git'); } |
| 28 | 29 | catch { return { isRepo: false }; } |
| 29 | - const out = { isRepo: true, branch: '(detached)', lastCommit: null }; | |
| 30 | + const out = { isRepo: true, branch: '(detached)', lastCommit: null, web: null }; | |
| 30 | 31 | try { |
| 31 | 32 | const head = (await readIn(git, 'HEAD')).trim(); |
| 32 | 33 | out.branch = head.match(/ref:\s*refs\/heads\/(.+)/)?.[1] || head.slice(0, 7); |
| 33 | 34 | } catch { /* sin HEAD */ } |
| 34 | 35 | try { |
| 36 | + // «<viejo> <nuevo> Autor <correo> <ts> <tz>\t<mensaje>»: el SHA del commit | |
| 37 | + // es el SEGUNDO campo (antes se tiraba). El correo no se guarda: no se enseña. | |
| 35 | 38 | const last = (await readIn(git, 'logs/HEAD')).trim().split('\n').pop(); |
| 36 | - const m = last.match(/^\S+ \S+ (.+?) <[^>]*> (\d+)[^\t]*\t(.+)$/); | |
| 37 | - if (m) out.lastCommit = { author: m[1], when: new Date(+m[2] * 1000), msg: m[3] }; | |
| 39 | + const m = last.match(/^\S+ (\S+) (.+?) <[^>]*> (\d+)[^\t]*\t(.+)$/); | |
| 40 | + if (m) out.lastCommit = { sha: /^[0-9a-f]{7,64}$/i.test(m[1]) ? m[1] : null, author: m[2], when: new Date(+m[3] * 1000), msg: m[4] }; | |
| 38 | 41 | } catch { /* sin logs (repo recién creado) */ } |
| 42 | + try { out.web = remoteWeb(await readIn(git, 'config')); } catch { /* sin config */ } | |
| 39 | 43 | return out; |
| 40 | 44 | } |
| 41 | 45 | |
| 46 | +// La URL web del remoto «origin», SIN credenciales (https://usuario:token@… | |
| 47 | +// no puede acabar en un enlace) y con los enlaces de rama y commit según el | |
| 48 | +// tipo de forja. null si no hay remoto o no es http(s)/ssh reconocible. | |
| 49 | +export function remoteWeb(config) { | |
| 50 | + const sec = String(config || '').split(/^\s*\[/m).find(b => /^remote\s+"origin"\s*\]/.test(b)); | |
| 51 | + const raw = sec?.match(/^\s*url\s*=\s*(\S+)/m)?.[1]; | |
| 52 | + if (!raw) return null; | |
| 53 | + let host, path; | |
| 54 | + const ssh = raw.match(/^(?:ssh:\/\/)?[\w.-]+@([\w.-]+)(?::\d+)?[:/](.+)$/); | |
| 55 | + if (/^https?:\/\//i.test(raw)) { | |
| 56 | + try { const u = new URL(raw); host = u.hostname; path = u.pathname; } catch { return null; } | |
| 57 | + } else if (ssh) { host = ssh[1]; path = ssh[2]; } | |
| 58 | + else return null; | |
| 59 | + path = path.replace(/^\/+/, '').replace(/\.git\/?$/, '').replace(/\/+$/, ''); | |
| 60 | + if (!host || !/^[\w.-]+\/[\w.\-/]+$/.test(path)) return null; | |
| 61 | + const base = `https://${host}/${path}`; | |
| 62 | + const kind = /(^|\.)github\.com$/i.test(host) ? 'github' : /(^|\.)gitlab\.com$/i.test(host) ? 'gitlab' | |
| 63 | + : /(^|\.)bitbucket\.org$/i.test(host) ? 'bitbucket' : 'gitea'; | |
| 64 | + const enc = s => String(s).split('/').map(encodeURIComponent).join('/'); | |
| 65 | + return { | |
| 66 | + base, kind, | |
| 67 | + branch: b => kind === 'gitea' ? `${base}/src/branch/${enc(b)}` : kind === 'bitbucket' ? `${base}/src/${enc(b)}` : kind === 'gitlab' ? `${base}/-/tree/${enc(b)}` : `${base}/tree/${enc(b)}`, | |
| 68 | + commit: sha => kind === 'bitbucket' ? `${base}/commits/${sha}` : kind === 'gitlab' ? `${base}/-/commit/${sha}` : `${base}/commit/${sha}`, | |
| 69 | + }; | |
| 70 | +} | |
| 71 | + | |
| 42 | 72 | // Lista plana de archivos (para el command palette). Cacheada por proyecto. |
| 43 | 73 | let fileListCache = null; |
| 44 | 74 | export function invalidateFileList() { fileListCache = null; } |