UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

2 lines • 2.51 kB
import{a as e}from"./git-operation.worker-errors-BicYkIHf.mjs";import{c as t,p as n,s as r}from"./git-operation.worker-git-TpQcAIgG.mjs";import{Jt as i,en as a,hn as o}from"./git-operation.worker.js";import{t as s}from"./git-operation.worker-preparation-timing-B0hOiKBf.mjs";import c from"node:fs/promises";import{createHash as l}from"node:crypto";async function resolveCheckoutRootFromRealPath(r,i){let o=await t(r,[`rev-parse`,`--show-toplevel`,`--verify`,`HEAD^{commit}`]);if(o.code!==0){if(o.termination===`exit`&&o.stdout.trim()){let n=await t(r,[`symbolic-ref`,`--quiet`,`HEAD`]),a=n.stdout.trim();if(n.termination===`exit`&&n.code===0&&!n.stderr.trim()&&a.startsWith(`refs/heads/`)){let n=await t(r,[`show-ref`,`--verify`,`--quiet`,a]);if(n.termination===`exit`&&n.code===1&&!n.stderr.trim())throw new e(`git checkout has no commits: ${i}. Create an initial commit, then retry.`,{reason:`unborn`})}}throw await n(r)?Error(`Git metadata is unavailable for ${r}; checkout preserved. Restore the original repository metadata, then use git worktree repair from that repository. Do not recreate its index or delete the checkout to bypass recovery.`):new e(`not a git checkout: ${i}`)}let s=o.stdout.replace(/\n$/,``),l=s.lastIndexOf(` `),u=l<0?``:s.slice(0,l);if(!u)throw new e(`not a git checkout: ${i}`);return{root:await c.realpath(a(u))}}async function resolveRepositoryPathsFromRealPath(e,t){let{root:n}=await resolveCheckoutRootFromRealPath(e,t);return{sourceRoot:n,...await r(n)}}async function resolveRepositoryFromRealPath(e,n){return o(`repository.identities`,async()=>{let{sourceRoot:r,canonicalRoot:a,commonDir:o}=await resolveRepositoryPathsFromRealPath(e,n),s=await t(a,[`config`,`--get`,`remote.origin.url`]);if(s.termination!==`exit`||s.code!==0&&s.code!==1)throw i(`git config --get remote.origin.url`,s);let c=s.code===0?s.stdout.trim():``;return{repoRoot:a,sourceRoot:r,commonDir:o,originUrl:c,fingerprint:l(`sha256`).update(`${o}\n${c}`).digest(`hex`).slice(0,16)}},`default`)}async function withRepositoryRealPath(e,t){return await s(`repository`,async()=>await t(await c.realpath(e).catch(()=>{throw Error(`repository does not exist: ${e}`)}),e))}function resolveRepository(e){return withRepositoryRealPath(e,resolveRepositoryFromRealPath)}async function resolveRepositoryIdentity(e){let t=await resolveRepository(e);return{checkoutRoot:t.sourceRoot,repoRoot:t.repoRoot,originUrl:t.originUrl,fingerprint:t.fingerprint}}export{resolveCheckoutRootFromRealPath,resolveRepositoryIdentity};