(()=>{"use strict";var t={};const e=require("fs/promises"),a=require("path");async function r(t){const s=[];try{const n=await e.readdir(t,{withFileTypes:!0});for(const e of n){const n=a.join(t,e.name);if(e.isDirectory()){const t=await r(n);s.push(...t)}else s.push(n)}}catch{}return s}async function s(t){try{const r=a.join(t,".git","HEAD"),s=await e.readFile(r,"utf-8");if(s.startsWith("ref: ")){const r=s.slice(5).trim(),n=a.join(t,".git",r);return(await e.readFile(n,"utf-8")).trim()}return s.trim()}catch{return null}}async function n(t){try{const r=a.join(t,".git","HEAD"),s=await e.readFile(r,"utf-8");return s.startsWith("ref: ")?s.slice(5).trim().replace("refs/heads/",""):null}catch{return null}}async function i(t){try{const e=a.join(t,".git","refs","heads");return(await r(e)).map(t=>t.replace(e+a.sep,""))}catch{return[]}}async function c(t){try{const e=a.join(t,".git","refs","tags");return(await r(e)).map(t=>t.replace(e+a.sep,""))}catch{return[]}}async function o(t){try{const s=a.join(t,".git","refs","remotes"),n=await r(s),i=[];for(const t of n){const r=await e.readFile(t,"utf-8"),n=t.replace(s+a.sep,"");i.push([n,r.trim()])}return i}catch{return[]}}async function u(t){try{const r=a.join(t,".git","refs","remotes","origin","HEAD");try{const t=await e.readFile(r,"utf-8");if(t.startsWith("ref: "))return t.slice(5).trim().replace("refs/remotes/origin/","")}catch{}const s=a.join(t,".git","config"),n=(await e.readFile(s,"utf-8")).match(/\[init\]\s*\n\s*defaultBranch\s*=\s*(.+)/);if(n)return n[1].trim();const c=await i(t);return c.includes("main")?"main":c.includes("master")?"master":null}catch{return null}}async function l(t){try{const r=a.join(t,".git","FETCH_HEAD");return(await e.readFile(r,"utf-8")).split("\n")[0]}catch{return null}}async function f(t){try{const r=a.join(t,".git","refs","stash");return(await e.readFile(r,"utf-8")).trim()}catch{return null}}async function h(t){try{return await e.stat(t),!0}catch{return!1}}process.on("message",async t=>{const r=await async function(t){try{let r;switch(t.type){case"getRepoState":r=await async function(t){const[e,a,r,h,w,p,g,m]=await Promise.all([s(t),n(t),u(t),i(t),c(t),o(t),l(t),f(t)]);return{commitHash:e,currentBranch:a,defaultBranch:r,branches:h,tags:w,remoteRefs:p,fetchHead:g,stashHash:m}}(t.workspacePath);break;case"getBranches":r=await i(t.workspacePath);break;case"getTags":r=await c(t.workspacePath);break;case"getRemoteRefs":r=await o(t.workspacePath);break;case"getCurrentCommitHash":r=await s(t.workspacePath);break;case"getCurrentBranch":r=await n(t.workspacePath);break;case"getDefaultBranch":r=await u(t.workspacePath);break;case"getFetchHead":r=await l(t.workspacePath);break;case"getStashHash":r=await f(t.workspacePath);break;case"isRebasing":r=await async function(t){const e=a.join(t,".git","rebase-merge"),r=a.join(t,".git","rebase-apply"),[s,n]=await Promise.all([h(e),h(r)]);return s||n}(t.workspacePath);break;case"fileExists":r=await h(t.args?.filePath);break;case"getRemoteUrl":r=await async function(t,r="origin"){try{const s=a.join(t,".git","config"),n=await e.readFile(s,"utf-8"),i=`[remote "${r}"]`,c=n.indexOf(i);if(-1===c)return null;const o=n.slice(c).match(/\s*url\s*=\s*(.+)$/m);return o&&o[1]?o[1].trim():null}catch{return null}}(t.workspacePath,t.args?.remoteName);break;default:{const e=t.type;throw new Error(`Unknown request type: ${e}`)}}return{id:t.id,success:!0,result:r}}catch(e){return{id:t.id,success:!1,error:e instanceof Error?e.message:String(e)}}}(t);process.send?.(r)}),process.send?.({type:"ready"});var w=exports;for(var p in t)w[p]=t[p];t.__esModule&&Object.defineProperty(w,"__esModule",{value:!0})})();
//# sourceMappingURL=http://go/sourcemap/sourcemaps/aac81804b986d739acab348ed96b8bea6e83cc50/extensions/cursor-always-local/dist/gitWorker.js.map