bisgit 0.5.0 → 0.7.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
@@ -18,7 +18,8 @@ Full Tui coming soon
18
18
  - `gi backmerge <branch>` updates a branch and then merges it into the current branch.
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
- <!-- - `gi lines <branch> <ignore-file> <ignore-file> ...*` shows the number of lines changed. -->
21
+ - `gi files <ref>` shows files of the commit or stash.
22
+ - `gi lines <ref> <ref?>` shows the number of lines changed.
22
23
 
23
24
  ### Branching
24
25
 
@@ -38,7 +39,6 @@ Full Tui coming soon
38
39
 
39
40
  - `gi pwd` shows repo root path.
40
41
  - `gi wipe` clears all uncommitted trackable files
41
- - `gi files <commit>` shows the files edited by the given commit.
42
42
  - `gi churn` shows you the 25 most edited files.
43
43
  - `gi exclude` and `gi include` allows you to ignore files locally without modifying the .gitignore file.
44
44
  - `gi remote-default` shows whether the remote default branch is 'main', 'master', etc.
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import{b as n,c,d as m}from"./chunk-R7DNYVL6.js";import h from"fs/promises";async function T(t){try{return await h.access(t),!0}catch{return!1}}async function p(){return await c("git ls-files")}async function y(){return await c("git ls-files --others --exclude-standard")}async function v(){let[t,e]=await Promise.all([p(),y()]),r=[...t,...e].sort(([s],[o])=>s.localeCompare(o)),i={};for(let s of r){let o=s.split("/"),a=i;for(let u of o)a[u]||(a[u]={}),a=a[u]}return i}function w(t,e=""){let r=[];for(let[i,s]of Object.entries(t)){let o=e?`${e}/${i}`:i;r.push(o),Object.keys(s).length>0&&r.push(...w(s,o))}return r}import{normalize as f}from"node:path";async function x(){let{stdout:t}=await n("git branch --show-current");return t.trim()}async function C(t){t??=await x();let{stdout:e}=await n(`git config --get branch.${t}.remote`);return e.trim()}async function N(t,e){try{let{stdout:r}=await n(`git rev-list --count ${t}/${e}..${e}`);return parseInt(r.trim(),10)}catch(r){return console.error("Error getting commits ahead:",r),NaN}}async function E(t,e){try{let{stdout:r}=await n(`git rev-list --count ${e}..${t}/${e}`);return parseInt(r.trim(),10)}catch(r){return console.error("Error getting commits behind:",r),NaN}}async function F(t){let{stdout:e}=await n(`git rev-parse --git-path ${t}`);return f(e.trim())}async function S(){let{stdout:t}=await n("git rev-parse --git-dir");return f(t.trim())}async function k(){let{stdout:t}=await n("git rev-parse --show-toplevel");return f(t.trim())}async function G(t){let{code:e}=await m("git",["remote","get-url",t],{stdio:"ignore"});return e===0}async function I(){let{stdout:t}=await n("git rev-parse --abbrev-ref HEAD");return t.trim()==="HEAD"}async function M(t,e){let r="git fetch";t&&(r+=` ${t}`),e&&(r+=` ${e}`),await n(r)}async function z(){let{stdout:t}=await m("git",["status","--porcelain"]);return!t?.trim()}async function A(){return await c("git status --porcelain")}async function $(t,e){let{stdout:r}=await n(`git merge-base ${t} ${e}`);return r.trim()}async function H(t,e){let r=await $(t,e),{stdout:i}=await m("git",["merge-tree",r,e,t]);return!i?.split(/\r?\n/)?.includes("+=======")}async function O(t){let{stdout:e}=await n(`git rev-parse ${t}`);return e.trim()}async function j(t,e,r){return await c(`git rev-list ${r?"--reverse":""} ${t}..${e}`)}async function V(){return await c("git for-each-ref --format='%(refname:short)' refs/heads")}async function q(){let{stdout:t}=await n("git remote -v");return t.trim().split(/\r?\n/).map(r=>{let i=r.match(/^(\S+)\s+(\S+)\s+\((fetch|push)\)$/);if(!i)return null;let[,s,o,a]=i;return{name:s,url:o,type:a}}).filter(r=>r!==null)}async function J(t){try{let{stdout:e}=await n(`git log -1 --format='%an|%ae|%ad|%h' -- "${t}"`,{encoding:"utf8"}),[r,i,s,o]=e.trim().split("|");return{authorName:r,authorEmail:i,authorDate:s,shortHash:o}}catch{return{}}}async function K(t,e){let r=e?`git diff --numstat ${t} ${e}`:b(t)?`git stash show --numstat --format="" --include-untracked ${t}`:`git show --numstat --format="" ${t}`;return(await c(r)).map(s=>{let[o,a,u]=s.split(" ");if(o==="-"&&a==="-")return{file:u,added:null,deleted:null,changeType:"binary"};let g=Number(o),l=Number(a),d="modified";return g>0&&l===0?d="added":g===0&&l>0&&(d="deleted"),{file:u,added:g,deleted:l,changeType:d}})}function b(t){return/^stash@\{\d+\}$/.test(t)}export{T as a,v as b,w as c,x as d,C as e,N as f,E as g,F as h,S as i,k as j,G as k,I as l,M as m,z as n,A as o,$ as p,H as q,O as r,j as s,V as t,q as u,J as v,K as w,b as x};
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import{a as s,l as i,n}from"./chunk-7XT4D6II.js";function u(){return process.argv[2]}function g(){return process.argv.slice(3)}async function p(){let[r,t]=g();return r||(console.error("Requires <branch> or <remote> <branch>"),process.exit(1)),t?{remote:r,branch:t}:{remote:"origin",branch:r}}import{spawnSync as a}from"node:child_process";function e(r,t,o){let{status:c}=a(r,t,{stdio:"ignore"});c!==0&&(o&&console.error(o),process.exit(1))}var h=()=>e("git",["rev-parse","--git-dir"],"Need to use command in a git repository."),x=()=>e("git",["rev-parse","HEAD"],"Need to create first commit."),q=(r="origin")=>e("git",["remote","get-url",r],`Need to add remote '${r}'.`),v=r=>e("git",["show-ref","--branches",r],`Branch '${r}' isn't tracked locally and may not exist.`),y=async()=>{await n()||(console.error("You should stash or commit your changes first."),process.exit(1))},b=async r=>{await s(r)||(console.error(`${r} must exist for this operation and it doesn't for some reason`),process.exit(1))},w=async()=>{await i()&&(console.error("Operation not allowed in a 'detached HEAD' state"),process.exit(1))},A=r=>e("git",["rev-parse","--abbrev-ref","--symbolic-full-name",`${r}@{u}`],`branch '${r}' has no upstream`);function C(r="Error: missing required argument"){if(process.argv[3])return process.argv[3];console.error(r),process.exit(1)}async function $(){let{status:r}=a("git",["diff","--staged","--quiet"],{stdio:"ignore"});r===0&&(console.error("You have no staged changes"),process.exit(1))}export{u as a,g as b,p as c,h as d,x as e,q as f,v as g,y as h,b as i,w as j,A as k,C as l,$ as m};
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import{exec as d,spawn as p}from"node:child_process";import{promisify as u}from"node:util";function w(n,s,t){let e=p(n,s,t??{});t?.silent||(e.stdout?.on("data",o=>{console.log(String(o))}),e.stderr?.on("data",o=>{console.error(String(o))})),e.on("close",o=>{t?.triggerExit&&process.exit(o)})}var g=u(d);async function x(n){let{stdout:s}=await g(n),t=s.trim();return t?t.split(/\r?\n/):[]}async function y(n,s,t={}){let{promise:e,resolve:o,reject:c}=Promise.withResolvers(),r=p(n,s,t),l="",a="";return r.stdout?.on("data",i=>l+=i),r.stderr?.on("data",i=>a+=i),r.on("close",i=>o({code:i,stdout:l,stderr:a})),r.on("error",i=>c(i)),e}async function h(n,s="inherit"){let{promise:t,resolve:e,reject:o}=Promise.withResolvers(),c=p("git",["-c","color.ui=always",...n],{stdio:s});return c.on("close",r=>{r===0?e({code:r}):o({code:r})}),c.on("error",o),t}export{w as a,g as b,x as c,y as d,h as e};
@@ -0,0 +1,13 @@
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};
@@ -0,0 +1,2 @@
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&&lt(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};
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import{a as r}from"./chunk-HCUVDNFV.js";var i=["init","clone","add","status","diff","commit","restore","reset","branch","checkout","switch","merge","log","stash","tag","worktree","fetch","pull","push","remote","submodule","show","apply","cherry-pick","rebase","revert","bisect","blame","grep","clean","fsck","reflog","bundle","daemon","cat-file","check-ignore","checkout-index","commit-tree","count-objects","diff-index","for-each-ref","hash-object","ls-files","ls-tree","merge-base","read-tree","rev-list","rev-parse","show-ref","symbolic-ref","update-index","update-ref","verify-pack","write-tree","column"];function t(e){return i.includes(e)}var n=["auth","browse","codespace","gist","issue","org","pr","project","release","repo","cache","run","workflow","agent-task","alias","api","attestation","completion","config","extension","gpg-key","label","preview","ruleset","search","secret","ssh-key","status","variable"];function s(e){return n.includes(e)}var o=e=>{r(e,process.argv.slice(2),{stdio:"inherit",silent:!0})};async function f(e){return t(e)?(o("git"),!0):s(e)?(o("gh"),!0):!1}export{f as runWrapper};
2
+ import{a as r}from"./chunk-R7DNYVL6.js";var i=["init","clone","add","status","diff","commit","restore","reset","branch","checkout","switch","merge","log","stash","tag","worktree","fetch","pull","push","remote","submodule","show","apply","cherry-pick","rebase","revert","bisect","blame","grep","clean","fsck","reflog","bundle","daemon","cat-file","check-ignore","checkout-index","commit-tree","count-objects","diff-index","for-each-ref","hash-object","ls-files","ls-tree","merge-base","read-tree","rev-list","rev-parse","show-ref","symbolic-ref","update-index","update-ref","verify-pack","write-tree","column"];function t(e){return i.includes(e)}var n=["auth","browse","codespace","gist","issue","org","pr","project","release","repo","cache","run","workflow","agent-task","alias","api","attestation","completion","config","extension","gpg-key","label","preview","ruleset","search","secret","ssh-key","status","variable"];function s(e){return n.includes(e)}var o=e=>{r(e,process.argv.slice(2),{stdio:"inherit",silent:!0})};async function f(e){return t(e)?(o("git"),!0):s(e)?(o("gh"),!0):!1}export{f as runWrapper};
package/dist/main.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import{a as n}from"./chunks/chunk-5WTQIRZS.js";async function a(){let r=n();if(!r){let{renderApp:e}=await import("./chunks/pages-7PP5OZ4V.js");return e()}let{runCommand:o}=await import("./chunks/commands-AGYREPE5.js");if(await o(r))return;let{runWrapper:t}=await import("./chunks/wrapper-5X5SODCK.js");await t(r)||(console.error("unknown command"),process.exit(1))}a().catch(r=>{console.error(`An error occurred: ${r.stderr??r.message}`),process.exit(1)});
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-TD7NDORN.js");return i()}let{runCommand:n}=await import("./chunks/commands-GZGY632Z.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,6 +1,6 @@
1
1
  {
2
2
  "name": "bisgit",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "description": "Git CLI tool to simplify common advanced git workflows",
5
5
  "main": "dist/main.js",
6
6
  "bin": {
@@ -41,10 +41,10 @@
41
41
  "prepare": "husky"
42
42
  },
43
43
  "devDependencies": {
44
- "@types/node": "^25.0.9",
45
- "@types/react": "^19.2.8",
46
- "@typescript-eslint/eslint-plugin": "^8.53.0",
47
- "@typescript-eslint/parser": "^8.53.0",
44
+ "@types/node": "^25.0.10",
45
+ "@types/react": "^19.2.9",
46
+ "@typescript-eslint/eslint-plugin": "^8.53.1",
47
+ "@typescript-eslint/parser": "^8.53.1",
48
48
  "esbuild": "^0.27.2",
49
49
  "esbuild-lazy-analyzer": "^1.4.0",
50
50
  "esbuild-visualizer": "^0.7.0",
@@ -53,12 +53,12 @@
53
53
  "husky": "^9.1.7",
54
54
  "lint-staged": "^16.2.7",
55
55
  "npm-run-all": "^4.1.5",
56
- "prettier": "^3.8.0",
56
+ "prettier": "^3.8.1",
57
57
  "react-devtools-core": "^6.1.5"
58
58
  },
59
59
  "dependencies": {
60
60
  "chalk": "^5.6.2",
61
- "clipboardy": "^5.0.2",
61
+ "clipboardy": "^5.1.0",
62
62
  "ink": "^6.6.0",
63
63
  "ink-select-input": "^6.2.0",
64
64
  "ink-spinner": "^5.0.0",
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- function t(){return process.argv[2]}function n(){return process.argv.slice(3)}async function o(){let[r,e]=n();return r||(console.error("Requires <branch> or <remote> <branch>"),process.exit(1)),e?{remote:r,branch:e}:{remote:"origin",branch:r}}export{t as a,n as b,o as c};
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- import{b as n,c as s}from"./chunk-HCUVDNFV.js";import{normalize as a}from"node:path";async function g(){let{stdout:t}=await n("git branch --show-current");return t.trim()}async function d(t){t??=await g();let{stdout:r}=await n(`git config --get branch.${t}.remote`);return r.trim()}async function y(t,r){try{let{stdout:e}=await n(`git rev-list --count ${t}/${r}..${r}`);return parseInt(e.trim(),10)}catch(e){return console.error("Error getting commits ahead:",e),NaN}}async function h(t,r){try{let{stdout:e}=await n(`git rev-list --count ${r}..${t}/${r}`);return parseInt(e.trim(),10)}catch(e){return console.error("Error getting commits behind:",e),NaN}}async function w(t){let{stdout:r}=await n(`git rev-parse --git-path ${t}`);return a(r.trim())}async function x(){let{stdout:t}=await n("git rev-parse --git-dir");return a(t.trim())}async function $(t){let{code:r}=await s("git",["remote","get-url",t],{stdio:"ignore"});return r===0}async function P(){let{stdout:t}=await n("git rev-parse --abbrev-ref HEAD");return t.trim()==="HEAD"}async function v(t,r){let e="git fetch";t&&(e+=` ${t}`),r&&(e+=` ${r}`),await n(e)}async function b(){let{stdout:t}=await s("git",["status","--porcelain"]);return!t?.trim()}async function D(){let{stdout:t}=await s("git",["status","--porcelain"]);return t?.trim()?.split(/\r?\n/)}async function m(t,r){let{stdout:e}=await n(`git merge-base ${t} ${r}`);return e.trim()}async function R(t,r){let e=await m(t,r),{stdout:i}=await s("git",["merge-tree",e,r,t]);return!i?.split(/\r?\n/)?.includes("+=======")}async function A(t){let{stdout:r}=await n(`git rev-parse ${t}`);return r.trim()}async function B(t,r,e){let{stdout:i}=await n(`git rev-list ${e?"--reverse":""} ${t}..${r}`);return i.trim().split(/\r?\n/)}async function G(){let{stdout:t}=await n("git for-each-ref --format='%(refname:short)' refs/heads");return t.trim().split(/\r?\n/)}async function L(){let{stdout:t}=await n("git remote -v");return t.trim().split(/\r?\n/).map(e=>{let i=e.match(/^(\S+)\s+(\S+)\s+\((fetch|push)\)$/);if(!i)return null;let[,o,c,u]=i;return{name:o,url:c,type:u}}).filter(e=>e!==null)}import p from"fs/promises";async function C(t){try{return await p.access(t),!0}catch{return!1}}export{g as a,d as b,y as c,h as d,w as e,x as f,$ as g,P as h,v as i,b as j,D as k,m as l,R as m,A as n,B as o,G as p,L as q,C as r};
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- import{exec as d,spawn as l}from"node:child_process";import{promisify as g}from"node:util";function f(e,i,r){let n=l(e,i,r??{});r?.silent||(n.stdout?.on("data",o=>{console.log(String(o))}),n.stderr?.on("data",o=>{console.error(String(o))})),n.on("close",o=>{r?.triggerExit&&process.exit(o)})}var w=g(d);async function x(e,i,r={}){let{promise:n,resolve:o,reject:c}=Promise.withResolvers(),t=l(e,i,r),p="",a="";return t.stdout?.on("data",s=>p+=s),t.stderr?.on("data",s=>a+=s),t.on("close",s=>o({code:s,stdout:p,stderr:a})),t.on("error",s=>c(s)),n}async function h(e,i="inherit"){let{promise:r,resolve:n,reject:o}=Promise.withResolvers(),c=l("git",["-c","color.ui=always",...e],{stdio:i});return c.on("close",t=>{t===0?n({code:t}):o({code:t})}),c.on("error",o),r}export{f as a,w as b,x as c,h as d};
@@ -1,12 +0,0 @@
1
- #!/usr/bin/env node
2
- import{b as g,c as z}from"./chunk-5WTQIRZS.js";import{a as h,b as Z,c as B,d as H,e as D,f as Q,g as X,h as tt,i as W,j as d,k as G,l as R,m as et,n as ot,o as F,p as rt,r as y}from"./chunk-C7H7IYZ2.js";import{a as u,b as s,c as w,d as l}from"./chunk-HCUVDNFV.js";import S from"node:path";async function it(){let t=await G(),e=/^(UU|DU|UD)/;return!!t?.some(o=>e.test(o))}async function N(){let t=await Q(),[e,o,r,i,n]=await Promise.all([await y(S.join(t,"MERGE_HEAD")),await y(S.join(t,"rebase-merge")),await y(S.join(t,"rebase-apply")),await y(S.join(t,"CHERRY_PICK_HEAD")),await y(S.join(t,"REVERT_HEAD"))]);return{merge:e,rebaseMerge:o,rebaseApply:r,cherryPick:i,revert:n}}async function nt(){let{merge:t,rebaseMerge:e,rebaseApply:o,cherryPick:r,revert:i}=await N(),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 it()?"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"])}import{spawnSync as st}from"node:child_process";function E(t,e,o){let{status:r}=st(t,e,{stdio:"ignore"});r!==0&&(o&&console.error(o),process.exit(1))}var at=()=>E("git",["rev-parse","--git-dir"],"Need to use command in a git repository."),C=()=>E("git",["rev-parse","HEAD"],"Need to create first commit."),b=(t="origin")=>E("git",["remote","get-url",t],`Need to add remote '${t}'.`),O=t=>E("git",["show-ref","--branches",t],`Branch '${t}' isn't tracked locally and may not exist.`),P=async()=>{await d()||(console.error("You should stash or commit your changes first."),process.exit(1))},M=async t=>{await y(t)||(console.error(`${t} must exist for this operation and it doesn't for some reason`),process.exit(1))},T=async()=>{await tt()&&(console.error("Operation not allowed in a 'detached HEAD' state"),process.exit(1))},ct=t=>E("git",["rev-parse","--abbrev-ref","--symbolic-full-name",`${t}@{u}`],`branch '${t}' has no upstream`);function $(t="Error: missing required argument"){if(process.argv[3])return process.argv[3];console.error(t),process.exit(1)}async function v(){let{status:t}=st("git",["diff","--staged","--quiet"],{stdio:"ignore"});t===0&&(console.error("You have no staged changes"),process.exit(1))}async function mt(){await T(),await v(),u("git",["commit","--amend","--no-edit",...g()],{stdio:"inherit",silent:!0,triggerExit:!0})}import{render as Kt}from"ink";import{render as Yt}from"ink";import{Suspense as Lt,use as Ut,useEffect as It}from"react";import{Text as lt,useApp as Ot}from"ink";import jt from"ink-spinner";import{jsx as L,jsxs as Vt}from"react/jsx-runtime";function c(t){let{msg:e}=t;return L(Lt,{fallback:Vt(lt,{children:[L(jt,{type:"dots"}),"\xA0",e]}),children:L(_t,{...t})})}function _t({msg:t,promise:e}){let o=Ut(e),{exit:r}=Ot();return It(()=>{r()},[o]),L(lt,{children:`\u2714 ${typeof o=="string"?o:t}`})}import{jsx as Jt}from"react/jsx-runtime";async function ft(){let t=process.argv[3],e=process.argv[4]??await h();if(O(t),O(e),t===e)return console.log(`No reason to merge '${t}' into '${e}'`);let o=await Z(t);b(o),Yt(Jt(c,{msg:"Updating target branch and merging",promise:(async()=>{try{await q(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}`),u("git",["merge",t],{stdio:"inherit",silent:!0})})()}))}async function q(t,e){await W(t,e);let[o,r,i]=await Promise.all([B(t,e),H(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 k(){C(),b();let{stdout:t,code:e}=await w("git",["rev-parse","--abbrev-ref","origin/HEAD"]);if(e===0)return pt(t.trim());await s("git remote set-head origin -a");let{stdout:o}=await s("git rev-parse --abbrev-ref origin/HEAD");return pt(o.trim())}async function gt(){let{remote:t,branch:e}=await k();console.log(`Remote default branch is '${t}/${e}'`)}async function pt(t){let e=t.split("/"),o=t.split("/").map((r,i)=>e.slice(0,i+1).join("/"));for(let r of o)if(await X(r)){let i=t.slice(r.length+1);return{remote:r,branch:i}}throw new Error("Failed to get default remote")}import{jsx as Zt}from"react/jsx-runtime";var zt=["master","main","development","lingoport"];async function ut(){await P();let{branch:t,remote:e}=await k();await s(`git switch ${t}`);let o=(async()=>{await l(["fetch","--prune","--prune-tags"]),await q(e,t)})();Kt(Zt(c,{msg:"Fetching and pruning remote references",promise:o})),await o;let r=await rt();for(let i of r){if(i===t||zt.includes(i))continue;let{code:n}=await w("git",["diff","--quiet",t,i]);if(n===0){j(i);continue}let{code:a}=await w("git",["merge-base","--is-ancestor",i,t]);if(a===0){j(i);continue}let m=await R(i,t),{stdout:f}=await w("git",["merge-tree",m,t,i]);f?.trim()||j(i)}}function j(t){l(["branch","-D",t])}import{spawn as Qt}from"node:child_process";import{createInterface as Xt}from"node:readline/promises";async function wt(){C;let e=[...(await te()).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 te(){let{promise:t,resolve:e,reject:o}=Promise.withResolvers(),r=new Map,i=Qt("git",["log","--all","-M","-C","--name-only","--format=format:"]),n=Xt({input:i.stdout,crlfDelay:1/0});return n.on("line",a=>{let m=a.trim();m&&r.set(m,(r.get(m)??0)+1)}),n.on("close",()=>e(r)),i.on("error",o),t}import{render as ee}from"ink";import{jsx as re}from"react/jsx-runtime";async function ht(){await v();let t=$("Error: missing github username argument"),e=(async()=>{let i=await oe(t);return i.email||(console.error(`Couldn't find an email for ${t}`),process.exit(1)),i})();ee(re(c,{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 oe(t){let{stdout:e}=await s(`gh api users/${t}`);return JSON.parse(e.trim())}import{render as _}from"ink";import{isDeepStrictEqual as ie}from"node:util";import{jsx as V}from"react/jsx-runtime";async function dt(){let t=$("Error: missing id of PR to checkout");await P();let e=(async()=>Promise.all([s(`gh co ${t}`),s(`gh pr view ${t} --json baseRefName -q .baseRefName`)]))();_(V(c,{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 -")})();_(V(c,{msg:`Updating ${r} branch merge destination`,promise:i})),await i;let n=(async()=>{let p=await R(r,"HEAD");return await s(`git reset ${p} --soft`),await ne("HEAD")})();_(V(c,{msg:"Creating an editable, explorable, local PR experience",promise:n}));let[a,m]=await Promise.all([n,se(t)]),{files:f,additions:x,deletions:I}=m;if(ie(a,m))return console.info(`Files: ${f}, +${x} -${I}`);console.info("The PR stat doesn't match the local stat."),console.info("LOCAL"),console.table(a),console.info("GITHUB"),console.table(m),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 ne(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 se(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 ae}from"node:child_process";import{createInterface as ce}from"node:readline/promises";import Y from"chalk";async function yt(){let t=$("Error: missing target branch argument"),e=await R("HEAD",t),{promise:o,resolve:r,reject:i}=Promise.withResolvers(),n=ae("git",["merge-tree",e,"HEAD",t]),a=ce({input:n.stdout,crlfDelay:1/0}),m=!1,f=0;a.on("line",p=>{p=p.trimEnd(),p==="+<<<<<<< .our"?(m=!0,console.info(Y.red(p)),f+=1):p==="+>>>>>>> .their"?(m=!1,console.info(Y.green(p))):p==="+======="?console.info(Y.yellow(p)):m&&console.info(p)}),a.on("close",()=>r(f)),n.on("error",i);let x=await o,I=x?`\u274C ${x} conflicts would occur!`:"\u2705 No conflicts. Safe to merge.";console.info(I)}async function bt(){let{merge:t,rebaseMerge:e,rebaseApply:o,cherryPick:r,revert:i}=await N(),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 le}from"node:fs";import{readFile as me}from"node:fs/promises";async function U(t){return(await me(t,"utf-8")).split(/\r?\n/).map(o=>o.trim()).filter(o=>o&&!o.startsWith("#"))}async function $t(){let t=await D("info/exclude");await M(t);let e=await U(t);g().forEach(o=>{e.includes(o)?console.info(`Already Exists: '${o}'`):(le(t,`${o}
4
- `),console.info(`Added '${o}'`))}),console.info(`
5
- See file at ${t}`)}function xt(){u("git",["show","--name-only","--pretty=format:",...g()],{stdio:"inherit",silent:!0,triggerExit:!0})}import{spawn as fe}from"node:child_process";async function Rt(){let t=$("Error: missing valid target ref argument");await v();let e=await ot(t);await l(["commit",`--fixup=${e}`]);let r=(await F(`${e}^`,"HEAD",!0)).map(n=>pe(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 pe(t){let{stdout:e}=await s(`git diff ${t}^ ${t}`),{promise:o,resolve:r,reject:i}=Promise.withResolvers(),n=fe("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 ge,writeFile as ue}from"node:fs/promises";async function Ct(){let t=await D("info/exclude");await M(t);let e=await U(t),o=g();o.filter(a=>!e.includes(a)).forEach(a=>console.info(`No match: '${a}'`));let i=(await ge(t,"utf-8")).split(/\r?\n/).map(a=>a.trim()),n=i.filter(a=>!o.includes(a));await ue(t,n.join(`
6
- `)),console.info(`
7
- Removed ${i.length-n.length} entries from ${t}`)}import{render as we}from"ink";import{jsx as be}from"react/jsx-runtime";async function Pt(){let t=(async()=>{let i=await he();return await de(i)})();we(be(c,{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)}% - ${ye(n)}`);console.log(r.join(`
8
- `))}async function he(){let{stdout:t}=await s("gh repo view --json nameWithOwner -q .nameWithOwner");return t.trim()}async function de(t){let{stdout:e}=await s(`gh api repos/${t}/languages`);return JSON.parse(e.trim())}function ye(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{execSync as $e}from"node:child_process";function xe(){return $e("git rev-parse --show-toplevel",{encoding:"utf-8"}).trim()}function vt(){let t=xe();console.log(t)}import{render as Dt}from"ink";function At(){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 A(){let t=At();await s("git add -A"),await l(["commit","-m",`"WIP ${t}"`])}import{nanoid as Re}from"nanoid";import Ce from"chalk";import{jsx as St}from"react/jsx-runtime";async function Et(){let{remote:t,branch:e}=await k(),o=process.argv[3]??e;await d()||await A(),await et(o,"HEAD")||(console.warn("Conflicts would occur. Not safe to rebranch."),process.exit(1));let r=await h(),i=(async()=>{await q(t,o)})();Dt(St(c,{msg:`Updating branch ${o}`,promise:i})),await i;let n=`${Re(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 m=await F(o,n,!0);for(let f of m)try{await s(`git cherry-pick ${f}`)}catch{let x=Ce.yellow(`git branch -D ${r} && git branch -m ${n} ${r}`);throw new Error(`\u274C cherry pick failed at ${f}
9
- Run this to restore backup branch
10
- > ${x}`)}await s(`git branch -D ${n}`)})();Dt(St(c,{msg:`Rewriting branch ${r}`,promise:a})),await a,console.info(`Successfully recreated branch ${r} from ${o}`)}import{execSync as Pe}from"node:child_process";async function qt(){C();let t=ve(process.argv[3]),{default:e}=await import("clipboardy");await e.write(t),console.log(`'${t}' copied to clipboard`)}function ve(t="HEAD"){return Pe(`git rev-parse --short ${t}`,{encoding:"utf-8"}).trim()}import{render as Ae}from"ink";import{jsx as De}from"react/jsx-runtime";async function kt(){let{remote:t,branch:e}=await z();b(t),await P();let o=W(t,e);Ae(De(c,{msg:`Fetching branch ${e} from ${t}`,promise:o})),await o,await l(["switch","-c",e,"--track",`${t}/${e}`])}async function J(){let{stdout:t}=await s("npm list -g bisgit --depth=0 --json");return JSON.parse(t.trim()).dependencies.bisgit.version}async function Bt(){console.info(await J())}async function Se(){let{code:t}=await w("npm",["outdated","-g","bisgit"]);return t===0}async function Ee(){let{stdout:t}=await s("npm view bisgit version",{encoding:"utf8"});return t.trim()}async function Ht(){if(await Se())return console.info("Already up to date");console.info(`Updating: ${await J()} -> ${await Ee()}`),u("npm",["i","-g","bisgit@latest"])}async function Wt(){let[t,e]=await Promise.allSettled([await ke("user.name"),await qe()]);t.status==="fulfilled"&&console.info(`Git: ${t.value}`),e.status==="fulfilled"&&console.info(`Github: ${e.value}`)}async function qe(){let{stdout:t}=await s("gh api user --jq .login");return t.trim()}async function ke(t){let{stdout:e}=await s(`git config ${t}`);return e.trim()}import{render as Me}from"ink";import{Text as Be,useApp as He,useInput as We}from"ink";import{useState as Ge}from"react";import{Fragment as Ne,jsx as Fe,jsxs as Gt}from"react/jsx-runtime";function Ft({prompt:t,msg:e,onConfirm:o}){let[r,i]=Ge(""),{exit:n}=He();return We((a,m)=>{if(r)return;let f=a.toLowerCase();f==="y"?i("Yes"):(f==="n"||m.return)&&(i("No"),n())}),Gt(Ne,{children:[Gt(Be,{children:[t," [y/N] ",r]}),r==="Yes"&&Fe(c,{msg:e,promise:o()})]})}import{jsx as Te}from"react/jsx-runtime";async function Nt(){if(at(),await d())return console.log("Already a clean working tree");let t=await G();if(!t)throw new Error("git status cmd failed");let e=new K(t);e.displayReport(),Me(Te(Ft,{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 K=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}
11
- ${o.map(r=>`- ${r}
12
- `)}`)}};import{nanoid as Le}from"nanoid";import{render as Ue}from"ink";import{jsx as Ie}from"react/jsx-runtime";async function Mt(){await T();let t=process.argv[3]??"origin";b(t);let e=await h();ct(e);let o="",i=(async()=>{let n=[s(`git fetch ${t} ${e} --force`)];await d()||n.push(A()),await Promise.all(n);let[a,m]=await Promise.all([B(t,e),H(t,e)]);if(!(a===0&&m===0)){if(a!==0){let f=`${e}-${Le(8)}`;o=`Created branch ${f}`,await s(`git branch ${f}`)}await s(`git reset --hard ${t}/${e}`)}})();Ue(Ie(c,{msg:`Force pull reseting ${e} -> ${t}`,promise:i})),await i,o&&console.info(o)}var Tt={abort:nt,amend:mt,autoprune:ut,backmerge:ft,churn:wt,coauthor:ht,"code-review":dt,conflict:yt,continue:bt,exclude:$t,files:xt,fixup:Rt,include:Ct,languages:Pt,pwd:vt,rebranch:Et,"remote-default":gt,savepoint:A,sha:qt,track:kt,update:Ht,"--version":Bt,whoami:Wt,wipe:Nt,yank:Mt};async function nn(t){return await Tt[t]?.(),Object.hasOwn(Tt,t)}export{nn as runCommand};
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- import{a as oe,j as re,k as ne,p as ie,q as se,r as ce}from"./chunk-C7H7IYZ2.js";import{b as y}from"./chunk-HCUVDNFV.js";import{render as to}from"ink";import{createContext as _e,useContext as Ye,useState as qe}from"react";import{jsx as Qe}from"react/jsx-runtime";var ae=_e(void 0),de=({children:e})=>{let[t,o]=qe({}),r=(n,s)=>{o(c=>({...c,[n]:s}))},i=n=>{let s=Array.isArray(n)?n:[n];o(c=>{let d={...c};for(let m of s)delete d[m];return d})};return Qe(ae.Provider,{value:{keybindings:t,setKeybinding:r,removeKeybinding:i},children:e})},S=()=>{let e=Ye(ae);if(!e)throw new Error("useKeybindings must be used within a KeybindingsProvider");return e};import{useEffect as Xt}from"react";import{Text as Zt,Box as Fe,useInput as jt}from"ink";import{useStdout as Je}from"ink";function g(){let{stdout:e}=Je(),t=e.rows-2,o=Math.floor(t/2);return{width:e.columns,height:e.rows,sectionHeight:t,sectionHalfHeight:o}}import{Box as ue,Text as je}from"ink";import{useState as E,createContext as ze,useContext as Xe}from"react";import{jsx as Ze}from"react/jsx-runtime";var M={Status:"Status",Log:"Log","Commit Details":"Log",Branches:"Branches",Worktrees:"Branches",Remotes:"Branches"},L=Object.keys(M),le=ze({});function me({children:e}){let[t,o]=E(!1),r=()=>o(!0),i=()=>o(!1),[n,s]=E("Status"),[c,d]=E("Status"),m=a=>{t||(d(a),s(M[a]))},u=a=>{t||(s(a),d(a))},f=()=>{t||d(a=>{let l=L.at((L.indexOf(a)+1)%L.length);return s(M[l]),l})},p=()=>{t||d(a=>{let l=L.at(L.indexOf(a)-1);return s(M[l]),l})};return Ze(le.Provider,{value:{activeGroup:n,setActiveGroup:u,activeSection:c,setActiveSection:m,prevSection:p,nextSection:f,isLocked:t,lock:r,unlock:i},children:e})}function h(){let e=Xe(le);if(!e)throw new Error("useNavContext must be used within a NavProvider");return e}import{jsx as H}from"react/jsx-runtime";var et=Array.from(new Set(Object.values(M)));function fe(){let{activeGroup:e}=h();return H(ue,{width:"100%",flexDirection:"row",children:et.map((t,o)=>H(ue,{borderStyle:"classic",borderLeft:!!o,borderRight:!1,borderTop:!1,borderBottom:!1,children:H(je,{color:t===e?"cyan":"",children:` [${o+1}]: ${t} `})},t))})}import{Text as Qt,useInput as Jt}from"ink";import{Box as pe,measureElement as tt,Text as ge}from"ink";import{useMemo as ot,useRef as rt}from"react";import{Fragment as nt,jsx as D,jsxs as it}from"react/jsx-runtime";function v(e){let{title:t,footer:o,children:r,width:i,height:n,innerHeight:s,isModal:c,backgroundColor:d}=e,{width:m}=g(),u=i??m,f=rt(null),p=ot(()=>{if(!f.current)return 0;let{width:V}=tt(f.current);return V},[f.current]),a=p-8,l={...e,height:s,width:p},{activeSection:w}=h(),B=w===t||c?"cyan":"";return D(pe,{ref:f,flexDirection:"column",height:n,width:u,backgroundColor:d,children:p!==0&&it(nt,{children:[t&&D(ge,{color:B,wrap:"truncate-end",children:"\u256D\u2500\u2500\u2500\u2500 "+t+" "+"\u2500".repeat(a-t.length)+"\u256E"}),D(pe,{flexDirection:"column",...l,borderStyle:"round",borderColor:B,borderTop:!t,borderBottom:!o,paddingLeft:1,children:r}),o&&D(ge,{color:B,wrap:"truncate-end",children:"\u2570"+"\u2500".repeat(a-o.length)+" "+o+" \u2500\u2500\u2500\u2500\u256F"})]})})}import{Text as ct}from"ink";import{useEffect as st,useState as G}from"react";function x(e,t=[]){let[o,r]=G(void 0),[i,n]=G(!1),[s,c]=G(0),d=()=>c(m=>m+1);return st(()=>{let m=!1;return n(!1),r(void 0),e().then(u=>{m||(r(u),n(!0))}).catch(()=>{m||n(!0)}),()=>{m=!0}},[s,...t]),{value:o,resolved:i,refresh:d}}import{jsx as he}from"react/jsx-runtime";function $(){let{value:e,resolved:t}=x(ne);return he(v,{flexDirection:"column",title:"Bisgit",width:"100%",children:t&&e?.map((o,r)=>he(ct,{children:o},r))})}import{useEffect as At,useState as Ne}from"react";import{Box as Wt,useInput as It}from"ink";import{Text as at}from"ink";import{jsx as xe}from"react/jsx-runtime";function ve({sha:e}){let{resolved:t,value:o}=x(()=>dt(e),[e]);return xe(v,{title:"Commit Details",width:"50%",height:"100%",children:e&&t&&xe(at,{children:o})})}async function dt(e){if(!e)return;let{stdout:t}=await y(`git show ${e} --name-only`);return t.trim()}import{useEffect as mt}from"react";import{Box as K,Text as F,useInput as ut}from"ink";import{useEffect as lt,useState as ye}from"react";function R(e,t){let[o,r]=ye(0),[i,n]=ye(0);lt(()=>{r(0),n(0)},[e]);let s=Math.max(0,e.length-t),c=e.length-1,d=()=>{n(p=>{let a=Math.min(p+1,c);return r(l=>a>=l+t?Math.min(l+1,s):l),a})},m=()=>{n(p=>{let a=Math.max(p-1,0);return r(l=>a<l?Math.max(l-1,0):l),a})},u=e.slice(o,o+t),f=e[i];return{scrollDown:d,scrollUp:m,outList:u,selectedIndex:i,selectedValue:f}}import{jsx as C,jsxs as ft}from"react/jsx-runtime";function be({setSha:e,mode:t}){let{label:o,value:r}=t,{sectionHeight:i}=g(),{activeSection:n,isLocked:s}=h(),{resolved:c,value:d=[]}=x(r,[o]),{scrollUp:m,scrollDown:u,outList:f,selectedValue:p}=R(d,i-2),a=p?.sha;return mt(()=>{e(a)},[a]),ut((l,w)=>{n!=="Log"||s||(w.upArrow?m():w.downArrow&&u())}),C(v,{overflowY:"hidden",height:"100%",title:"Log",width:"50%",children:c&&f.map(({sha:l,message:w})=>ft(K,{flexDirection:"row",flexWrap:"nowrap",children:[C(K,{minWidth:2,children:l===a?C(F,{children:"> "}):null}),C(K,{minWidth:8,children:C(F,{color:"yellow",children:l})}),C(K,{children:C(F,{wrap:"truncate-end",children:w})})]},`${l}-${t}`))})}import{useState as Bt}from"react";import{useInput as Lt}from"ink";import Dt from"ink-text-input";import{useInput as pt}from"ink";import{createContext as gt,useContext as ht,useEffect as xt,useState as Se}from"react";import{Fragment as vt,jsx as bt,jsxs as yt}from"react/jsx-runtime";var we=gt({});function T(){let e=ht(we);if(!e)throw new Error("useKeybindings must be used within a KeybindingsProvider");return e}function Te({children:e}){let[t,o]=Se(null),{lock:r,unlock:i}=h(),[n,s]=Se(!1),c=()=>{i(),s(!1)},d=()=>{r(),s(!0)},m=()=>{n?c():d()},u=a=>{c(),o(a)};pt((a,l)=>{l.escape&&c()});let{setKeybinding:f,removeKeybinding:p}=S();return xt(()=>{if(n)return f("esc","close"),()=>{p("esc")}},[n]),bt(we.Provider,{value:{setModal:u,open:d,close:c,toggle:m,isOpen:n},children:yt(vt,{children:[e,t]})})}import{Box as Pe}from"ink";import U from"node:path";import _ from"node:os";import St from"node:fs/promises";import{createContext as wt,useContext as Tt}from"react";import{jsx as Pt}from"react/jsx-runtime";var Ce=wt({});function ke({children:e}){let{value:t}=x(Ct);return Pt(Ce.Provider,{value:{bgColor:t},children:e})}var Me=()=>{let e=Tt(Ce);if(!e)throw new Error("useKeybindings must be used within a KeybindingsProvider");return e};async function Ct(){if(!(!process.stdin.isTTY||!process.stdout.isTTY))return process.env.TERM_PROGRAM==="vscode"?await Mt():new Promise(e=>{let t="\x1B]11;?\x07",o="",r,i=s=>{clearTimeout(r),process.stdin.off("data",n);try{process.stdin.setRawMode(!1),process.stdin.pause()}catch{}e(s)},n=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 d=kt(c[1],c[2],c[3]);i(d)}};try{process.stdin.setRawMode(!0),process.stdin.resume(),process.stdin.on("data",n),r=setTimeout(()=>i(void 0),150),process.stdout.write(t)}catch{i(void 0)}})}function kt(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 Mt(){let e="Code";process.env.TERM_PROGRAM_VERSION?.includes("insider")&&(e="Code - Insiders");let t;switch(process.platform){case"win32":t=U.join(_.homedir(),"AppData","Roaming",e,"User","settings.json");break;case"linux":t=U.join(_.homedir(),".config",e,"User","settings.json");break;case"darwin":t=U.join(_.homedir(),"Library","Application Support",e,"User","settings.json");break;default:return}if(!await ce(t))return;let o=await St.readFile(t,{encoding:"utf-8"}),{default:r}=await import("strip-json-comments"),i=r(o).replace(/,\s*(\}|\])/g,"$1");switch(JSON.parse(i)["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 Y}from"react/jsx-runtime";var Be=36;function N({children:e,title:t}){let o=g(),{width:r}=o,i=Math.floor((r-Be)/2),{bgColor:n}=Me();return Y(Pe,{...o,position:"absolute",children:Y(Pe,{alignSelf:"center",marginLeft:i,marginRight:i,children:Y(v,{title:t,width:Be,isModal:!0,backgroundColor:n,children:e})})})}import{jsx as Le}from"react/jsx-runtime";function De({title:e,handleSubmit:t}){let[o,r]=Bt(""),{isOpen:i,close:n}=T();return Lt((s,c)=>{c.return&&i&&(t(o),r(""),n())}),i&&Le(N,{title:e,children:Le(Dt,{value:o,onChange:r})})}import{useInput as Rt}from"ink";import Kt from"ink-select-input";import{jsx as Re}from"react/jsx-runtime";function Ke({title:e,handleSubmit:t,options:o,initialIndex:r}){let{isOpen:i,close:n}=T();return Rt((s,c)=>{c.return&&i&&n()}),i&&Re(N,{title:e,children:Re(Kt,{items:o,onSelect:t,initialIndex:r})})}var A=[{value:()=>q("git log --oneline -n 400"),label:"log"},{value:()=>q("git log --oneline --tags --no-walk --decorate"),label:"tags"},{value:()=>q("git reflog"),label:"reflog"}];async function q(e){let{stdout:t}=await y(e);return t.trim().split(/\r?\n/).map(Nt)}function Nt(e){let t=e.indexOf(" ");return{sha:e.slice(0,t),message:e.slice(t+1)}}import{jsx as Q,jsxs as Ot}from"react/jsx-runtime";function J(){let{setModal:e,toggle:t}=T(),[o,r]=Ne(),{width:i,sectionHeight:n}=g(),[s,c]=Ne(A[0]),{isLocked:d}=h();It((f,p)=>{f==="m"&&(e(Q(Ke,{options:A,title:"Log Type",handleSubmit:c,initialIndex:A.indexOf(s)})),t()),!d&&f==="c"&&o&&re().then(a=>{a&&y(`git checkout ${o}`)})});let{setKeybinding:m,removeKeybinding:u}=S();return At(()=>(m("c","checkout"),m("m","mode"),()=>{u(["c","m"])}),[]),Ot(Wt,{width:i,height:n,children:[Q(be,{setSha:r,mode:s}),Q(ve,{sha:o})]})}import{useEffect as Yt}from"react";import{Box as Ee}from"ink";import{Box as z,Text as Ae,useInput as Vt}from"ink";import{useEffect as Et}from"react";import{Fragment as Gt,jsx as k,jsxs as Ht}from"react/jsx-runtime";function We(){let{activeSection:e,isLocked:t}=h(),{sectionHalfHeight:o}=g(),{value:r=[],refresh:i}=x(ie),{value:n,refresh:s}=x(oe),{setKeybinding:c,removeKeybinding:d}=S();Et(()=>{if(e==="Branches")return c("s","switch"),()=>{d("s")}},[e]);let{outList:m,selectedValue:u,scrollUp:f,scrollDown:p}=R(r,o-2),a=async b=>{await y(`git branch ${b}`),i()},l=async()=>{await y(`git branch -D ${u}`),i()},w=async()=>{await y(`git switch ${u}`),i(),s()},{setModal:B,open:V}=T();return Vt((b,te)=>{e!=="Branches"||t||(te.upArrow?f():te.downArrow?p():b==="c"?(B(k(De,{title:"Name your new branch",handleSubmit:a})),V()):b==="d"?l():b==="s"&&w())}),k(Gt,{children:k(v,{width:"100%",title:"Branches",innerHeight:o-1,children:m.map(b=>Ht(z,{flexDirection:"row",flexWrap:"nowrap",children:[k(z,{minWidth:2,children:b===u?k(Ae,{children:"> "}):null}),k(z,{minWidth:8,children:k(Ae,{color:b===n?"magenta":void 0,children:b})})]},b))})})}import{Text as X}from"ink";import{Fragment as $t}from"react";import{jsx as Z,jsxs as Ie}from"react/jsx-runtime";function Oe(){let{value:e}=x(se);return Z(v,{width:"50%",title:"Remotes",children:e?.map(({url:t,name:o,type:r})=>Ie($t,{children:[Ie(X,{wrap:"truncate-end",children:[o," (",r,")"]}),Z(X,{wrap:"truncate-end",children:t}),Z(X,{children:" "})]},`${o}-${r}`))})}import{Text as j}from"ink";import{Fragment as Ft}from"react";import{jsx as W,jsxs as _t}from"react/jsx-runtime";function Ve(){let{sectionHalfHeight:e}=g(),{value:t}=x(Ut);return W(v,{width:"100%",title:"Worktrees",innerHeight:e-1,children:t?.map(({branch:o,detached:r,path:i,head:n})=>_t(Ft,{children:[W(j,{children:r?n:o}),W(j,{children:i}),W(j,{children:" "})]},i))})}async function Ut(){let{stdout:e}=await y("git worktree list --porcelain"),t=e.trim().split(/\r?\n/),o=[],r=[];for(let i of t)i.trim()===""?r.length&&(o.push(r),r=[]):r.push(i);return r.length&&o.push(r),o.map(i=>{let n={detached:!1};for(let s of i)s.startsWith("worktree ")?n.path=s.slice(9):s.startsWith("HEAD ")?n.head=s.slice(5):s.startsWith("branch ")?n.branch=s.slice(7):s==="detached"&&(n.detached=!0);return n})}import{Fragment as qt,jsx as I,jsxs as He}from"react/jsx-runtime";function Ge(){let{width:e,sectionHeight:t}=g(),{setKeybinding:o,removeKeybinding:r}=S();return Yt(()=>(o("c","create"),o("d","delete"),()=>{r(["c","d"])}),[]),I(qt,{children:He(Ee,{width:e,height:t,children:[He(Ee,{flexDirection:"column",width:"50%",height:t,children:[I(We,{}),I(Ve,{})]}),I(Oe,{})]})})}import{jsx as ee,jsxs as zt}from"react/jsx-runtime";function $e(){let{prevSection:e,nextSection:t,activeGroup:o,setActiveGroup:r}=h();switch(Jt((i,n)=>{n.tab&&n.shift?e():n.tab?t():i==="1"?r("Status"):i==="2"?r("Log"):i==="3"&&r("Branches")}),o){case"Status":return ee($,{});case"Log":return ee(J,{});case"Branches":return ee(Ge,{});default:return zt(Qt,{children:["Error, unknown page ",o]})}}import{jsx as O,jsxs as eo}from"react/jsx-runtime";function Ue(){let{isLocked:e}=h();jt((i,n)=>{e||i.toLowerCase()==="q"&&process.exit()});let t=g(),{keybindings:o,setKeybinding:r}=S();return Xt(()=>r("q","quit"),[]),eo(Fe,{flexDirection:"column",...t,children:[O(fe,{}),O($e,{}),O(Fe,{flexDirection:"row",children:Object.entries(o).map(([i,n])=>O(Zt,{children:`[${i}]: ${n} `},n))})]})}import{jsx as P}from"react/jsx-runtime";function oo(){return P(ke,{children:P(me,{children:P(de,{children:P(Te,{children:P(Ue,{})})})})})}var ei=()=>to(P(oo,{}),{patchConsole:!0});export{ei as renderApp};