bisgit 0.7.0 → 0.8.0
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
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
<img alt="biscuit with jelly" src="https://github.com/alexanderdombroski/bisgit/blob/main/public/bisgit.png" width="200px" />
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Run `gi` or `bisgit` for full TUI.
|
|
6
6
|
|
|
7
7
|
## Commands
|
|
8
8
|
|
|
@@ -19,7 +19,7 @@ Full Tui coming soon
|
|
|
19
19
|
- `gi conflict <branch>` shows all conflicts that would occur in a merge.
|
|
20
20
|
- `gi abort` and `gi continue` are useful in conflict resolution situations.
|
|
21
21
|
- `gi files <ref>` shows files of the commit or stash.
|
|
22
|
-
- `gi lines <ref> <ref?>` shows the number of lines changed.
|
|
22
|
+
- `gi lines <ref> <ref?>` shows the number of lines changed. Use `-v` for verbose output.
|
|
23
23
|
|
|
24
24
|
### Branching
|
|
25
25
|
|
|
@@ -33,7 +33,7 @@ Full Tui coming soon
|
|
|
33
33
|
- `gi code-review <pr>` checks out a pr and creates a diff similar to github's code review diff viewer.
|
|
34
34
|
- `gi whoami` shows github username.
|
|
35
35
|
- `gi languages` prints the percentages of languages for this repo.
|
|
36
|
-
- `gi coauthor <username
|
|
36
|
+
- `gi coauthor <username?>` commits with a co-authorship description.
|
|
37
37
|
|
|
38
38
|
### Utility
|
|
39
39
|
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{b as g,c as X,d as at,e as R,f as w,g as V,h as A,i as N,j as U,k as ct,l as y,m as S}from"./chunk-HKY7QTE6.js";import{a as C,d as h,e as tt,f as W,g as G,h as k,i as et,j as ot,k as rt,m as I,n as x,o as M,p as P,q as it,r as nt,s as F,t as st,w as H,x as L}from"./chunk-7XT4D6II.js";import{a as b,b as s,c as E,d,e as f}from"./chunk-R7DNYVL6.js";import B from"node:path";async function mt(){let t=await M(),e=/^(UU|DU|UD)/;return!!t?.some(o=>e.test(o))}async function j(){let t=await et(),[e,o,r,i,n]=await Promise.all([await C(B.join(t,"MERGE_HEAD")),await C(B.join(t,"rebase-merge")),await C(B.join(t,"rebase-apply")),await C(B.join(t,"CHERRY_PICK_HEAD")),await C(B.join(t,"REVERT_HEAD"))]);return{merge:e,rebaseMerge:o,rebaseApply:r,cherryPick:i,revert:n}}async function lt(){let{merge:t,rebaseMerge:e,rebaseApply:o,cherryPick:r,revert:i}=await j(),n="";if(t)n="merge";else if(e||o)n="rebase";else if(r)n="cherry-pick";else if(i)n="revert";else{let a=await mt()?"Conflicts exist, but likely are from a stash and are not abortable. Resolve them manually.":"Nothing to abort.";console.log(a);return}console.log(`Aborting the ${n}`),await f([n,"--abort"])}async function ft(){await U(),await S(),b("git",["commit","--amend","--no-edit",...g()],{stdio:"inherit",silent:!0,triggerExit:!0})}import{render as re}from"ink";import{render as ee}from"ink";import{Suspense as zt,use as Jt,useEffect as Kt}from"react";import{Text as pt,useApp as Zt}from"ink";import Qt from"ink-spinner";import{jsx as O,jsxs as te}from"react/jsx-runtime";function m(t){let{msg:e}=t;return O(zt,{fallback:te(pt,{children:[O(Qt,{type:"dots"}),"\xA0",e]}),children:O(Xt,{...t})})}function Xt({msg:t,promise:e}){let o=Jt(e),{exit:r}=Zt();return Kt(()=>{r()},[o]),O(pt,{children:`\u2714 ${typeof o=="string"?o:t}`})}import{jsx as oe}from"react/jsx-runtime";async function gt(){let t=process.argv[3],e=process.argv[4]??await h();if(V(t),V(e),t===e)return console.log(`No reason to merge '${t}' into '${e}'`);let o=await tt(t);w(o),ee(oe(m,{msg:"Updating target branch and merging",promise:(async()=>{try{await T(o,t)}catch{console.error(`Error when updating branch ${t} with remote ${o}. Fix divergent branches before merging into ${e}`);return}await h()!==e&&await s(`git switch ${e}`),b("git",["merge",t],{stdio:"inherit",silent:!0})})()}))}async function T(t,e){await I(t,e);let[o,r,i]=await Promise.all([W(t,e),G(t,e),h()]);if(r!==0){if(o===0&&i!==e){await s(`git fetch ${t} ${e}:${e}`);return}if(await s(`git switch ${e}`),o===0){await s(`git merge ${t}/${e}`);return}await f(["merge",`${t}/${e}`],["ignore","ignore","inherit"])}}async function q(){R(),w();let{stdout:t,code:e}=await d("git",["rev-parse","--abbrev-ref","origin/HEAD"]);if(e===0)return ut(t.trim());await s("git remote set-head origin -a");let{stdout:o}=await s("git rev-parse --abbrev-ref origin/HEAD");return ut(o.trim())}async function dt(){let{remote:t,branch:e}=await q();console.log(`Remote default branch is '${t}/${e}'`)}async function ut(t){let e=t.split("/"),o=t.split("/").map((r,i)=>e.slice(0,i+1).join("/"));for(let r of o)if(await rt(r)){let i=t.slice(r.length+1);return{remote:r,branch:i}}throw new Error("Failed to get default remote")}import{jsx as ne}from"react/jsx-runtime";var ie=["master","main","development","lingoport"];async function ht(){await A();let{branch:t,remote:e}=await q();await s(`git switch ${t}`);let o=(async()=>{await f(["fetch","--prune","--prune-tags"]),await T(e,t)})();re(ne(m,{msg:"Fetching and pruning remote references",promise:o})),await o;let r=await st();for(let i of r){if(i===t||ie.includes(i))continue;let{code:n}=await d("git",["diff","--quiet",t,i]);if(n===0){Y(i);continue}let{code:a}=await d("git",["merge-base","--is-ancestor",i,t]);if(a===0){Y(i);continue}let c=await P(i,t),{stdout:l}=await d("git",["merge-tree",c,t,i]);l?.trim()||Y(i)}}function Y(t){f(["branch","-D",t])}import{spawn as se}from"node:child_process";import{createInterface as ae}from"node:readline/promises";async function wt(){R;let e=[...(await ce()).entries()].sort(([,r],[,i])=>i-r).slice(0,25),o=e[0][1].toString().length;console.info(e.map(([r,i])=>`${String(i).padEnd(o)} ${r}:`).join(`
|
|
3
|
+
`))}async function ce(){let{promise:t,resolve:e,reject:o}=Promise.withResolvers(),r=new Map,i=se("git",["log","--all","-M","-C","--name-only","--format=format:"]),n=ae({input:i.stdout,crlfDelay:1/0});return n.on("line",a=>{let c=a.trim();c&&r.set(c,(r.get(c)??0)+1)}),n.on("close",()=>e(r)),i.on("error",o),t}import{render as bt}from"ink";import{Box as me,Text as le,useApp as fe,useInput as pe}from"ink";import ge from"ink-select-input";import{jsx as yt,jsxs as ue}from"react/jsx-runtime";function $t({prompt:t,onSelect:e,items:o}){let{exit:r}=fe();return pe((i,n)=>{n.escape&&r()}),ue(me,{flexDirection:"column",children:[yt(le,{children:t}),yt(ge,{items:o,onSelect:e})]})}import{jsx as xt}from"react/jsx-runtime";async function Pt(){await S();let t=g()[0];if(!t){let n=(await he()).map(c=>({value:c,label:`${c.name} ${c.email} (${c.commits})`}));bt(xt($t,{items:n,prompt:"Who assisted in this commit?",onSelect:({value:{name:c,email:l}})=>{Ct(c,l.slice(1,-1))}}));return}let e=(async()=>{let i=await de(t);return i.email||(console.error(`Couldn't find an email for ${t}`),process.exit(1)),i})();bt(xt(m,{msg:"Fetching name and email",promise:e}));let{name:o,email:r}=await e;Ct(o,r)}async function de(t){let{stdout:e}=await s(`gh api users/${t}`);return JSON.parse(e.trim())}async function he(){let t=await E('git log --format="%an|<%ae>"'),e=new Map;for(let o of t){let[r,i]=o.split("|"),n=`${r}|${i}`;e.has(n)||e.set(n,{name:r,email:i,commits:0}),e.get(n).commits+=1}return[...e.values()].toSorted((o,r)=>r.commits-o.commits)}async function Ct(t,e){f(["commit","--edit","-m","<insert summary>","-m",`Co-authored-by: ${t} <${e}>`])}import{render as z}from"ink";import{isDeepStrictEqual as we}from"node:util";import{jsx as J}from"react/jsx-runtime";async function Rt(){let t=y("Error: missing id of PR to checkout");await A();let e=(async()=>Promise.all([s(`gh co ${t}`),s(`gh pr view ${t} --json baseRefName -q .baseRefName`)]))();z(J(m,{msg:`Checking out pr #${t}`,promise:e}));let[,{stdout:o}]=await e,r=o.trim(),i=(async()=>{await s(`git switch ${r}`),await s("git pull"),await s("git switch -")})();z(J(m,{msg:`Updating ${r} branch merge destination`,promise:i})),await i;let n=(async()=>{let p=await P(r,"HEAD");return await s(`git reset ${p} --soft`),await ye("HEAD")})();z(J(m,{msg:"Creating an editable, explorable, local PR experience",promise:n}));let[a,c]=await Promise.all([n,$e(t)]),{files:l,additions:u,deletions:D}=c;if(we(a,c))return console.info(`Files: ${l}, +${u} -${D}`);console.info("The PR stat doesn't match the local stat."),console.info("LOCAL"),console.table(a),console.info("GITHUB"),console.table(c),console.info("One option to fix (there'll likely be conflicts):"),console.info("1. git stash -u"),console.info(`2. git merge ${r}`),console.info("3. git stash pop")}async function ye(t){let{stdout:e}=await s(`git diff --shortstat ${t}`),o=/(\d+)\s+files? changed(?:, (\d+) insertions?\(\+\))?(?:, (\d+) deletions?\(-\))?/,r=e.trim().match(o);if(!r)throw new Error(`Couldn't generate short stat for ref(s): ${t}`);let[,i,n,a]=r;return{files:parseInt(i,10),additions:n?parseInt(n,10):0,deletions:a?parseInt(a,10):0}}async function $e(t){let{stdout:e}=await s(`gh pr view ${t} --json deletions,files,additions`),o=JSON.parse(e.trim());return o.files=o.files.length,o}import{spawn as be}from"node:child_process";import{createInterface as Ce}from"node:readline/promises";import K from"chalk";async function At(){let t=y("Error: missing target branch argument"),e=await P("HEAD",t),{promise:o,resolve:r,reject:i}=Promise.withResolvers(),n=be("git",["merge-tree",e,"HEAD",t]),a=Ce({input:n.stdout,crlfDelay:1/0}),c=!1,l=0;a.on("line",p=>{p=p.trimEnd(),p==="+<<<<<<< .our"?(c=!0,console.info(K.red(p)),l+=1):p==="+>>>>>>> .their"?(c=!1,console.info(K.green(p))):p==="+======="?console.info(K.yellow(p)):c&&console.info(p)}),a.on("close",()=>r(l)),n.on("error",i);let u=await o,D=u?`\u274C ${u} conflicts would occur!`:"\u2705 No conflicts. Safe to merge.";console.info(D)}async function St(){let{merge:t,rebaseMerge:e,rebaseApply:o,cherryPick:r,revert:i}=await j(),n="";if(t)n="merge";else if(e||o)n="rebase";else if(r)n="cherry-pick";else if(i)n="revert";else{console.log("Nothing to continue.");return}console.log(`Continuing the ${n}`),await f([n,"--continue"])}import{appendFileSync as Pe}from"node:fs";import{readFile as xe}from"node:fs/promises";async function _(t){return(await xe(t,"utf-8")).split(/\r?\n/).map(o=>o.trim()).filter(o=>o&&!o.startsWith("#"))}async function vt(){let t=await k("info/exclude");await N(t);let e=await _(t);g().forEach(o=>{e.includes(o)?console.info(`Already Exists: '${o}'`):(Pe(t,`${o}
|
|
4
|
+
`),console.info(`Added '${o}'`))}),console.info(`
|
|
5
|
+
See file at ${t}`)}async function Dt(){let t=g();if(t[0]){let e=await Re(t[0]);console.info(e.join(`
|
|
6
|
+
`))}else f(["status","--short"])}async function Re(t){return L(t)?await E(`git stash show -p --include-untracked --name-only ${t}`):await E(`git show --name-only --pretty=format:"" ${t}`)}import{spawn as Ae}from"node:child_process";async function Et(){let t=y("Error: missing valid target ref argument");await S();let e=await nt(t);await f(["commit",`--fixup=${e}`]);let r=(await F(`${e}^`,"HEAD",!0)).map(n=>Se(n));(await Promise.all(r)).every(Boolean)||(console.warn("Rebase conflict would occur!"),await s("git reset HEAD~1 --soft"),process.exit(1)),await s(`git rebase -i --autosquash ${e}^`)}async function Se(t){let{stdout:e}=await s(`git diff ${t}^ ${t}`),{promise:o,resolve:r,reject:i}=Promise.withResolvers(),n=Ae("git",["apply","--check","--3way","-q"],{stdio:["pipe","ignore","ignore"]});return n.on("close",a=>{r(a===0)}),n.on("error",i),n.stdin.write(e),n.stdin.end(),o}import{readFile as ve,writeFile as De}from"node:fs/promises";async function kt(){let t=await k("info/exclude");await N(t);let e=await _(t),o=g();o.filter(a=>!e.includes(a)).forEach(a=>console.info(`No match: '${a}'`));let i=(await ve(t,"utf-8")).split(/\r?\n/).map(a=>a.trim()),n=i.filter(a=>!o.includes(a));await De(t,n.join(`
|
|
7
|
+
`)),console.info(`
|
|
8
|
+
Removed ${i.length-n.length} entries from ${t}`)}import{render as Ee}from"ink";import{jsx as qe}from"react/jsx-runtime";async function Bt(){let t=(async()=>{let i=await ke();return await Be(i)})();Ee(qe(m,{msg:"Fetching repo languages",promise:t}));let e=await t,o=Object.values(e).reduce((i,n)=>i+n,0),r=Object.entries(e).map(([i,n])=>`${i}: ${Math.round(n/o*100)}% - ${Te(n)}`);console.log(r.join(`
|
|
9
|
+
`))}async function ke(){let{stdout:t}=await s("gh repo view --json nameWithOwner -q .nameWithOwner");return t.trim()}async function Be(t){let{stdout:e}=await s(`gh api repos/${t}/languages`);return JSON.parse(e.trim())}function Te(t,e=2){if(t===0)return"0 B";let o=1024,r=e<0?0:e,i=["B","KB","MB","GB","TB","PB","EB","ZB","YB"],n=Math.floor(Math.log(t)/Math.log(o));return`${parseFloat((t/Math.pow(o,n)).toFixed(r))} ${i[n]}`}import $ from"chalk";async function Tt(){y();let t=g(),[e,o]=t.filter(i=>i!=="-v"),r=[];if(L(e)?(r.push(...await H(`${e}^3`)),r.push(...await H(`${e}^2`))):r.push(...await H(e,o)),t.includes("-v")){let i={added:"A",modified:"M",deleted:"D",binary:"B"};r.forEach(n=>{let c=`${We(n.changeType)(i[n.changeType])} ${n.file} |`;n.added&&(c+=$.green(` +${n.added}`)),n.deleted&&(c+=$.red(` -${n.deleted}`)),console.info(c)})}else{let i=new Set(r.map(({file:u})=>u)).size,[n,a]=r.reduce((u,{added:D,deleted:p})=>[u[0]+(D??0),u[1]+(p??0)],[0,0]),c=$.green(`+${n}`),l=$.red(`-${a}`);console.info(`${i} files: ${c} ${l}`)}}var We=t=>{switch(t){case"modified":return $.yellow;case"added":return $.green;case"deleted":return $.red;default:return e=>e}};async function qt(){let t=await ot();console.log(t)}import{render as Gt}from"ink";function Wt(){return new Date().toLocaleString("en-US",{year:"2-digit",month:"2-digit",day:"2-digit",hour:"numeric",minute:"2-digit",hour12:!0}).replace(",","")}async function v(){let t=Wt();await s("git add -A"),await f(["commit","-m",`"WIP ${t}"`])}import{nanoid as Ge}from"nanoid";import Ie from"chalk";import{jsx as It}from"react/jsx-runtime";async function Mt(){let{remote:t,branch:e}=await q(),o=process.argv[3]??e;await x()||await v(),await it(o,"HEAD")||(console.warn("Conflicts would occur. Not safe to rebranch."),process.exit(1));let r=await h(),i=(async()=>{await T(t,o)})();Gt(It(m,{msg:`Updating branch ${o}`,promise:i})),await i;let n=`${Ge(8)}`,a=(async()=>{await s(`git switch ${r}`),await s(`git branch ${n}`),await s(`git switch ${o}`),await s(`git branch -D ${r}`),await s(`git switch -c ${r}`);let c=await F(o,n,!0);for(let l of c)try{await s(`git cherry-pick ${l}`)}catch{let u=Ie.yellow(`git branch -D ${r} && git branch -m ${n} ${r}`);throw new Error(`\u274C cherry pick failed at ${l}
|
|
10
|
+
Run this to restore backup branch
|
|
11
|
+
> ${u}`)}await s(`git branch -D ${n}`)})();Gt(It(m,{msg:`Rewriting branch ${r}`,promise:a})),await a,console.info(`Successfully recreated branch ${r} from ${o}`)}import{execSync as Me}from"node:child_process";async function Ft(){R();let t=Fe(process.argv[3]),{default:e}=await import("clipboardy");await e.write(t),console.log(`'${t}' copied to clipboard`)}function Fe(t="HEAD"){return Me(`git rev-parse --short ${t}`,{encoding:"utf-8"}).trim()}import{render as He}from"ink";import{jsx as Le}from"react/jsx-runtime";async function Ht(){let{remote:t,branch:e}=await X();w(t),await A();let o=I(t,e);He(Le(m,{msg:`Fetching branch ${e} from ${t}`,promise:o})),await o,await f(["switch","-c",e,"--track",`${t}/${e}`])}async function Z(){let{stdout:t}=await s("npm list -g bisgit --depth=0 --json");return JSON.parse(t.trim()).dependencies.bisgit.version}async function Lt(){console.info(await Z())}async function Ne(){let{code:t}=await d("npm",["outdated","-g","bisgit"]);return t===0}async function Ue(){let{stdout:t}=await s("npm view bisgit version",{encoding:"utf8"});return t.trim()}async function Nt(){if(await Ne())return console.info("Already up to date");console.info(`Updating: ${await Z()} -> ${await Ue()}`),b("npm",["i","-g","bisgit@latest"])}async function Ut(){let[t,e]=await Promise.allSettled([await Oe("user.name"),await je()]);t.status==="fulfilled"&&console.info(`Git: ${t.value}`),e.status==="fulfilled"&&console.info(`Github: ${e.value}`)}async function je(){let{stdout:t}=await s("gh api user --jq .login");return t.trim()}async function Oe(t){let{stdout:e}=await s(`git config ${t}`);return e.trim()}import{render as Ze}from"ink";import{Text as _e,useApp as Ve,useInput as Ye}from"ink";import{useState as ze}from"react";import{Fragment as Ke,jsx as Je,jsxs as jt}from"react/jsx-runtime";function Ot({prompt:t,msg:e,onConfirm:o}){let[r,i]=ze(""),{exit:n}=Ve();return Ye((a,c)=>{if(r)return;let l=a.toLowerCase();l==="y"?i("Yes"):(l==="n"||c.return)&&(i("No"),n())}),jt(Ke,{children:[jt(_e,{children:[t," [y/N] ",r]}),r==="Yes"&&Je(m,{msg:e,promise:o()})]})}import{jsx as Qe}from"react/jsx-runtime";async function _t(){if(at(),await x())return console.log("Already a clean working tree");let t=await M();if(!t)throw new Error("git status cmd failed");let e=new Q(t);e.displayReport(),Ze(Qe(Ot,{prompt:"Approve these changes?",msg:"Running git reset && git clean",onConfirm:async()=>(await s("git reset --hard"),await s("git clean -f"),`Altered ${e.willDelete.length+e.willRecreate.length+e.willRevert.length} files.`)}))}var Q=class{willDelete=[];willRecreate=[];willRevert=[];constructor(e){e.forEach(o=>{if(o){let r=o.slice(0,2).trim(),i=o.slice(3);r.includes("?")||r.includes("A")?this.willDelete.push(i):r==="DU"||r==="D"?this.willRecreate.push(i):this.willRevert.push(i)}}),this.willDelete.sort(),this.willRecreate.sort(),this.willRevert.sort()}displayReport(){this.displaySection("Will Recreate:",this.willRecreate),this.displaySection("Will Revert:",this.willRevert),this.displaySection("Will Delete:",this.willDelete)}displaySection(e,o){o.length&&console.log(`${e}
|
|
12
|
+
${o.map(r=>`- ${r}`).join(`
|
|
13
|
+
`)}`)}};import{nanoid as Xe}from"nanoid";import{render as to}from"ink";import{jsx as eo}from"react/jsx-runtime";async function Vt(){await U();let t=process.argv[3]??"origin";w(t);let e=await h();ct(e);let o="",i=(async()=>{let n=[s(`git fetch ${t} ${e} --force`)];await x()||n.push(v()),await Promise.all(n);let[a,c]=await Promise.all([W(t,e),G(t,e)]);if(!(a===0&&c===0)){if(a!==0){let l=`${e}-${Xe(8)}`;o=`Created branch ${l}`,await s(`git branch ${l}`)}await s(`git reset --hard ${t}/${e}`)}})();to(eo(m,{msg:`Force pull reseting ${e} -> ${t}`,promise:i})),await i,o&&console.info(o)}var Yt={abort:lt,amend:ft,autoprune:ht,backmerge:gt,churn:wt,coauthor:Pt,"code-review":Rt,conflict:At,continue:St,exclude:vt,files:Dt,fixup:Et,include:kt,languages:Bt,lines:Tt,pwd:qt,rebranch:Mt,"remote-default":dt,savepoint:v,sha:Ft,track:Ht,update:Nt,"--version":Lt,whoami:Ut,wipe:_t,yank:Vt};async function vn(t){return await Yt[t]?.(),Object.hasOwn(Yt,t)}export{vn as runCommand};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{a as Le,b as Re,c as Ne,d as Fe,j as We,o as Ie,r as Oe,t as Ke,u as $e,v as Ge,w as Q}from"./chunk-7XT4D6II.js";import{b as P,c as De}from"./chunk-R7DNYVL6.js";import{render as gn}from"ink";import{createContext as ro,useContext as no,useState as io}from"react";import{jsx as so}from"react/jsx-runtime";var He=ro(void 0),Ve=({children:e})=>{let[t,r]=io({}),o=(i,s)=>{r(a=>({...a,[i]:s}))},n=i=>{let s=Array.isArray(i)?i:[i];r(a=>{let l={...a};for(let c of s)delete l[c];return l})};return so(He.Provider,{value:{keybindings:t,setKeybinding:o,removeKeybinding:n},children:e})},M=()=>{let e=no(He);if(!e)throw new Error("useKeybindings must be used within a KeybindingsProvider");return e};import{useEffect as mn}from"react";import{Text as un,Box as to,useInput as pn}from"ink";import{useStdout as ao}from"ink";function g(){let{stdout:e}=ao(),t=e.rows-2,r=Math.floor(t/2),o=e.columns>100?96:e.columns-4;return{width:e.columns,height:e.rows,sectionHeight:t,sectionHalfHeight:r,modalWidth:o}}import{Box as Ye,Text as uo}from"ink";import{useState as se,createContext as co,useContext as lo}from"react";import{jsx as mo}from"react/jsx-runtime";var I={Files:"Files","File Meta":"Files",Status:"Status",Log:"Log","Commit Details":"Log",Branches:"Branches",Worktrees:"Branches",Remotes:"Branches",Stashes:"Stashes","Stash Details":"Stashes"},U=Object.keys(I),_e=co({});function Ue({children:e}){let[t,r]=se(!1),o=()=>r(!0),n=()=>r(!1),[i,s]=se("Status"),[a,l]=se("Status"),c=p=>{t||(l(p),s(I[p]))},m=p=>{t||(s(p),l(p))},f=()=>{t||l(p=>{let S=U.at((U.indexOf(p)+1)%U.length);return s(I[S]),S})},b=()=>{t||l(p=>{let S=U.at(U.indexOf(p)-1);return s(I[S]),S})};return mo(_e.Provider,{value:{activeGroup:i,setActiveGroup:m,activeSection:a,setActiveSection:c,prevSection:b,nextSection:f,isLocked:t,lock:o,unlock:n},children:e})}function w(){let e=lo(_e);if(Object.keys(e).length===0)throw new Error("useNavContext must be used within a NavProvider");return e}import{memo as po}from"react";import{jsx as ae}from"react/jsx-runtime";var fo=Array.from(new Set(Object.values(I))),qe=po(({activeGroup:e})=>ae(Ye,{width:"100%",flexDirection:"row",height:1,children:fo.map((t,r)=>ae(Ye,{borderStyle:"classic",borderLeft:!!r,borderRight:!1,borderTop:!1,borderBottom:!1,children:ae(uo,{color:t===e?"cyan":"",children:` [${r+1}]: ${t} `})},t))}),(e,t)=>e.activeGroup===t.activeGroup);import{Text as an,useInput as cn}from"ink";import{Box as So,Text as wo}from"ink";import{Box as Qe,measureElement as go,Text as ze}from"ink";import{useMemo as ho,useRef as xo}from"react";import{Fragment as vo,jsx as z,jsxs as yo}from"react/jsx-runtime";function T(e){let{title:t,footer:r,children:o,width:n,height:i,innerHeight:s,isModal:a,backgroundColor:l}=e,{width:c}=g(),m=n??c,f=xo(null),b=ho(()=>{if(!f.current)return 0;let{width:d}=go(f.current);return d},[f.current]),p=b-8,S={...e,height:s,width:b},{activeSection:x}=w(),u=x===t||a?"cyan":"";return z(Qe,{ref:f,flexDirection:"column",height:i,width:m,backgroundColor:l,children:b!==0&&yo(vo,{children:[t&&z(ze,{color:u,wrap:"truncate-end",children:"\u256D\u2500\u2500\u2500\u2500 "+t+" "+"\u2500".repeat(p-t.length)+"\u256E"}),z(Qe,{flexDirection:"column",...S,borderStyle:"round",borderColor:u,borderTop:!t,borderBottom:!r,paddingLeft:1,children:o}),r&&z(ze,{color:u,wrap:"truncate-end",children:"\u2570"+"\u2500".repeat(p-r.length)+" "+r+" \u2500\u2500\u2500\u2500\u256F"})]})})}import{useEffect as bo,useState as ce}from"react";function y(e,t=[]){let[r,o]=ce(void 0),[n,i]=ce(!1),[s,a]=ce(0),l=()=>a(c=>c+1);return bo(()=>{let c=!1;return i(!1),o(void 0),e().then(m=>{c||(o(m),i(!0))}).catch(()=>{c||i(!0)}),()=>{c=!0}},[s,...t]),{value:r,resolved:n,refresh:l}}import{jsx as le}from"react/jsx-runtime";function Je(){let{width:e,sectionHeight:t}=g(),{value:r}=y(Ie);return le(So,{width:e,height:t,children:le(T,{title:"Status",innerHeight:t-1,children:r?.map(o=>le(wo,{children:o},o))})})}import{useEffect as Mt,useState as Pt}from"react";import{Box as vr,useInput as yr}from"ink";import{Text as To}from"ink";import{jsx as Xe}from"react/jsx-runtime";function Ze({sha:e}){let{resolved:t,value:r}=y(()=>Mo(e),[e]);return Xe(T,{title:"Commit Details",width:"50%",height:"100%",children:e&&t&&Xe(To,{children:r})})}async function Mo(e){if(!e)return;let{stdout:t}=await P(`git show ${e} --name-only`);return t.trim()}import{useCallback as Io,useEffect as Oo}from"react";import{Box as J,Text as ue,useInput as Ko}from"ink";import{useEffect as je,useRef as Po,useState as de}from"react";function O(e,t){let[r,o]=de(0),[n,i]=de(0),s=Po(void 0),[a,l]=de(0),c=()=>l(u=>u+1);je(()=>{let u=0;if(s.current!==void 0){let h=e.findIndex(v=>v===s.current);h>=0&&(u=h)}i(u);let d=Math.min(Math.max(u-Math.floor(t/2),0),Math.max(0,e.length-t));o(d)},[e,t,a]),je(()=>{s.current=e[n]},[n,e]);let m=Math.max(0,e.length-t),f=e.length-1,b=()=>{i(u=>{let d=Math.min(u+1,f);return o(h=>d>=h+t?Math.min(h+1,m):h),d})},p=()=>{i(u=>{let d=Math.max(u-1,0);return o(h=>d<h?Math.max(h-1,0):h),d})},S=e.slice(r,r+t),x=e[n];return{scrollDown:b,scrollUp:p,outList:S,selectedIndex:n,renderedIndex:n-r,selectedValue:x,refresh:c}}import{useInput as Co}from"ink";import{createContext as Eo,useContext as Ao}from"react";import{useEffect as rt,useState as et}from"react";import{jsx as Bo}from"react/jsx-runtime";var tt="\u2190",ot="\u2192",nt=Eo({});function it({children:e}){let[t,r]=et("truncate-end"),[o,n]=et(0),{removeKeybinding:i,setKeybinding:s}=M();return rt(()=>(o&&(t==="truncate-start"?s(tt,"pan left"):s(ot,"pan right")),()=>{i([ot,tt])}),[t,o]),Co((a,l)=>{o&&(l.rightArrow?r("truncate-start"):l.leftArrow&&r("truncate-end"))}),Bo(nt.Provider,{value:{mode:t,_isToggleable:o,_setIsToggleable:n},children:e})}function k(){let e=Ao(nt);if(Object.keys(e).length===0)throw new Error("useTruncationMode must be used within an TruncationModeProvider");let{mode:t,_setIsToggleable:r}=e;return rt(()=>(r(o=>o+1),()=>r(o=>o-1)),[]),{mode:t}}import{createContext as ko,useContext as Do,useEffect as st,useMemo as Lo,useRef as at,useState as ct}from"react";import{useInput as Ro}from"ink";import{jsx as Wo}from"react/jsx-runtime";var lt=ko({});function dt({children:e}){let{activeSection:t}=w(),{sectionHeight:r}=g(),o=r-3,{value:{tree:n,files:i}={},resolved:s}=y(No),a=at(new Set),l=at(new Set(["."])),[c,m]=ct();st(()=>{n&&i&&(a.current=new Set(Object.keys(n)),m(i[0]))},[s]);let f=Lo(()=>i?.filter(x=>a.current.has(x))??[],[a.current.size,s]),[b,p]=ct(0),S=()=>p(x=>x+1);return Ro((x,u)=>{if(t!=="Files"||!n||!c)return;if(u.upArrow){let h=Math.max(0,f.indexOf(c)-1);m(f[h]),S()}else if(u.downArrow){let h=Math.min(f.length-1,f.indexOf(c)+1);m(f[h]),S()}let d;if(u.leftArrow?d="collapse":u.rightArrow&&(d="expand"),d){let h=me(n,c);if(!h)return;for(let v of Object.keys(h)){let E=`${c}/${v}`;d==="expand"?a.current.add(E):a.current.delete(E)}S()}}),st(()=>{if(l.current.clear(),l.current.add("."),f.length<=o){f.forEach(_=>l.current.add(_));return}let x=c?Fo(c):[],u=Math.max(1,o-x.length),d=f.filter(_=>!x.includes(_)),h=c?d.indexOf(c):0,v=Math.max(0,h-Math.floor(u/2)),E=v+u;E>d.length&&(E=d.length,v=Math.max(0,E-u));let q=d.slice(v,E);[...x,...q].forEach(_=>{l.current.add(_)})},[f.length,c,o]),Wo(lt.Provider,{value:{version:b,tree:n,visibleFiles:l.current,expandedFiles:a.current,selectedFile:c},children:e})}function B(){let e=Do(lt);if(Object.keys(e).length===0)throw new Error("useTreeNavigation must be used within an TreeNavigationProvider");return e}var me=(e,t)=>{let r=t.split("/"),o=e;for(let n of r)o=o[n];return o},No=async()=>{let e=await Re(),t=Ne(e);return{tree:e,files:t}},Fo=e=>{let t=e.split("/"),r=[];for(let o=1;o<t.length;o++)r.push(t.slice(0,o).join("/"));return r};import{jsx as R,jsxs as Go}from"react/jsx-runtime";function mt({setSha:e,mode:t}){let{label:r,value:o}=t,{sectionHeight:n}=g(),{activeSection:i,isLocked:s}=w(),{selectedFile:a}=B(),{mode:l}=k(),c=Io(()=>o.length&&a?o(a):o(),[o,a]),{resolved:m,value:f=[]}=y(c,[r]),{scrollUp:b,scrollDown:p,outList:S,selectedValue:x,renderedIndex:u}=O(f,n-2),d=x?.sha;Oo(()=>{e(d)},[d]),Ko((v,E)=>{i!=="Log"||s||(E.upArrow?b():E.downArrow&&p())});let h=$o.includes(t.label);return R(T,{overflowY:"hidden",height:"100%",title:"Log",width:"50%",children:m&&S.map(({sha:v,message:E},q)=>Go(J,{flexDirection:"row",flexWrap:"nowrap",children:[R(J,{minWidth:2,children:v===d?R(ue,{color:h&&q===u?"magenta":void 0,children:"> "}):null}),R(J,{minWidth:8,children:R(ue,{color:"yellow",children:v})}),R(J,{children:R(ue,{wrap:l,children:E})})]},`${v}-${t.label}${h?q:""}`))})}var $o=["blame","reflog"];import{useState as rr}from"react";import{useInput as nr}from"ink";import ir from"ink-text-input";import{useInput as Ho}from"ink";import{createContext as Vo,useContext as _o,useEffect as Uo,useState as pe}from"react";import{Fragment as Yo,jsx as Qo,jsxs as qo}from"react/jsx-runtime";var ut=Vo({});function C(){let e=_o(ut);if(Object.keys(e).length===0)throw new Error("useKeybindings must be used within a KeybindingsProvider");return e}function pt({children:e}){let[t,r]=pe(null),{lock:o,unlock:n}=w(),[i,s]=pe(!1),[a,l]=pe(),c=()=>{n(),s(!1),a?.(),r(null)},m=()=>{o(),s(!0)},f=()=>{i?c():m()},b=(x,u)=>{c(),l(u?.onClose),r(x)};Ho((x,u)=>{u.escape&&c()});let{setKeybinding:p,removeKeybinding:S}=M();return Uo(()=>{if(i)return p("esc","close"),()=>{S("esc")}},[i]),Qo(ut.Provider,{value:{setModal:b,open:m,close:c,toggle:f,isOpen:i},children:qo(Yo,{children:[e,t]})})}import{Box as xt}from"ink";import fe from"node:path";import ge from"node:os";import zo from"node:fs/promises";import{createContext as Jo,useContext as Xo}from"react";import{jsx as tr}from"react/jsx-runtime";var ft=Jo({});function gt({children:e}){let{value:t}=y(Zo);return tr(ft.Provider,{value:{bgColor:t},children:e})}var ht=()=>{let e=Xo(ft);if(Object.keys(e).length===0)throw new Error("useKeybindings must be used within a KeybindingsProvider");return e};async function Zo(){if(!(!process.stdin.isTTY||!process.stdout.isTTY))return process.env.TERM_PROGRAM==="vscode"?await er():new Promise(e=>{let t="\x1B]11;?\x07",r="",o,n=s=>{clearTimeout(o),process.stdin.off("data",i);try{process.stdin.setRawMode(!1),process.stdin.pause()}catch{}e(s)},i=s=>{r+=s.toString("ascii");let a=r.match(/\x1b]11;rgb:([0-9a-fA-F]{1,4})\/([0-9a-fA-F]{1,4})\/([0-9a-fA-F]{1,4})\x07/);if(a){let l=jo(a[1],a[2],a[3]);n(l)}};try{process.stdin.setRawMode(!0),process.stdin.resume(),process.stdin.on("data",i),o=setTimeout(()=>n(void 0),150),process.stdout.write(t)}catch{n(void 0)}})}function jo(e,t,r){return"#"+[e,t,r].map(o=>Math.round(parseInt(o,16)*255/((1<<4*o.length)-1)).toString(16).padStart(2,"0")).join("")}async function er(){let e="Code";process.env.TERM_PROGRAM_VERSION?.includes("insider")&&(e="Code - Insiders");let t;switch(process.platform){case"win32":t=fe.join(ge.homedir(),"AppData","Roaming",e,"User","settings.json");break;case"linux":t=fe.join(ge.homedir(),".config",e,"User","settings.json");break;case"darwin":t=fe.join(ge.homedir(),"Library","Application Support",e,"User","settings.json");break;default:return}if(!await Le(t))return;let r=await zo.readFile(t,{encoding:"utf-8"}),{default:o}=await import("strip-json-comments"),n=o(r).replace(/,\s*(\}|\])/g,"$1");switch(JSON.parse(n)["workbench.colorTheme"]){case"Default Dark Modern":case void 0:return"#181818";case"Visual Studio Dark":case"Default Dark+":return"#1e1e1e";case"Default High Contrast":return"#000000";case"Default Light+":case"Visual Studio Light":case"Default High Contrast Light":return"#ffffff";case"Default Light Modern":return"#f8f8f8";default:return}}import{jsx as he}from"react/jsx-runtime";var or=36;function K({children:e,title:t,width:r=or}){let o=g(),{width:n}=o,i=Math.floor((n-r)/2),{bgColor:s}=ht();return he(xt,{...o,position:"absolute",children:he(xt,{alignSelf:"center",marginLeft:i,marginRight:i,children:he(T,{title:t,width:r,isModal:!0,backgroundColor:s,children:e})})})}import{jsx as vt}from"react/jsx-runtime";function X({title:e,handleSubmit:t}){let[r,o]=rr(""),{isOpen:n,close:i}=C();return nr((s,a)=>{a.return&&n&&(t(r),o(""),i())}),n&&vt(K,{title:e,children:vt(ir,{value:r,onChange:o})})}import{useInput as sr}from"ink";import ar from"ink-select-input";import{jsx as yt}from"react/jsx-runtime";function Z({title:e,handleSubmit:t,options:r,initialIndex:o,width:n}){let{isOpen:i,close:s}=C();return sr((a,l)=>{l.return&&i&&s()}),i&&yt(K,{title:e,width:n,children:yt(ar,{items:r,onSelect:t,initialIndex:o})})}var G=[{value:()=>$("git log --oneline -n 400"),label:"log"},{value:()=>$("git log --oneline --tags --no-walk --decorate"),label:"tags"},{value:()=>$("git reflog"),label:"reflog"},{value:()=>$('git log --oneline --author="$(git config user.name)"'),label:"my commits"},{value:e=>$(`git log --oneline "${e}"`),label:"file"},{value:e=>$(`git blame --follow "${e}"`),label:"blame"}];async function $(e){let{stdout:t}=await P(e);return t.trim().split(/\r?\n/).map(cr)}function cr(e){let t=e.indexOf(" ");return{sha:e.slice(0,t),message:e.slice(t+1)}}import{createContext as lr,useContext as dr,useEffect as mr,useState as ur}from"react";import{jsx as pr}from"react/jsx-runtime";var bt=lr({});function St({children:e}){let[t,r]=ur(),o=(n,...i)=>{n(...i).catch(s=>r(s.stderr??s.message))};return mr(()=>{if(t)throw new Error(t)},[t]),pr(bt.Provider,{value:{attempt:o,err:t},children:e})}function H(){let e=dr(bt);if(Object.keys(e).length===0)throw new Error("useErrorCatcher must be used within an ErrorCatcherProvider");return e}import{createContext as fr,useContext as gr,useState as hr}from"react";import{jsx as xr}from"react/jsx-runtime";var wt=fr({});function Tt({children:e}){let[t,r]=hr(),o=i=>r(i),n=i=>{let s=t===i;return s&&r(void 0),s};return xr(wt.Provider,{value:{sendMessage:o,receiveMessage:n},children:e})}function j(){let e=gr(wt);if(Object.keys(e).length===0)throw new Error("useMessaging must be used within an MessagingProvider");return e}import{jsx as xe,jsxs as br}from"react/jsx-runtime";function ve(){let{setModal:e,toggle:t}=C(),[r,o]=Pt(),{width:n,sectionHeight:i}=g(),[s,a]=Pt(G[0]),{receiveMessage:l}=j();Mt(()=>{l("log-file")&&a(G[4]),l("blame-file")&&a(G[5])},[]);let{isLocked:c}=w(),{attempt:m}=H();yr((p,S)=>{p==="m"&&(e(xe(Z,{options:G,title:"Log Type",handleSubmit:x=>a(x),initialIndex:G.indexOf(s)})),t()),!c&&p==="c"&&r&&m(()=>P(`git checkout ${r}`))});let{setKeybinding:f,removeKeybinding:b}=M();return Mt(()=>(f("c","checkout"),f("m","mode"),()=>{b(["c","m"])}),[]),br(vr,{width:n,height:i,children:[xe(mt,{setSha:o,mode:s}),xe(Ze,{sha:r})]})}import{useEffect as Br}from"react";import{Box as Dt}from"ink";import{Box as ye,Text as Ct,useInput as Sr}from"ink";import{useEffect as wr}from"react";import{Fragment as Mr,jsx as N,jsxs as Tr}from"react/jsx-runtime";function Et(){let{activeSection:e,isLocked:t}=w(),{sectionHalfHeight:r}=g(),{value:o=[],refresh:n}=y(Ke),{value:i,refresh:s}=y(Fe),{setKeybinding:a,removeKeybinding:l}=M();wr(()=>{if(e==="Branches")return a("s","switch"),()=>{l("s")}},[e]);let{outList:c,selectedValue:m,scrollUp:f,scrollDown:b}=O(o,r-2),p=async v=>{await P(`git branch ${v}`),n()},S=async()=>{await P(`git branch -D ${m}`),n()},x=async()=>{await P(`git switch ${m}`),n(),s()},{setModal:u,open:d}=C(),{attempt:h}=H();return Sr((v,E)=>{e!=="Branches"||t||(E.upArrow?f():E.downArrow?b():v==="c"?(u(N(X,{title:"Name your new branch",handleSubmit:p})),d()):v==="d"?h(S):v==="s"&&h(x))}),N(Mr,{children:N(T,{width:"100%",title:"Branches",innerHeight:r-1,children:c.map(v=>Tr(ye,{flexDirection:"row",flexWrap:"nowrap",children:[N(ye,{minWidth:2,children:v===m?N(Ct,{children:"> "}):null}),N(ye,{children:N(Ct,{color:v===i?"magenta":void 0,children:v})})]},v))})})}import{Text as be}from"ink";import{Fragment as Pr}from"react";import{jsx as Se,jsxs as At}from"react/jsx-runtime";function Bt(){let{value:e}=y($e);return Se(T,{width:"50%",title:"Remotes",children:e?.map(({url:t,name:r,type:o})=>At(Pr,{children:[At(be,{wrap:"truncate-end",children:[r," (",o,")"]}),Se(be,{wrap:"truncate-end",children:t}),Se(be,{children:" "})]},`${r}-${o}`))})}import{Text as we}from"ink";import{Fragment as Cr}from"react";import{jsx as ee,jsxs as Ar}from"react/jsx-runtime";function kt(){let{sectionHalfHeight:e}=g(),{value:t}=y(Er);return ee(T,{width:"100%",title:"Worktrees",innerHeight:e-1,children:t?.map(({branch:r,detached:o,path:n,head:i})=>Ar(Cr,{children:[ee(we,{children:o?i:r}),ee(we,{children:n}),ee(we,{children:" "})]},n))})}async function Er(){let{stdout:e}=await P("git worktree list --porcelain"),t=e.trim().split(/\r?\n/),r=[],o=[];for(let n of t)n.trim()===""?o.length&&(r.push(o),o=[]):o.push(n);return o.length&&r.push(o),r.map(n=>{let i={detached:!1};for(let s of n)s.startsWith("worktree ")?i.path=s.slice(9):s.startsWith("HEAD ")?i.head=s.slice(5):s.startsWith("branch ")?i.branch=s.slice(7):s==="detached"&&(i.detached=!0);return i})}import{Fragment as kr,jsx as te,jsxs as Lt}from"react/jsx-runtime";function Rt(){let{width:e,sectionHeight:t}=g(),{setKeybinding:r,removeKeybinding:o}=M();return Br(()=>(r("c","create"),r("d","delete"),()=>{o(["c","d"])}),[]),te(kr,{children:Lt(Dt,{width:e,height:t,children:[Lt(Dt,{flexDirection:"column",width:"50%",height:t,children:[te(Et,{}),te(kt,{})]}),te(Bt,{})]})})}import{Component as Dr,useEffect as Lr}from"react";import{Text as Nt}from"ink";import{jsx as Te}from"react/jsx-runtime";function oe({title:e,message:t,width:r}){let{isOpen:o}=C(),{mode:n}=k();return o&&Te(K,{title:e,width:r,children:Array.isArray(t)?t.map(i=>Te(Nt,{wrap:n,children:i})):Te(Nt,{children:t})})}import{jsx as Ft}from"react/jsx-runtime";var re=class extends Dr{state={hasError:!1};constructor(t){super(t)}static getDerivedStateFromError(t){return{hasError:!0,message:t?.stderr??t?.message}}dismissError(){this.setState({hasError:!1})}componentDidCatch(t,r){let o=t?.stderr??t?.message;this.setState({hasError:!0,message:o})}render(){return this.state.hasError?Ft(Rr,{dismissError:this.dismissError.bind(this),message:this.state.message,children:this.props.children}):this.props.children}};function Rr({message:e,dismissError:t,children:r}){let{setModal:o,open:n}=C(),{modalWidth:i}=g();return Lr(()=>{if(e){let s=e.split(/\r?\n/).map(a=>a.trim());o(Ft(oe,{title:"Error",message:s,width:i}),{onClose:t}),n()}},[e]),r}import{Box as Ur,useInput as Yr}from"ink";import{useEffect as qr}from"react";import{Box as Me,Text as Kt}from"ink";import Pe from"node:path";import{memo as Nr,useEffect as Wt,useState as Fr}from"react";import{Fragment as Kr,jsx as D,jsxs as Ce}from"react/jsx-runtime";var Wr="\u2190",Ir="\u2191",$t="\u2192",Gt="\u2193",It=`${Wr}${Ir}${Gt}${$t}`;function Ht(){let{sectionHeight:e}=g(),{activeSection:t}=w(),{setKeybinding:r,removeKeybinding:o}=M();Wt(()=>{if(t==="Files")return r(It,"NAVIGATION_KEY"),()=>o(It)},[t]);let{tree:n,version:i}=B(),{value:s}=y(We),[,a]=Fr(0);return Wt(()=>{a(l=>l+1)},[i]),D(T,{title:"Files",innerHeight:e,width:"50%",children:s&&n&&D(Vt,{name:Pe.basename(s),contents:n,depth:0,fp:s})})}function Vt(e){let{contents:t,depth:r,fp:o,rp:n="."}=e,i=Object.keys(t).length===0,{selectedFile:s,visibleFiles:a,expandedFiles:l}=B(),c=n===s;if(!a.has(n))return null;let m=r+2;if(i)return D(Ot,{...e,depth:m,isSelected:c},o);let f=`${n}/`,b=Or(l,p=>p.startsWith(f))||r===0;return Ce(Kr,{children:[Ce(Me,{flexDirection:"row",flexWrap:"nowrap",children:[D(Me,{width:2,children:D(Kt,{children:b?Gt:$t})}),D(Me,{width:"100%",children:D(Ot,{...e,isSelected:c})})]}),b&&Object.entries(t).map(([p,S])=>{let x=Pe.join(n,p),u=Pe.join(o,p);return D(Vt,{name:p,contents:S,depth:m,rp:x,fp:u})})]})}var Ot=Nr(({name:e,depth:t,isSelected:r})=>Ce(Kt,{wrap:"truncate-end",color:r?"yellow":void 0,children:["\xA0".repeat(t),e]}),(e,t)=>e.isSelected===t.isSelected&&e.fp===t.fp);function Or(e,t){for(let r of e)if(t(r))return!0;return!1}import{Box as Ut,Text as F}from"ink";import{Box as $r,measureElement as Gr,Text as _t}from"ink";import{useMemo as Hr,useRef as Vr}from"react";import{jsx as Ee}from"react/jsx-runtime";function ne({text:e}){let t=Vr(null),r=Hr(()=>{if(!t.current)return 0;let{width:a}=Gr(t.current);return a-4},[t.current]),o=Math.max(0,r-e.length),n=Math.floor(o/2),i=o-n,s=`${"=".repeat(n)} ${e} ${"=".repeat(i)}`;return Ee($r,{width:"100%",ref:t,children:e.length>r?Ee(_t,{children:e}):Ee(_t,{children:s})})}import{jsx as Ae,jsxs as L}from"react/jsx-runtime";function Yt(){let{sectionHeight:e}=g(),{selectedFile:t}=B(),{value:r={}}=y(()=>Ge(t),[t]),{authorDate:o,authorEmail:n,authorName:i,shortHash:s}=r,{value:{added:a,deleted:l}={},resolved:c}=y(async()=>_r(s,t),[s,t]),{mode:m}=k();return Ae(Ut,{width:"50%",height:e,children:L(T,{width:"100%",title:"File Meta",innerHeight:e-1,children:[t&&Ae(ne,{text:t}),s&&L(F,{wrap:m,children:["Last Commit: ",s]}),i&&L(F,{wrap:m,children:["Edited By: ",i]}),o&&L(F,{wrap:m,children:["Edit On: ",o]}),n&&L(F,{wrap:m,children:["Contact: ",n]}),c&&(a||l)&&L(Ut,{flexDirection:"row",flexWrap:"nowrap",children:[Ae(F,{children:"Changes:\xA0"}),L(F,{color:"green",children:["+",a??0,"\xA0"]}),L(F,{color:"red",children:["-",l??0]})]})]})})}var _r=async(e,t)=>!e||!t?{}:(await Q(e)).find(({file:o})=>t===o)??{};import{jsx as Be,jsxs as Qr}from"react/jsx-runtime";function qt(){let{width:e,sectionHeight:t}=g(),{selectedFile:r,tree:o}=B(),{setKeybinding:n,removeKeybinding:i}=M();qr(()=>(n("l","log"),n("b","blame"),()=>{i(["l","b"])}),[]);let{setActiveGroup:s}=w(),{sendMessage:a}=j(),{setModal:l,open:c}=C();return Yr((m,f)=>{m==="l"?(a("log-file"),s("Log")):m==="b"&&(Object.keys(me(o??{},r)).length===0?(a("blame-file"),s("Log")):(l(Be(oe,{title:"Sorry",message:["Can't blame a folder."]})),c()))}),Qr(Ur,{width:e,height:t,children:[Be(Ht,{}),Be(Yt,{})]})}import{Box as on}from"ink";import{Box as Qt,Text as zt,useInput as zr}from"ink";import{useEffect as Jr}from"react";import{jsx as V,jsxs as Zr}from"react/jsx-runtime";function Jt({setStash:e}){let{sectionHeight:t}=g(),{mode:r}=k(),{attempt:o}=H(),{setModal:n,open:i}=C(),{activeSection:s,isLocked:a}=w(),{value:l=[],refresh:c}=y(Xr),{outList:m,selectedValue:f,selectedIndex:b,scrollUp:p,scrollDown:S}=O(l,t-2);Jr(()=>{e(`stash@{${b}}`)},[b]);let x=d=>async()=>{await P(`git stash ${d} stash@{${b}}`),c()},u=async()=>{let d=`stash@{${b}}`,h=await Oe(d);n(V(X,{title:`reword ${d}`,handleSubmit:async v=>{await P(`git stash drop ${d}`),await P(`git stash store ${h} -m "${v}"`),c()}})),i()};return zr((d,h)=>{a||(d==="s"?(n(V(Z,{title:"Stash",options:[{value:"git stash",label:"tracked only"},{value:"git stash -u",label:"tracked & untracked"}],handleSubmit:({value:v})=>o(async()=>{await P(v),c()})})),i()):d==="a"?o(x("apply")):d==="p"?o(x("pop")):d==="d"?o(x("drop")):d==="r"&&o(u),s==="Stashes"&&(h.upArrow?p():h.downArrow&&S()))}),V(T,{title:"Stashes",width:"50%",height:"100%",children:m.map(d=>Zr(Qt,{flexDirection:"row",flexWrap:"nowrap",children:[V(Qt,{minWidth:2,children:d===f?V(zt,{children:"> "}):null}),V(zt,{wrap:r,children:d})]},d))})}async function Xr(){return await De("git stash list")}import{Box as jr,Text as ke}from"ink";import{jsx as tn,jsxs as Y}from"react/jsx-runtime";function Xt({stash:e}){let{value:t=[]}=y(()=>en(e),[e]);return Y(T,{title:"Stash Details",width:"50%",height:"100%",children:[e&&tn(ne,{text:e}),t.map(({file:r,added:o,deleted:n,changeType:i})=>i!=="binary"&&Y(jr,{flexDirection:"row",flexWrap:"nowrap",children:[Y(ke,{children:[r,":\xA0"]}),Y(ke,{color:"green",children:["+",o??0,"\xA0"]}),Y(ke,{color:"red",children:["-",n??0]})]}))]})}async function en(e){if(e)return await Q(e)}import{useEffect as rn,useState as nn}from"react";import{jsx as Zt,jsxs as sn}from"react/jsx-runtime";function jt(){let{sectionHeight:e,width:t}=g(),[r,o]=nn(),{setKeybinding:n,removeKeybinding:i}=M();return rn(()=>(n("s","stash"),n("d","drop"),n("a","apply"),n("p","pop"),n("r","reword"),()=>i(["s","p","d","a","r"])),[]),sn(on,{width:t,height:e,children:[Zt(Jt,{setStash:o}),Zt(Xt,{stash:r})]})}import{jsx as A,jsxs as dn}from"react/jsx-runtime";function eo(){let{prevSection:e,nextSection:t,activeGroup:r,setActiveGroup:o}=w();return cn((n,i)=>{i.tab&&i.shift?e():i.tab?t():n==="1"?o("Files"):n==="2"?o("Status"):n==="3"?o("Log"):n==="4"?o("Branches"):n==="5"&&o("Stashes")}),A(re,{children:A(St,{children:A(Tt,{children:A(dt,{children:A(ln,{group:r})})})})})}function ln({group:e}){switch(e){case"Files":return A(qt,{});case"Status":return A(Je,{});case"Log":return A(ve,{});case"Branches":return A(Rt,{});case"Stashes":return A(jt,{});default:return dn(an,{children:['Error, unknown page "',e,'"']})}}import{jsx as ie,jsxs as fn}from"react/jsx-runtime";function oo(){let{isLocked:e,activeGroup:t}=w();pn((i,s)=>{e||i.toLowerCase()==="q"&&process.exit()});let r=g(),{keybindings:o,setKeybinding:n}=M();return mn(()=>n("q","quit"),[]),fn(to,{flexDirection:"column",...r,children:[ie(qe,{activeGroup:t}),ie(eo,{}),ie(to,{flexDirection:"row",children:Object.entries(o).map(([i,s])=>ie(un,{children:`[${i}]: ${s} `},s))})]})}import{jsx as W}from"react/jsx-runtime";function hn(){return W(gt,{children:W(Ue,{children:W(Ve,{children:W(it,{children:W(pt,{children:W(oo,{})})})})})})}var vl=()=>gn(W(hn,{}),{patchConsole:!0});export{vl as renderApp};
|
package/dist/main.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{a as o,d as t}from"./chunks/chunk-HKY7QTE6.js";import"./chunks/chunk-7XT4D6II.js";import"./chunks/chunk-R7DNYVL6.js";async function a(){let r=o();if(!r){t();let{renderApp:i}=await import("./chunks/pages-
|
|
2
|
+
import{a as o,d as t}from"./chunks/chunk-HKY7QTE6.js";import"./chunks/chunk-7XT4D6II.js";import"./chunks/chunk-R7DNYVL6.js";async function a(){let r=o();if(!r){t();let{renderApp:i}=await import("./chunks/pages-YLGVYIE5.js");return i()}let{runCommand:n}=await import("./chunks/commands-6NWVWJQB.js");if(await n(r))return;let{runWrapper:e}=await import("./chunks/wrapper-PHXQ7CVF.js");await e(r)||(console.error("unknown command"),process.exit(1))}a().catch(r=>{console.error(`An error occurred: ${r.stderr??r.message}`),process.exit(1)});
|
package/package.json
CHANGED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import{b as u,c as X,d as at,e as P,f as y,g as V,h as A,i as N,j as U,k as ct,l as d,m as v}from"./chunk-HKY7QTE6.js";import{a as R,d as h,e as tt,f as T,g as W,h as E,i as et,j as ot,k as rt,m as G,n as C,o as F,p as x,q as it,r as nt,s as M,t as st,w as H,x as L}from"./chunk-7XT4D6II.js";import{a as $,b as s,c as _,d as w,e as l}from"./chunk-R7DNYVL6.js";import k from"node:path";async function mt(){let t=await F(),e=/^(UU|DU|UD)/;return!!t?.some(o=>e.test(o))}async function I(){let t=await et(),[e,o,r,i,n]=await Promise.all([await R(k.join(t,"MERGE_HEAD")),await R(k.join(t,"rebase-merge")),await R(k.join(t,"rebase-apply")),await R(k.join(t,"CHERRY_PICK_HEAD")),await R(k.join(t,"REVERT_HEAD"))]);return{merge:e,rebaseMerge:o,rebaseApply:r,cherryPick:i,revert:n}}async function lt(){let{merge:t,rebaseMerge:e,rebaseApply:o,cherryPick:r,revert:i}=await I(),n="";if(t)n="merge";else if(e||o)n="rebase";else if(r)n="cherry-pick";else if(i)n="revert";else{let a=await mt()?"Conflicts exist, but likely are from a stash and are not abortable. Resolve them manually.":"Nothing to abort.";console.log(a);return}console.log(`Aborting the ${n}`),await l([n,"--abort"])}async function ft(){await U(),await v(),$("git",["commit","--amend","--no-edit",...u()],{stdio:"inherit",silent:!0,triggerExit:!0})}import{render as Qt}from"ink";import{render as Kt}from"ink";import{Suspense as jt,use as Ot,useEffect as _t}from"react";import{Text as pt,useApp as Vt}from"ink";import Yt from"ink-spinner";import{jsx as j,jsxs as Jt}from"react/jsx-runtime";function m(t){let{msg:e}=t;return j(jt,{fallback:Jt(pt,{children:[j(Yt,{type:"dots"}),"\xA0",e]}),children:j(zt,{...t})})}function zt({msg:t,promise:e}){let o=Ot(e),{exit:r}=Vt();return _t(()=>{r()},[o]),j(pt,{children:`\u2714 ${typeof o=="string"?o:t}`})}import{jsx as Zt}from"react/jsx-runtime";async function gt(){let t=process.argv[3],e=process.argv[4]??await h();if(V(t),V(e),t===e)return console.log(`No reason to merge '${t}' into '${e}'`);let o=await tt(t);y(o),Kt(Zt(m,{msg:"Updating target branch and merging",promise:(async()=>{try{await B(o,t)}catch{console.error(`Error when updating branch ${t} with remote ${o}. Fix divergent branches before merging into ${e}`);return}await h()!==e&&await s(`git switch ${e}`),$("git",["merge",t],{stdio:"inherit",silent:!0})})()}))}async function B(t,e){await G(t,e);let[o,r,i]=await Promise.all([T(t,e),W(t,e),h()]);if(r!==0){if(o===0&&i!==e){await s(`git fetch ${t} ${e}:${e}`);return}if(await s(`git switch ${e}`),o===0){await s(`git merge ${t}/${e}`);return}await l(["merge",`${t}/${e}`],["ignore","ignore","inherit"])}}async function q(){P(),y();let{stdout:t,code:e}=await w("git",["rev-parse","--abbrev-ref","origin/HEAD"]);if(e===0)return ut(t.trim());await s("git remote set-head origin -a");let{stdout:o}=await s("git rev-parse --abbrev-ref origin/HEAD");return ut(o.trim())}async function dt(){let{remote:t,branch:e}=await q();console.log(`Remote default branch is '${t}/${e}'`)}async function ut(t){let e=t.split("/"),o=t.split("/").map((r,i)=>e.slice(0,i+1).join("/"));for(let r of o)if(await rt(r)){let i=t.slice(r.length+1);return{remote:r,branch:i}}throw new Error("Failed to get default remote")}import{jsx as te}from"react/jsx-runtime";var Xt=["master","main","development","lingoport"];async function wt(){await A();let{branch:t,remote:e}=await q();await s(`git switch ${t}`);let o=(async()=>{await l(["fetch","--prune","--prune-tags"]),await B(e,t)})();Qt(te(m,{msg:"Fetching and pruning remote references",promise:o})),await o;let r=await st();for(let i of r){if(i===t||Xt.includes(i))continue;let{code:n}=await w("git",["diff","--quiet",t,i]);if(n===0){Y(i);continue}let{code:a}=await w("git",["merge-base","--is-ancestor",i,t]);if(a===0){Y(i);continue}let c=await x(i,t),{stdout:f}=await w("git",["merge-tree",c,t,i]);f?.trim()||Y(i)}}function Y(t){l(["branch","-D",t])}import{spawn as ee}from"node:child_process";import{createInterface as oe}from"node:readline/promises";async function ht(){P;let e=[...(await re()).entries()].sort(([,r],[,i])=>i-r).slice(0,25),o=e[0][1].toString().length;console.info(e.map(([r,i])=>`${String(i).padEnd(o)} ${r}:`).join(`
|
|
3
|
-
`))}async function re(){let{promise:t,resolve:e,reject:o}=Promise.withResolvers(),r=new Map,i=ee("git",["log","--all","-M","-C","--name-only","--format=format:"]),n=oe({input:i.stdout,crlfDelay:1/0});return n.on("line",a=>{let c=a.trim();c&&r.set(c,(r.get(c)??0)+1)}),n.on("close",()=>e(r)),i.on("error",o),t}import{render as ie}from"ink";import{jsx as se}from"react/jsx-runtime";async function yt(){await v();let t=d("Error: missing github username argument"),e=(async()=>{let i=await ne(t);return i.email||(console.error(`Couldn't find an email for ${t}`),process.exit(1)),i})();ie(se(m,{msg:"Fetching name and email",promise:e}));let{name:o,email:r}=await e;l(["commit","--edit","-m","<insert summary>","-m",`Co-authored-by: ${o} <${r}>`])}async function ne(t){let{stdout:e}=await s(`gh api users/${t}`);return JSON.parse(e.trim())}import{render as z}from"ink";import{isDeepStrictEqual as ae}from"node:util";import{jsx as J}from"react/jsx-runtime";async function bt(){let t=d("Error: missing id of PR to checkout");await A();let e=(async()=>Promise.all([s(`gh co ${t}`),s(`gh pr view ${t} --json baseRefName -q .baseRefName`)]))();z(J(m,{msg:`Checking out pr #${t}`,promise:e}));let[,{stdout:o}]=await e,r=o.trim(),i=(async()=>{await s(`git switch ${r}`),await s("git pull"),await s("git switch -")})();z(J(m,{msg:`Updating ${r} branch merge destination`,promise:i})),await i;let n=(async()=>{let p=await x(r,"HEAD");return await s(`git reset ${p} --soft`),await ce("HEAD")})();z(J(m,{msg:"Creating an editable, explorable, local PR experience",promise:n}));let[a,c]=await Promise.all([n,me(t)]),{files:f,additions:g,deletions:D}=c;if(ae(a,c))return console.info(`Files: ${f}, +${g} -${D}`);console.info("The PR stat doesn't match the local stat."),console.info("LOCAL"),console.table(a),console.info("GITHUB"),console.table(c),console.info("One option to fix (there'll likely be conflicts):"),console.info("1. git stash -u"),console.info(`2. git merge ${r}`),console.info("3. git stash pop")}async function ce(t){let{stdout:e}=await s(`git diff --shortstat ${t}`),o=/(\d+)\s+files? changed(?:, (\d+) insertions?\(\+\))?(?:, (\d+) deletions?\(-\))?/,r=e.trim().match(o);if(!r)throw new Error(`Couldn't generate short stat for ref(s): ${t}`);let[,i,n,a]=r;return{files:parseInt(i,10),additions:n?parseInt(n,10):0,deletions:a?parseInt(a,10):0}}async function me(t){let{stdout:e}=await s(`gh pr view ${t} --json deletions,files,additions`),o=JSON.parse(e.trim());return o.files=o.files.length,o}import{spawn as le}from"node:child_process";import{createInterface as fe}from"node:readline/promises";import K from"chalk";async function $t(){let t=d("Error: missing target branch argument"),e=await x("HEAD",t),{promise:o,resolve:r,reject:i}=Promise.withResolvers(),n=le("git",["merge-tree",e,"HEAD",t]),a=fe({input:n.stdout,crlfDelay:1/0}),c=!1,f=0;a.on("line",p=>{p=p.trimEnd(),p==="+<<<<<<< .our"?(c=!0,console.info(K.red(p)),f+=1):p==="+>>>>>>> .their"?(c=!1,console.info(K.green(p))):p==="+======="?console.info(K.yellow(p)):c&&console.info(p)}),a.on("close",()=>r(f)),n.on("error",i);let g=await o,D=g?`\u274C ${g} conflicts would occur!`:"\u2705 No conflicts. Safe to merge.";console.info(D)}async function Rt(){let{merge:t,rebaseMerge:e,rebaseApply:o,cherryPick:r,revert:i}=await I(),n="";if(t)n="merge";else if(e||o)n="rebase";else if(r)n="cherry-pick";else if(i)n="revert";else{console.log("Nothing to continue.");return}console.log(`Continuing the ${n}`),await l([n,"--continue"])}import{appendFileSync as ge}from"node:fs";import{readFile as pe}from"node:fs/promises";async function O(t){return(await pe(t,"utf-8")).split(/\r?\n/).map(o=>o.trim()).filter(o=>o&&!o.startsWith("#"))}async function Ct(){let t=await E("info/exclude");await N(t);let e=await O(t);u().forEach(o=>{e.includes(o)?console.info(`Already Exists: '${o}'`):(ge(t,`${o}
|
|
4
|
-
`),console.info(`Added '${o}'`))}),console.info(`
|
|
5
|
-
See file at ${t}`)}async function xt(){let t=u();if(t[0]){let e=await ue(t[0]);console.info(e.join(`
|
|
6
|
-
`))}else l(["status","--short"])}async function ue(t){return L(t)?await _(`git stash show -p --include-untracked --name-only ${t}`):await _(`git show --name-only --pretty=format:"" ${t}`)}import{spawn as de}from"node:child_process";async function Pt(){let t=d("Error: missing valid target ref argument");await v();let e=await nt(t);await l(["commit",`--fixup=${e}`]);let r=(await M(`${e}^`,"HEAD",!0)).map(n=>we(n));(await Promise.all(r)).every(Boolean)||(console.warn("Rebase conflict would occur!"),await s("git reset HEAD~1 --soft"),process.exit(1)),await s(`git rebase -i --autosquash ${e}^`)}async function we(t){let{stdout:e}=await s(`git diff ${t}^ ${t}`),{promise:o,resolve:r,reject:i}=Promise.withResolvers(),n=de("git",["apply","--check","--3way","-q"],{stdio:["pipe","ignore","ignore"]});return n.on("close",a=>{r(a===0)}),n.on("error",i),n.stdin.write(e),n.stdin.end(),o}import{readFile as he,writeFile as ye}from"node:fs/promises";async function At(){let t=await E("info/exclude");await N(t);let e=await O(t),o=u();o.filter(a=>!e.includes(a)).forEach(a=>console.info(`No match: '${a}'`));let i=(await he(t,"utf-8")).split(/\r?\n/).map(a=>a.trim()),n=i.filter(a=>!o.includes(a));await ye(t,n.join(`
|
|
7
|
-
`)),console.info(`
|
|
8
|
-
Removed ${i.length-n.length} entries from ${t}`)}import{render as be}from"ink";import{jsx as xe}from"react/jsx-runtime";async function vt(){let t=(async()=>{let i=await $e();return await Re(i)})();be(xe(m,{msg:"Fetching repo languages",promise:t}));let e=await t,o=Object.values(e).reduce((i,n)=>i+n,0),r=Object.entries(e).map(([i,n])=>`${i}: ${Math.round(n/o*100)}% - ${Ce(n)}`);console.log(r.join(`
|
|
9
|
-
`))}async function $e(){let{stdout:t}=await s("gh repo view --json nameWithOwner -q .nameWithOwner");return t.trim()}async function Re(t){let{stdout:e}=await s(`gh api repos/${t}/languages`);return JSON.parse(e.trim())}function Ce(t,e=2){if(t===0)return"0 B";let o=1024,r=e<0?0:e,i=["B","KB","MB","GB","TB","PB","EB","ZB","YB"],n=Math.floor(Math.log(t)/Math.log(o));return`${parseFloat((t/Math.pow(o,n)).toFixed(r))} ${i[n]}`}import b from"chalk";async function St(){d();let t=u(),[e,o]=t.filter(i=>i!=="-v"),r=[];if(L(e)?(r.push(...await H(`${e}^3`)),r.push(...await H(`${e}^2`))):r.push(...await H(e,o)),t.includes("-v")){let i={added:"A",modified:"M",deleted:"D",binary:"B"};r.forEach(n=>{let c=`${Pe(n.changeType)(i[n.changeType])} ${n.file} |`;n.added&&(c+=b.green(` +${n.added}`)),n.deleted&&(c+=b.red(` -${n.deleted}`)),console.info(c)})}else{let i=new Set(r.map(({file:g})=>g)).size,[n,a]=r.reduce((g,{added:D,deleted:p})=>[g[0]+(D??0),g[1]+(p??0)],[0,0]),c=b.green(`+${n}`),f=b.red(`-${a}`);console.info(`${i} files: ${c} ${f}`)}}var Pe=t=>{switch(t){case"modified":return b.yellow;case"added":return b.green;case"deleted":return b.red;default:return e=>e}};async function Dt(){let t=await ot();console.log(t)}import{render as kt}from"ink";function Et(){return new Date().toLocaleString("en-US",{year:"2-digit",month:"2-digit",day:"2-digit",hour:"numeric",minute:"2-digit",hour12:!0}).replace(",","")}async function S(){let t=Et();await s("git add -A"),await l(["commit","-m",`"WIP ${t}"`])}import{nanoid as Ae}from"nanoid";import ve from"chalk";import{jsx as Bt}from"react/jsx-runtime";async function qt(){let{remote:t,branch:e}=await q(),o=process.argv[3]??e;await C()||await S(),await it(o,"HEAD")||(console.warn("Conflicts would occur. Not safe to rebranch."),process.exit(1));let r=await h(),i=(async()=>{await B(t,o)})();kt(Bt(m,{msg:`Updating branch ${o}`,promise:i})),await i;let n=`${Ae(8)}`,a=(async()=>{await s(`git switch ${r}`),await s(`git branch ${n}`),await s(`git switch ${o}`),await s(`git branch -D ${r}`),await s(`git switch -c ${r}`);let c=await M(o,n,!0);for(let f of c)try{await s(`git cherry-pick ${f}`)}catch{let g=ve.yellow(`git branch -D ${r} && git branch -m ${n} ${r}`);throw new Error(`\u274C cherry pick failed at ${f}
|
|
10
|
-
Run this to restore backup branch
|
|
11
|
-
> ${g}`)}await s(`git branch -D ${n}`)})();kt(Bt(m,{msg:`Rewriting branch ${r}`,promise:a})),await a,console.info(`Successfully recreated branch ${r} from ${o}`)}import{execSync as Se}from"node:child_process";async function Tt(){P();let t=De(process.argv[3]),{default:e}=await import("clipboardy");await e.write(t),console.log(`'${t}' copied to clipboard`)}function De(t="HEAD"){return Se(`git rev-parse --short ${t}`,{encoding:"utf-8"}).trim()}import{render as Ee}from"ink";import{jsx as ke}from"react/jsx-runtime";async function Wt(){let{remote:t,branch:e}=await X();y(t),await A();let o=G(t,e);Ee(ke(m,{msg:`Fetching branch ${e} from ${t}`,promise:o})),await o,await l(["switch","-c",e,"--track",`${t}/${e}`])}async function Z(){let{stdout:t}=await s("npm list -g bisgit --depth=0 --json");return JSON.parse(t.trim()).dependencies.bisgit.version}async function Gt(){console.info(await Z())}async function Be(){let{code:t}=await w("npm",["outdated","-g","bisgit"]);return t===0}async function qe(){let{stdout:t}=await s("npm view bisgit version",{encoding:"utf8"});return t.trim()}async function Ft(){if(await Be())return console.info("Already up to date");console.info(`Updating: ${await Z()} -> ${await qe()}`),$("npm",["i","-g","bisgit@latest"])}async function Mt(){let[t,e]=await Promise.allSettled([await We("user.name"),await Te()]);t.status==="fulfilled"&&console.info(`Git: ${t.value}`),e.status==="fulfilled"&&console.info(`Github: ${e.value}`)}async function Te(){let{stdout:t}=await s("gh api user --jq .login");return t.trim()}async function We(t){let{stdout:e}=await s(`git config ${t}`);return e.trim()}import{render as Ue}from"ink";import{Text as Ge,useApp as Fe,useInput as Me}from"ink";import{useState as He}from"react";import{Fragment as Ne,jsx as Le,jsxs as Ht}from"react/jsx-runtime";function Lt({prompt:t,msg:e,onConfirm:o}){let[r,i]=He(""),{exit:n}=Fe();return Me((a,c)=>{if(r)return;let f=a.toLowerCase();f==="y"?i("Yes"):(f==="n"||c.return)&&(i("No"),n())}),Ht(Ne,{children:[Ht(Ge,{children:[t," [y/N] ",r]}),r==="Yes"&&Le(m,{msg:e,promise:o()})]})}import{jsx as Ie}from"react/jsx-runtime";async function Nt(){if(at(),await C())return console.log("Already a clean working tree");let t=await F();if(!t)throw new Error("git status cmd failed");let e=new Q(t);e.displayReport(),Ue(Ie(Lt,{prompt:"Approve these changes?",msg:"Running git reset && git clean",onConfirm:async()=>(await s("git reset --hard"),await s("git clean -f"),`Altered ${e.willDelete.length+e.willRecreate.length+e.willRevert.length} files.`)}))}var Q=class{willDelete=[];willRecreate=[];willRevert=[];constructor(e){e.forEach(o=>{if(o){let r=o.slice(0,2).trim(),i=o.slice(3);r.includes("?")||r.includes("A")?this.willDelete.push(i):r==="DU"||r==="D"?this.willRecreate.push(i):this.willRevert.push(i)}}),this.willDelete.sort(),this.willRecreate.sort(),this.willRevert.sort()}displayReport(){this.displaySection("Will Recreate:",this.willRecreate),this.displaySection("Will Revert:",this.willRevert),this.displaySection("Will Delete:",this.willDelete)}displaySection(e,o){o.length&&console.log(`${e}
|
|
12
|
-
${o.map(r=>`- ${r}`).join(`
|
|
13
|
-
`)}`)}};import{nanoid as je}from"nanoid";import{render as Oe}from"ink";import{jsx as _e}from"react/jsx-runtime";async function Ut(){await U();let t=process.argv[3]??"origin";y(t);let e=await h();ct(e);let o="",i=(async()=>{let n=[s(`git fetch ${t} ${e} --force`)];await C()||n.push(S()),await Promise.all(n);let[a,c]=await Promise.all([T(t,e),W(t,e)]);if(!(a===0&&c===0)){if(a!==0){let f=`${e}-${je(8)}`;o=`Created branch ${f}`,await s(`git branch ${f}`)}await s(`git reset --hard ${t}/${e}`)}})();Oe(_e(m,{msg:`Force pull reseting ${e} -> ${t}`,promise:i})),await i,o&&console.info(o)}var It={abort:lt,amend:ft,autoprune:wt,backmerge:gt,churn:ht,coauthor:yt,"code-review":bt,conflict:$t,continue:Rt,exclude:Ct,files:xt,fixup:Pt,include:At,languages:vt,lines:St,pwd:Dt,rebranch:qt,"remote-default":dt,savepoint:S,sha:Tt,track:Wt,update:Ft,"--version":Gt,whoami:Mt,wipe:Nt,yank:Ut};async function fn(t){return await It[t]?.(),Object.hasOwn(It,t)}export{fn as runCommand};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import{a as Se,b as Me,c as Ce,d as Pe,j as Ee,o as Ae,t as ke,u as Be,v as Re,w as Le}from"./chunk-7XT4D6II.js";import{b as E}from"./chunk-R7DNYVL6.js";import{render as $r}from"ink";import{createContext as $t,useContext as _t,useState as Ut}from"react";import{jsx as Yt}from"react/jsx-runtime";var Ne=$t(void 0),De=({children:e})=>{let[t,o]=Ut({}),r=(i,s)=>{o(c=>({...c,[i]:s}))},n=i=>{let s=Array.isArray(i)?i:[i];o(c=>{let a={...c};for(let l of s)delete a[l];return a})};return Yt(Ne.Provider,{value:{keybindings:t,setKeybinding:r,removeKeybinding:n},children:e})},M=()=>{let e=_t(Ne);if(!e)throw new Error("useKeybindings must be used within a KeybindingsProvider");return e};import{useEffect as Kr}from"react";import{Text as Gr,Box as Ht,useInput as Hr}from"ink";import{useStdout as qt}from"ink";function f(){let{stdout:e}=qt(),t=e.rows-2,o=Math.floor(t/2),r=e.columns>100?96:e.columns-4;return{width:e.columns,height:e.rows,sectionHeight:t,sectionHalfHeight:o,modalWidth:r}}import{Box as We,Text as Xt}from"ink";import{useState as te,createContext as Qt,useContext as zt}from"react";import{jsx as Jt}from"react/jsx-runtime";var O={Files:"Files","File Meta":"Files",Status:"Status",Log:"Log","Commit Details":"Log",Branches:"Branches",Worktrees:"Branches",Remotes:"Branches"},V=Object.keys(O),Fe=Qt({});function Oe({children:e}){let[t,o]=te(!1),r=()=>o(!0),n=()=>o(!1),[i,s]=te("Status"),[c,a]=te("Status"),l=d=>{t||(a(d),s(O[d]))},p=d=>{t||(s(d),a(d))},u=()=>{t||a(d=>{let b=V.at((V.indexOf(d)+1)%V.length);return s(O[b]),b})},g=()=>{t||a(d=>{let b=V.at(V.indexOf(d)-1);return s(O[b]),b})};return Jt(Fe.Provider,{value:{activeGroup:i,setActiveGroup:p,activeSection:c,setActiveSection:l,prevSection:g,nextSection:u,isLocked:t,lock:r,unlock:n},children:e})}function w(){let e=zt(Fe);if(Object.keys(e).length===0)throw new Error("useNavContext must be used within a NavProvider");return e}import{memo as Zt}from"react";import{jsx as oe}from"react/jsx-runtime";var jt=Array.from(new Set(Object.values(O))),Ie=Zt(({activeGroup:e})=>oe(We,{width:"100%",flexDirection:"row",height:1,children:jt.map((t,o)=>oe(We,{borderStyle:"classic",borderLeft:!!o,borderRight:!1,borderTop:!1,borderBottom:!1,children:oe(Xt,{color:t===e?"cyan":"",children:` [${o+1}]: ${t} `})},t))}),(e,t)=>e.activeGroup===t.activeGroup);import{Text as Fr,useInput as Or}from"ink";import{Box as so,Text as co}from"ink";import{Box as Ke,measureElement as eo,Text as Ge}from"ink";import{useMemo as to,useRef as oo}from"react";import{Fragment as ro,jsx as U,jsxs as no}from"react/jsx-runtime";function S(e){let{title:t,footer:o,children:r,width:n,height:i,innerHeight:s,isModal:c,backgroundColor:a}=e,{width:l}=f(),p=n??l,u=oo(null),g=to(()=>{if(!u.current)return 0;let{width:h}=eo(u.current);return h},[u.current]),d=g-8,b={...e,height:s,width:g},{activeSection:v}=w(),m=v===t||c?"cyan":"";return U(Ke,{ref:u,flexDirection:"column",height:i,width:p,backgroundColor:a,children:g!==0&&no(ro,{children:[t&&U(Ge,{color:m,wrap:"truncate-end",children:"\u256D\u2500\u2500\u2500\u2500 "+t+" "+"\u2500".repeat(d-t.length)+"\u256E"}),U(Ke,{flexDirection:"column",...b,borderStyle:"round",borderColor:m,borderTop:!t,borderBottom:!o,paddingLeft:1,children:r}),o&&U(Ge,{color:m,wrap:"truncate-end",children:"\u2570"+"\u2500".repeat(d-o.length)+" "+o+" \u2500\u2500\u2500\u2500\u256F"})]})})}import{useEffect as io,useState as re}from"react";function T(e,t=[]){let[o,r]=re(void 0),[n,i]=re(!1),[s,c]=re(0),a=()=>c(l=>l+1);return io(()=>{let l=!1;return i(!1),r(void 0),e().then(p=>{l||(r(p),i(!0))}).catch(()=>{l||i(!0)}),()=>{l=!0}},[s,...t]),{value:o,resolved:n,refresh:a}}import{jsx as ne}from"react/jsx-runtime";function He(){let{width:e,sectionHeight:t}=f(),{value:o}=T(Ae);return ne(so,{width:e,height:t,children:ne(S,{title:"Status",innerHeight:t-1,children:o?.map(r=>ne(co,{children:r},r))})})}import{useEffect as xt,useState as vt}from"react";import{Box as nr,useInput as ir}from"ink";import{Text as ao}from"ink";import{jsx as Ve}from"react/jsx-runtime";function $e({sha:e}){let{resolved:t,value:o}=T(()=>lo(e),[e]);return Ve(S,{title:"Commit Details",width:"50%",height:"100%",children:e&&t&&Ve(ao,{children:o})})}async function lo(e){if(!e)return;let{stdout:t}=await E(`git show ${e} --name-only`);return t.trim()}import{useCallback as So,useEffect as Mo}from"react";import{Box as q,Text as ce,useInput as Co}from"ink";import{useEffect as _e,useRef as uo,useState as ie}from"react";function Y(e,t){let[o,r]=ie(0),[n,i]=ie(0),s=uo(void 0),[c,a]=ie(0),l=()=>a(m=>m+1);_e(()=>{let m=0;if(s.current!==void 0){let x=e.findIndex(y=>y===s.current);x>=0&&(m=x)}i(m);let h=Math.min(Math.max(m-Math.floor(t/2),0),Math.max(0,e.length-t));r(h)},[e,t,c]),_e(()=>{s.current=e[n]},[n,e]);let p=Math.max(0,e.length-t),u=e.length-1,g=()=>{i(m=>{let h=Math.min(m+1,u);return r(x=>h>=x+t?Math.min(x+1,p):x),h})},d=()=>{i(m=>{let h=Math.max(m-1,0);return r(x=>h<x?Math.max(x-1,0):x),h})},b=e.slice(o,o+t),v=e[n];return{scrollDown:g,scrollUp:d,outList:b,selectedIndex:n,renderedIndex:n-o,selectedValue:v,refresh:l}}import{useInput as mo}from"ink";import{createContext as po,useContext as fo}from"react";import{useEffect as Qe,useState as Ue}from"react";import{jsx as go}from"react/jsx-runtime";var Ye="\u2190",qe="\u2192",ze=po({});function Je({children:e}){let[t,o]=Ue("truncate-end"),[r,n]=Ue(0),{removeKeybinding:i,setKeybinding:s}=M();return Qe(()=>(r&&(t==="truncate-start"?s(Ye,"pan left"):s(qe,"pan right")),()=>{i([qe,Ye])}),[t,r]),mo((c,a)=>{r&&(a.rightArrow?o("truncate-start"):a.leftArrow&&o("truncate-end"))}),go(ze.Provider,{value:{mode:t,_isToggleable:r,_setIsToggleable:n},children:e})}function W(){let e=fo(ze);if(Object.keys(e).length===0)throw new Error("useTruncationMode must be used within an TruncationModeProvider");let{mode:t,_setIsToggleable:o}=e;return Qe(()=>(o(r=>r+1),()=>o(r=>r-1)),[]),{mode:t}}import{createContext as ho,useContext as xo,useEffect as Xe,useMemo as vo,useRef as Ze,useState as je}from"react";import{useInput as yo}from"ink";import{jsx as wo}from"react/jsx-runtime";var et=ho({});function tt({children:e}){let{activeSection:t}=w(),{sectionHeight:o}=f(),r=o-3,{value:{tree:n,files:i}={},resolved:s}=T(bo),c=Ze(new Set),a=Ze(new Set(["."])),[l,p]=je();Xe(()=>{n&&i&&(c.current=new Set(Object.keys(n)),p(i[0]))},[s]);let u=vo(()=>i?.filter(v=>c.current.has(v))??[],[c.current.size,s]),[g,d]=je(0),b=()=>d(v=>v+1);return yo((v,m)=>{if(t!=="Files"||!n||!l)return;if(m.upArrow){let x=Math.max(0,u.indexOf(l)-1);p(u[x]),b()}else if(m.downArrow){let x=Math.min(u.length-1,u.indexOf(l)+1);p(u[x]),b()}let h;if(m.leftArrow?h="collapse":m.rightArrow&&(h="expand"),h){let x=se(n,l);if(!x)return;for(let y of Object.keys(x)){let C=`${l}/${y}`;h==="expand"?c.current.add(C):c.current.delete(C)}b()}}),Xe(()=>{if(a.current.clear(),a.current.add("."),u.length<=r){u.forEach(H=>a.current.add(H));return}let v=l?To(l):[],m=Math.max(1,r-v.length),h=u.filter(H=>!v.includes(H)),x=l?h.indexOf(l):0,y=Math.max(0,x-Math.floor(m/2)),C=y+m;C>h.length&&(C=h.length,y=Math.max(0,C-m));let _=h.slice(y,C);[...v,..._].forEach(H=>{a.current.add(H)})},[u.length,l,r]),wo(et.Provider,{value:{version:g,tree:n,visibleFiles:a.current,expandedFiles:c.current,selectedFile:l},children:e})}function A(){let e=xo(et);if(Object.keys(e).length===0)throw new Error("useTreeNavigation must be used within an TreeNavigationProvider");return e}var se=(e,t)=>{let o=t.split("/"),r=e;for(let n of o)r=r[n];return r},bo=async()=>{let e=await Me(),t=Ce(e);return{tree:e,files:t}},To=e=>{let t=e.split("/"),o=[];for(let r=1;r<t.length;r++)o.push(t.slice(0,r).join("/"));return o};import{jsx as N,jsxs as Eo}from"react/jsx-runtime";function ot({setSha:e,mode:t}){let{label:o,value:r}=t,{sectionHeight:n}=f(),{activeSection:i,isLocked:s}=w(),{selectedFile:c}=A(),{mode:a}=W(),l=So(()=>r.length&&c?r(c):r(),[r,c]),{resolved:p,value:u=[]}=T(l,[o]),{scrollUp:g,scrollDown:d,outList:b,selectedValue:v,renderedIndex:m}=Y(u,n-2),h=v?.sha;Mo(()=>{e(h)},[h]),Co((y,C)=>{i!=="Log"||s||(C.upArrow?g():C.downArrow&&d())});let x=Po.includes(t.label);return N(S,{overflowY:"hidden",height:"100%",title:"Log",width:"50%",children:p&&b.map(({sha:y,message:C},_)=>Eo(q,{flexDirection:"row",flexWrap:"nowrap",children:[N(q,{minWidth:2,children:y===h?N(ce,{color:x&&_===m?"magenta":void 0,children:"> "}):null}),N(q,{minWidth:8,children:N(ce,{color:"yellow",children:y})}),N(q,{children:N(ce,{wrap:a,children:C})})]},`${y}-${t.label}${x?_:""}`))})}var Po=["blame","reflog"];import{useState as $o}from"react";import{useInput as _o}from"ink";import Uo from"ink-text-input";import{useInput as Ao}from"ink";import{createContext as ko,useContext as Bo,useEffect as Ro,useState as ae}from"react";import{Fragment as Lo,jsx as Do,jsxs as No}from"react/jsx-runtime";var rt=ko({});function P(){let e=Bo(rt);if(Object.keys(e).length===0)throw new Error("useKeybindings must be used within a KeybindingsProvider");return e}function nt({children:e}){let[t,o]=ae(null),{lock:r,unlock:n}=w(),[i,s]=ae(!1),[c,a]=ae(),l=()=>{n(),s(!1),c?.(),o(null)},p=()=>{r(),s(!0)},u=()=>{i?l():p()},g=(v,m)=>{l(),a(m?.onClose),o(v)};Ao((v,m)=>{m.escape&&l()});let{setKeybinding:d,removeKeybinding:b}=M();return Ro(()=>{if(i)return d("esc","close"),()=>{b("esc")}},[i]),Do(rt.Provider,{value:{setModal:g,open:p,close:l,toggle:u,isOpen:i},children:No(Lo,{children:[e,t]})})}import{Box as at}from"ink";import le from"node:path";import de from"node:os";import Fo from"node:fs/promises";import{createContext as Oo,useContext as Wo}from"react";import{jsx as Ho}from"react/jsx-runtime";var it=Oo({});function st({children:e}){let{value:t}=T(Io);return Ho(it.Provider,{value:{bgColor:t},children:e})}var ct=()=>{let e=Wo(it);if(Object.keys(e).length===0)throw new Error("useKeybindings must be used within a KeybindingsProvider");return e};async function Io(){if(!(!process.stdin.isTTY||!process.stdout.isTTY))return process.env.TERM_PROGRAM==="vscode"?await Go():new Promise(e=>{let t="\x1B]11;?\x07",o="",r,n=s=>{clearTimeout(r),process.stdin.off("data",i);try{process.stdin.setRawMode(!1),process.stdin.pause()}catch{}e(s)},i=s=>{o+=s.toString("ascii");let c=o.match(/\x1b]11;rgb:([0-9a-fA-F]{1,4})\/([0-9a-fA-F]{1,4})\/([0-9a-fA-F]{1,4})\x07/);if(c){let a=Ko(c[1],c[2],c[3]);n(a)}};try{process.stdin.setRawMode(!0),process.stdin.resume(),process.stdin.on("data",i),r=setTimeout(()=>n(void 0),150),process.stdout.write(t)}catch{n(void 0)}})}function Ko(e,t,o){return"#"+[e,t,o].map(r=>Math.round(parseInt(r,16)*255/((1<<4*r.length)-1)).toString(16).padStart(2,"0")).join("")}async function Go(){let e="Code";process.env.TERM_PROGRAM_VERSION?.includes("insider")&&(e="Code - Insiders");let t;switch(process.platform){case"win32":t=le.join(de.homedir(),"AppData","Roaming",e,"User","settings.json");break;case"linux":t=le.join(de.homedir(),".config",e,"User","settings.json");break;case"darwin":t=le.join(de.homedir(),"Library","Application Support",e,"User","settings.json");break;default:return}if(!await Se(t))return;let o=await Fo.readFile(t,{encoding:"utf-8"}),{default:r}=await import("strip-json-comments"),n=r(o).replace(/,\s*(\}|\])/g,"$1");switch(JSON.parse(n)["workbench.colorTheme"]){case"Default Dark Modern":case void 0:return"#181818";case"Visual Studio Dark":case"Default Dark+":return"#1e1e1e";case"Default High Contrast":return"#000000";case"Default Light+":case"Visual Studio Light":case"Default High Contrast Light":return"#ffffff";case"Default Light Modern":return"#f8f8f8";default:return}}import{jsx as ue}from"react/jsx-runtime";var Vo=36;function I({children:e,title:t,width:o=Vo}){let r=f(),{width:n}=r,i=Math.floor((n-o)/2),{bgColor:s}=ct();return ue(at,{...r,position:"absolute",children:ue(at,{alignSelf:"center",marginLeft:i,marginRight:i,children:ue(S,{title:t,width:o,isModal:!0,backgroundColor:s,children:e})})})}import{jsx as lt}from"react/jsx-runtime";function dt({title:e,handleSubmit:t}){let[o,r]=$o(""),{isOpen:n,close:i}=P();return _o((s,c)=>{c.return&&n&&(t(o),r(""),i())}),n&<(I,{title:e,children:lt(Uo,{value:o,onChange:r})})}import{useInput as Yo}from"ink";import qo from"ink-select-input";import{jsx as ut}from"react/jsx-runtime";function mt({title:e,handleSubmit:t,options:o,initialIndex:r,width:n}){let{isOpen:i,close:s}=P();return Yo((c,a)=>{a.return&&i&&s()}),i&&ut(I,{title:e,width:n,children:ut(qo,{items:o,onSelect:t,initialIndex:r})})}var G=[{value:()=>K("git log --oneline -n 400"),label:"log"},{value:()=>K("git log --oneline --tags --no-walk --decorate"),label:"tags"},{value:()=>K("git reflog"),label:"reflog"},{value:()=>K('git log --oneline --author="$(git config user.name)"'),label:"my commits"},{value:e=>K(`git log --oneline "${e}"`),label:"file"},{value:e=>K(`git blame --follow "${e}"`),label:"blame"}];async function K(e){let{stdout:t}=await E(e);return t.trim().split(/\r?\n/).map(Qo)}function Qo(e){let t=e.indexOf(" ");return{sha:e.slice(0,t),message:e.slice(t+1)}}import{createContext as zo,useContext as Jo,useEffect as Xo,useState as Zo}from"react";import{jsx as jo}from"react/jsx-runtime";var pt=zo({});function ft({children:e}){let[t,o]=Zo(),r=(n,...i)=>{n(...i).catch(s=>o(s.stderr??s.message))};return Xo(()=>{if(t)throw new Error(t)},[t]),jo(pt.Provider,{value:{attempt:r,err:t},children:e})}function Q(){let e=Jo(pt);if(Object.keys(e).length===0)throw new Error("useErrorCatcher must be used within an ErrorCatcherProvider");return e}import{createContext as er,useContext as tr,useState as or}from"react";import{jsx as rr}from"react/jsx-runtime";var gt=er({});function ht({children:e}){let[t,o]=or(),r=i=>o(i),n=i=>{let s=t===i;return s&&o(void 0),s};return rr(gt.Provider,{value:{sendMessage:r,receiveMessage:n},children:e})}function z(){let e=tr(gt);if(Object.keys(e).length===0)throw new Error("useMessaging must be used within an MessagingProvider");return e}import{jsx as me,jsxs as sr}from"react/jsx-runtime";function pe(){let{setModal:e,toggle:t}=P(),[o,r]=vt(),{width:n,sectionHeight:i}=f(),[s,c]=vt(G[0]),{receiveMessage:a}=z();xt(()=>{a("log-file")&&c(G[4]),a("blame-file")&&c(G[5])},[]);let{isLocked:l}=w(),{attempt:p}=Q();ir((d,b)=>{d==="m"&&(e(me(mt,{options:G,title:"Log Type",handleSubmit:v=>c(v),initialIndex:G.indexOf(s)})),t()),!l&&d==="c"&&o&&p(()=>E(`git checkout ${o}`))});let{setKeybinding:u,removeKeybinding:g}=M();return xt(()=>(u("c","checkout"),u("m","mode"),()=>{g(["c","m"])}),[]),sr(nr,{width:n,height:i,children:[me(ot,{setSha:r,mode:s}),me($e,{sha:o})]})}import{useEffect as gr}from"react";import{Box as Mt}from"ink";import{Box as fe,Text as yt,useInput as cr}from"ink";import{useEffect as ar}from"react";import{Fragment as dr,jsx as D,jsxs as lr}from"react/jsx-runtime";function bt(){let{activeSection:e,isLocked:t}=w(),{sectionHalfHeight:o}=f(),{value:r=[],refresh:n}=T(ke),{value:i,refresh:s}=T(Pe),{setKeybinding:c,removeKeybinding:a}=M();ar(()=>{if(e==="Branches")return c("s","switch"),()=>{a("s")}},[e]);let{outList:l,selectedValue:p,scrollUp:u,scrollDown:g}=Y(r,o-2),d=async y=>{await E(`git branch ${y}`),n()},b=async()=>{await E(`git branch -D ${p}`),n()},v=async()=>{await E(`git switch ${p}`),n(),s()},{setModal:m,open:h}=P(),{attempt:x}=Q();return cr((y,C)=>{e!=="Branches"||t||(C.upArrow?u():C.downArrow?g():y==="c"?(m(D(dt,{title:"Name your new branch",handleSubmit:d})),h()):y==="d"?x(b):y==="s"&&x(v))}),D(dr,{children:D(S,{width:"100%",title:"Branches",innerHeight:o-1,children:l.map(y=>lr(fe,{flexDirection:"row",flexWrap:"nowrap",children:[D(fe,{minWidth:2,children:y===p?D(yt,{children:"> "}):null}),D(fe,{minWidth:8,children:D(yt,{color:y===i?"magenta":void 0,children:y})})]},y))})})}import{Text as ge}from"ink";import{Fragment as ur}from"react";import{jsx as he,jsxs as Tt}from"react/jsx-runtime";function wt(){let{value:e}=T(Be);return he(S,{width:"50%",title:"Remotes",children:e?.map(({url:t,name:o,type:r})=>Tt(ur,{children:[Tt(ge,{wrap:"truncate-end",children:[o," (",r,")"]}),he(ge,{wrap:"truncate-end",children:t}),he(ge,{children:" "})]},`${o}-${r}`))})}import{Text as xe}from"ink";import{Fragment as mr}from"react";import{jsx as J,jsxs as fr}from"react/jsx-runtime";function St(){let{sectionHalfHeight:e}=f(),{value:t}=T(pr);return J(S,{width:"100%",title:"Worktrees",innerHeight:e-1,children:t?.map(({branch:o,detached:r,path:n,head:i})=>fr(mr,{children:[J(xe,{children:r?i:o}),J(xe,{children:n}),J(xe,{children:" "})]},n))})}async function pr(){let{stdout:e}=await E("git worktree list --porcelain"),t=e.trim().split(/\r?\n/),o=[],r=[];for(let n of t)n.trim()===""?r.length&&(o.push(r),r=[]):r.push(n);return r.length&&o.push(r),o.map(n=>{let i={detached:!1};for(let s of n)s.startsWith("worktree ")?i.path=s.slice(9):s.startsWith("HEAD ")?i.head=s.slice(5):s.startsWith("branch ")?i.branch=s.slice(7):s==="detached"&&(i.detached=!0);return i})}import{Fragment as hr,jsx as X,jsxs as Ct}from"react/jsx-runtime";function Pt(){let{width:e,sectionHeight:t}=f(),{setKeybinding:o,removeKeybinding:r}=M();return gr(()=>(o("c","create"),o("d","delete"),()=>{r(["c","d"])}),[]),X(hr,{children:Ct(Mt,{width:e,height:t,children:[Ct(Mt,{flexDirection:"column",width:"50%",height:t,children:[X(bt,{}),X(St,{})]}),X(wt,{})]})})}import{Component as xr,useEffect as vr}from"react";import{Text as Et}from"ink";import{jsx as ve}from"react/jsx-runtime";function Z({title:e,message:t,width:o}){let{isOpen:r}=P(),{mode:n}=W();return r&&ve(I,{title:e,width:o,children:Array.isArray(t)?t.map(i=>ve(Et,{wrap:n,children:i})):ve(Et,{children:t})})}import{jsx as At}from"react/jsx-runtime";var j=class extends xr{state={hasError:!1};constructor(t){super(t)}static getDerivedStateFromError(t){return{hasError:!0,message:t?.stderr??t?.message}}dismissError(){this.setState({hasError:!1})}componentDidCatch(t,o){let r=t?.stderr??t?.message;this.setState({hasError:!0,message:r})}render(){return this.state.hasError?At(yr,{dismissError:this.dismissError.bind(this),message:this.state.message,children:this.props.children}):this.props.children}};function yr({message:e,dismissError:t,children:o}){let{setModal:r,open:n}=P(),{modalWidth:i}=f();return vr(()=>{if(e){let s=e.split(/\r?\n/).map(c=>c.trim());r(At(Z,{title:"Error",message:s,width:i}),{onClose:t}),n()}},[e]),o}import{Box as Rr,useInput as Lr}from"ink";import{useEffect as Nr}from"react";import{Box as ye,Text as Lt}from"ink";import be from"node:path";import{memo as br,useEffect as kt,useState as Tr}from"react";import{Fragment as Cr,jsx as R,jsxs as Te}from"react/jsx-runtime";var wr="\u2190",Sr="\u2191",Nt="\u2192",Dt="\u2193",Bt=`${wr}${Sr}${Dt}${Nt}`;function Ft(){let{sectionHeight:e}=f(),{activeSection:t}=w(),{setKeybinding:o,removeKeybinding:r}=M();kt(()=>{if(t==="Files")return o(Bt,"NAVIGATION_KEY"),()=>r(Bt)},[t]);let{tree:n,version:i}=A(),{value:s}=T(Ee),[,c]=Tr(0);return kt(()=>{c(a=>a+1)},[i]),R(S,{title:"Files",innerHeight:e,width:"50%",children:s&&n&&R(Ot,{name:be.basename(s),contents:n,depth:0,fp:s})})}function Ot(e){let{contents:t,depth:o,fp:r,rp:n="."}=e,i=Object.keys(t).length===0,{selectedFile:s,visibleFiles:c,expandedFiles:a}=A(),l=n===s;if(!c.has(n))return null;let p=o+2;if(i)return R(Rt,{...e,depth:p,isSelected:l},r);let u=`${n}/`,g=Mr(a,d=>d.startsWith(u))||o===0;return Te(Cr,{children:[Te(ye,{flexDirection:"row",flexWrap:"nowrap",children:[R(ye,{width:2,children:R(Lt,{children:g?Dt:Nt})}),R(ye,{width:"100%",children:R(Rt,{...e,isSelected:l})})]}),g&&Object.entries(t).map(([d,b])=>{let v=be.join(n,d),m=be.join(r,d);return R(Ot,{name:d,contents:b,depth:p,rp:v,fp:m})})]})}var Rt=br(({name:e,depth:t,isSelected:o})=>Te(Lt,{wrap:"truncate-end",color:o?"yellow":void 0,children:["\xA0".repeat(t),e]}),(e,t)=>e.isSelected===t.isSelected&&e.fp===t.fp);function Mr(e,t){for(let o of e)if(t(o))return!0;return!1}import{Box as Wt,measureElement as Pr,Text as k}from"ink";import{useMemo as Er,useRef as Ar}from"react";import{jsx as $,jsxs as L}from"react/jsx-runtime";function It(){let{sectionHeight:e}=f(),{selectedFile:t}=A(),o=Ar(null),r=Er(()=>{if(!o.current)return 0;let{width:d}=Pr(o.current);return d-4},[o.current]),{value:n={}}=T(()=>Re(t),[t]),{authorDate:i,authorEmail:s,authorName:c,shortHash:a}=n,{value:{added:l,deleted:p}={},resolved:u}=T(async()=>kr(a,t),[a,t]),{mode:g}=W();return $(Wt,{width:"50%",height:e,ref:o,children:L(S,{width:"100%",title:"File Meta",innerHeight:e-1,children:[t&&$(Br,{width:r,text:t}),a&&L(k,{wrap:g,children:["Last Commit: ",a]}),c&&L(k,{wrap:g,children:["Edited By: ",c]}),i&&L(k,{wrap:g,children:["Edit On: ",i]}),s&&L(k,{wrap:g,children:["Contact: ",s]}),u&&(l||p)&&L(Wt,{flexDirection:"row",flexWrap:"nowrap",children:[$(k,{children:"Changes:\xA0"}),L(k,{color:"green",children:["+",l??0,"\xA0"]}),L(k,{color:"red",children:["-",p??0]})]})]})})}var kr=async(e,t)=>!e||!t?{}:(await Le(e)).find(({file:r})=>t===r)??{};function Br({width:e,text:t}){if(t.length>e)return $(k,{children:t});let o=Math.max(0,e-t.length-2),r=Math.floor(o/2),n=o-r,i=`${"=".repeat(r)} ${t} ${"=".repeat(n)}`;return $(k,{children:i})}import{jsx as we,jsxs as Dr}from"react/jsx-runtime";function Kt(){let{width:e,sectionHeight:t}=f(),{selectedFile:o,tree:r}=A(),{setKeybinding:n,removeKeybinding:i}=M();Nr(()=>(n("l","log"),n("b","blame"),()=>{i(["l","b"])}),[]);let{setActiveGroup:s}=w(),{sendMessage:c}=z(),{setModal:a,open:l}=P();return Lr((p,u)=>{p==="l"?(c("log-file"),s("Log")):p==="b"&&(Object.keys(se(r??{},o)).length===0?(c("blame-file"),s("Log")):(a(we(Z,{title:"Sorry",message:["Can't blame a folder."]})),l()))}),Dr(Rr,{width:e,height:t,children:[we(Ft,{}),we(It,{})]})}import{jsx as B,jsxs as Ir}from"react/jsx-runtime";function Gt(){let{prevSection:e,nextSection:t,activeGroup:o,setActiveGroup:r}=w();return Or((n,i)=>{i.tab&&i.shift?e():i.tab?t():n==="1"?r("Files"):n==="2"?r("Status"):n==="3"?r("Log"):n==="4"&&r("Branches")}),B(j,{children:B(ft,{children:B(ht,{children:B(tt,{children:B(Wr,{group:o})})})})})}function Wr({group:e}){switch(e){case"Files":return B(Kt,{});case"Status":return B(He,{});case"Log":return B(pe,{});case"Branches":return B(Pt,{});default:return Ir(Fr,{children:['Error, unknown page "',e,'"']})}}import{jsx as ee,jsxs as Vr}from"react/jsx-runtime";function Vt(){let{isLocked:e,activeGroup:t}=w();Hr((i,s)=>{e||i.toLowerCase()==="q"&&process.exit()});let o=f(),{keybindings:r,setKeybinding:n}=M();return Kr(()=>n("q","quit"),[]),Vr(Ht,{flexDirection:"column",...o,children:[ee(Ie,{activeGroup:t}),ee(Gt,{}),ee(Ht,{flexDirection:"row",children:Object.entries(r).map(([i,s])=>ee(Gr,{children:`[${i}]: ${s} `},s))})]})}import{jsx as F}from"react/jsx-runtime";function _r(){return F(st,{children:F(Oe,{children:F(De,{children:F(Je,{children:F(nt,{children:F(Vt,{})})})})})})}var pa=()=>$r(F(_r,{}),{patchConsole:!0});export{pa as renderApp};
|