Skip to content

Commit 850b84a

Browse files
author
João Pedro
committed
feat: create and delete branches
0 parents  commit 850b84a

File tree

13 files changed

+940
-0
lines changed

13 files changed

+940
-0
lines changed

.github/workflows/release.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: release
2+
on:
3+
push:
4+
tags:
5+
- "v*"
6+
permissions:
7+
contents: write
8+
9+
jobs:
10+
release:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
- uses: cli/gh-extension-precompile@v1

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/gh-b
2+
/gh-b.exe

go.mod

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
module github.com/joaom00/gh-b
2+
3+
go 1.17
4+
5+
require github.com/cli/go-gh v0.0.3
6+
7+
require (
8+
github.com/atotto/clipboard v0.1.4 // indirect
9+
github.com/containerd/console v1.0.3 // indirect
10+
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
11+
github.com/mattn/go-isatty v0.0.14 // indirect
12+
github.com/mattn/go-runewidth v0.0.13 // indirect
13+
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b // indirect
14+
github.com/muesli/reflow v0.3.0 // indirect
15+
github.com/muesli/termenv v0.11.1-0.20220212125758-44cd13922739 // indirect
16+
github.com/rivo/uniseg v0.2.0 // indirect
17+
github.com/sahilm/fuzzy v0.1.0 // indirect
18+
golang.org/x/sys v0.0.0-20210816183151-1e6c022a8912 // indirect
19+
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b // indirect
20+
)
21+
22+
require (
23+
github.com/charmbracelet/bubbles v0.10.3
24+
github.com/charmbracelet/bubbletea v0.20.0
25+
github.com/charmbracelet/lipgloss v0.5.0
26+
github.com/cli/safeexec v1.0.0 // indirect
27+
github.com/cli/shurcooL-graphql v0.0.1 // indirect
28+
github.com/henvic/httpretty v0.0.6 // indirect
29+
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 // indirect
30+
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
31+
)

go.sum

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
github.com/MakeNowJust/heredoc v1.0.0 h1:cXCdzVdstXyiTqTvfqk9SDHpKNjxuom+DOlyEeQ4pzQ=
2+
github.com/MakeNowJust/heredoc v1.0.0/go.mod h1:mG5amYoWBHf8vpLOuehzbGGw0EHxpZZ6lCpQ4fNJ8LE=
3+
github.com/atotto/clipboard v0.1.2/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
4+
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
5+
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
6+
github.com/charmbracelet/bubbles v0.8.0/go.mod h1:5WX1sSSjNCgCrzvRMN/z23HxvWaa+AI16Ch0KPZPeDs=
7+
github.com/charmbracelet/bubbles v0.10.3 h1:fKarbRaObLn/DCsZO4Y3vKCwRUzynQD9L+gGev1E/ho=
8+
github.com/charmbracelet/bubbles v0.10.3/go.mod h1:jOA+DUF1rjZm7gZHcNyIVW+YrBPALKfpGVdJu8UiJsA=
9+
github.com/charmbracelet/bubbletea v0.13.1/go.mod h1:tp9tr9Dadh0PLhgiwchE5zZJXm5543JYjHG9oY+5qSg=
10+
github.com/charmbracelet/bubbletea v0.16.0/go.mod h1:YTZSs2p3odhwYZdhqJheYHVUjU37c9OLgS85kw6NGQY=
11+
github.com/charmbracelet/bubbletea v0.19.3/go.mod h1:VuXF2pToRxDUHcBUcPmCRUHRvFATM4Ckb/ql1rBl3KA=
12+
github.com/charmbracelet/bubbletea v0.20.0 h1:/b8LEPgCbNr7WWZ2LuE/BV1/r4t5PyYJtDb+J3vpwxc=
13+
github.com/charmbracelet/bubbletea v0.20.0/go.mod h1:zpkze1Rioo4rJELjRyGlm9T2YNou1Fm4LIJQSa5QMEM=
14+
github.com/charmbracelet/harmonica v0.1.0/go.mod h1:KSri/1RMQOZLbw7AHqgcBycp8pgJnQMYYT8QZRqZ1Ao=
15+
github.com/charmbracelet/lipgloss v0.1.2/go.mod h1:5D8zradw52m7QmxRF6QgwbwJi9je84g8MkWiGN07uKg=
16+
github.com/charmbracelet/lipgloss v0.3.0/go.mod h1:VkhdBS2eNAmRkTwRKLJCFhCOVkjntMusBDxv7TXahuk=
17+
github.com/charmbracelet/lipgloss v0.4.0/go.mod h1:vmdkHvce7UzX6xkyf4cca8WlwdQ5RQr8fzta+xl7BOM=
18+
github.com/charmbracelet/lipgloss v0.5.0 h1:lulQHuVeodSgDez+3rGiuxlPVXSnhth442DATR2/8t8=
19+
github.com/charmbracelet/lipgloss v0.5.0/go.mod h1:EZLha/HbzEt7cYqdFPovlqy5FZPj0xFhg5SaqxScmgs=
20+
github.com/cli/go-gh v0.0.3 h1:GcVgUa7q0SeauIRbch3VSUXVij6+c49jtAHv7WuWj5c=
21+
github.com/cli/go-gh v0.0.3/go.mod h1:J1eNgrPJYAUy7TwPKj7GW1ibqI+WCiMndtyzrCyZIiQ=
22+
github.com/cli/safeexec v1.0.0 h1:0VngyaIyqACHdcMNWfo6+KdUYnqEr2Sg+bSP1pdF+dI=
23+
github.com/cli/safeexec v1.0.0/go.mod h1:Z/D4tTN8Vs5gXYHDCbaM1S/anmEDnJb1iW0+EJ5zx3Q=
24+
github.com/cli/shurcooL-graphql v0.0.1 h1:/9J3t9O6p1B8zdBBtQighq5g7DQRItBwuwGh3SocsKM=
25+
github.com/cli/shurcooL-graphql v0.0.1/go.mod h1:U7gCSuMZP/Qy7kbqkk5PrqXEeDgtfG5K+W+u8weorps=
26+
github.com/containerd/console v1.0.1/go.mod h1:XUsP6YE/mKtz6bxc+I8UiKKTP04qjQL4qcS3XoQ5xkw=
27+
github.com/containerd/console v1.0.2/go.mod h1:ytZPjGgY2oeTkAONYafi2kSj0aYggsf8acV1PGKCbzQ=
28+
github.com/containerd/console v1.0.3 h1:lIr7SlA5PxZyMV30bDW0MGbiOPXwc63yRuCP0ARubLw=
29+
github.com/containerd/console v1.0.3/go.mod h1:7LqA/THxQ86k76b8c/EMSiaJ3h1eZkMkXar0TQ1gf3U=
30+
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
31+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
32+
github.com/erikgeiser/promptkit v0.6.0 h1:Cxw/MBLZ+dxF7iOHMi/Z8dSi1vZeobPJsx8phAnsgW4=
33+
github.com/erikgeiser/promptkit v0.6.0/go.mod h1:NfO1VleTDkelTUpIPkrxEifJxkU2M3cToKaVHFjxEa0=
34+
github.com/google/goterm v0.0.0-20190703233501-fc88cf888a3f/go.mod h1:nOFQdrUlIlx6M6ODdSpBj1NVA+VgLC6kmw60mkw34H4=
35+
github.com/henvic/httpretty v0.0.6 h1:JdzGzKZBajBfnvlMALXXMVQWxWMF/ofTy8C3/OSUTxs=
36+
github.com/henvic/httpretty v0.0.6/go.mod h1:X38wLjWXHkXT7r2+uK8LjCMne9rsuNaBLJ+5cU2/Pmo=
37+
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
38+
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
39+
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
40+
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
41+
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
42+
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
43+
github.com/lucasb-eyer/go-colorful v1.0.3/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
44+
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
45+
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
46+
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
47+
github.com/mattn/go-isatty v0.0.13/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
48+
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
49+
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
50+
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
51+
github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
52+
github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
53+
github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
54+
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
55+
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b h1:1XF24mVaiu7u+CFywTdcDo2ie1pzzhwjt6RHqzpMU34=
56+
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b/go.mod h1:fQuZ0gauxyBcmsdE3ZT4NasjaRdxmbCS0jRHsrWu3Ho=
57+
github.com/muesli/reflow v0.2.1-0.20210115123740-9e1d0d53df68/go.mod h1:Xk+z4oIWdQqJzsxyjgl3P22oYZnHdZ8FFTHAQQt5BMQ=
58+
github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s=
59+
github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8=
60+
github.com/muesli/termenv v0.7.2/go.mod h1:ct2L5N2lmix82RaY3bMWwVu/jUFc9Ule0KGDCiKYPh8=
61+
github.com/muesli/termenv v0.8.1/go.mod h1:kzt/D/4a88RoheZmwfqorY3A+tnsSMA9HJC/fQSFKo0=
62+
github.com/muesli/termenv v0.9.0/go.mod h1:R/LzAKf+suGs4IsO95y7+7DpFHO0KABgnZqtlyx2mBw=
63+
github.com/muesli/termenv v0.11.1-0.20220204035834-5ac8409525e0/go.mod h1:Bd5NYQ7pd+SrtBSrSNoBBmXlcY8+Xj4BMJgh8qcZrvs=
64+
github.com/muesli/termenv v0.11.1-0.20220212125758-44cd13922739 h1:QANkGiGr39l1EESqrE0gZw0/AJNYzIvoGLhIoVYtluI=
65+
github.com/muesli/termenv v0.11.1-0.20220212125758-44cd13922739/go.mod h1:Bd5NYQ7pd+SrtBSrSNoBBmXlcY8+Xj4BMJgh8qcZrvs=
66+
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
67+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
68+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
69+
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
70+
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
71+
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
72+
github.com/sahilm/fuzzy v0.1.0 h1:FzWGaw2Opqyu+794ZQ9SYifWv2EIXpwP4q8dY1kDAwI=
73+
github.com/sahilm/fuzzy v0.1.0/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y=
74+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
75+
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
76+
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
77+
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
78+
golang.org/x/crypto v0.0.0-20201012173705-84dcc777aaee/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
79+
golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
80+
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
81+
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 h1:CIJ76btIcR3eFI5EgSo6k1qKw9KJexJuRLI9G7Hp5wE=
82+
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
83+
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
84+
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
85+
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
86+
golang.org/x/sys v0.0.0-20200916030750-2334cc1a136f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
87+
golang.org/x/sys v0.0.0-20201009025420-dfb3f7c4e634/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
88+
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
89+
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
90+
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
91+
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
92+
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
93+
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I=
94+
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
95+
golang.org/x/sys v0.0.0-20210816183151-1e6c022a8912 h1:uCLL3g5wH2xjxVREVuAbP9JM5PPKjRbXKRa6IBjkzmU=
96+
golang.org/x/sys v0.0.0-20210816183151-1e6c022a8912/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
97+
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
98+
golang.org/x/term v0.0.0-20210422114643-f5beecf764ed h1:Ei4bQjjpYUsS4efOUz+5Nz++IVkHk87n2zBA0NxBWc0=
99+
golang.org/x/term v0.0.0-20210422114643-f5beecf764ed/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
100+
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b h1:9zKuko04nR4gjZ4+DNjHqRlAJqbJETHwiNKDqTfOjfE=
101+
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
102+
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
103+
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
104+
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
105+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
106+
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
107+
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
108+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
109+
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
110+
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

internal/git/git.go

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package git
2+
3+
import (
4+
"os/exec"
5+
"strings"
6+
)
7+
8+
type Branch struct {
9+
Name string
10+
AuthorName string
11+
CommitterDate string
12+
Track string
13+
RemoteName string
14+
}
15+
16+
func (i Branch) FilterValue() string { return "" }
17+
18+
const format = `branch:%(refname:short)%(HEAD)
19+
authorname:%(authorname)
20+
committerdate:%(committerdate:relative)
21+
track:%(upstream:track)
22+
remotename:%(upstream:short)
23+
`
24+
25+
func GetAllBranches() (branches []Branch, err error) {
26+
cmd := exec.Command(
27+
"git",
28+
"for-each-ref",
29+
"refs/heads",
30+
"refs/remotes",
31+
"--sort",
32+
"-committerdate",
33+
"--sort",
34+
"-upstream",
35+
"upstream",
36+
"--format",
37+
format,
38+
)
39+
40+
out, err := cmd.CombinedOutput()
41+
if err != nil {
42+
return
43+
}
44+
45+
s := strings.Split(strings.TrimSpace(string(out)), "\n\n")
46+
47+
for _, branch := range s {
48+
fields := strings.Split(branch, "\n")
49+
50+
branch := strings.TrimPrefix(fields[0], "branch:")
51+
authorname := strings.TrimPrefix(fields[1], "authorname:")
52+
committerdate := strings.TrimPrefix(fields[2], "committerdate:")
53+
track := strings.TrimPrefix(fields[3], "track:")
54+
remotename := strings.TrimPrefix(fields[4], "remotename:")
55+
branches = append(branches, Branch{
56+
Name: strings.TrimSpace(branch),
57+
AuthorName: strings.TrimSpace(authorname),
58+
CommitterDate: strings.TrimSpace(committerdate),
59+
Track: strings.TrimSpace(track),
60+
RemoteName: strings.TrimSpace(remotename),
61+
})
62+
}
63+
64+
return
65+
}
66+
67+
func CheckoutBranch(branch string) string {
68+
cmd := exec.Command("git", "checkout", branch)
69+
70+
out, err := cmd.CombinedOutput()
71+
if err != nil {
72+
return string(out)
73+
}
74+
75+
return string(out)
76+
}
77+
78+
func CreateBranch(branch string) string {
79+
cmd := exec.Command("git", "checkout", "-b", branch)
80+
81+
out, err := cmd.CombinedOutput()
82+
if err != nil {
83+
return string(out)
84+
}
85+
86+
return string(out)
87+
}
88+
89+
func DeleteBranch(branch string) string {
90+
cmd := exec.Command("git", "branch", "-d", branch)
91+
92+
out, err := cmd.CombinedOutput()
93+
if err != nil {
94+
return string(out)
95+
}
96+
97+
return string(out)
98+
}

internal/tui/branch.go

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
package tui
2+
3+
// import (
4+
// "fmt"
5+
// "strings"
6+
7+
// tea "github.com/charmbracelet/bubbletea"
8+
// "github.com/joaom00/gh-b/internal/git"
9+
// )
10+
11+
// func (m Model) checkoutBranch() (tea.Model, tea.Cmd) {
12+
// branch := strings.TrimSuffix(m.branches[m.cursor].Branch, "*")
13+
// out := git.CheckoutBranch(branch)
14+
15+
// fmt.Println("\n\n", out)
16+
// return m, tea.Quit
17+
// }
18+
19+
// func (m *Model) createBranch() (tea.Model, tea.Cmd) {
20+
// switch m.confirmInput.Value() {
21+
22+
// case "y":
23+
// out := git.CreateBranch(m.createInput.Value())
24+
25+
// fmt.Println("\n\n", out)
26+
// return m, tea.Quit
27+
// case "n":
28+
// m.createInput.SetValue("")
29+
// m.confirmInput.SetValue("")
30+
// m.createInput.Blur()
31+
// m.confirmInput.Blur()
32+
// m.showConfirmInput = false
33+
// m.actionState = idle
34+
35+
// return m, nil
36+
// default:
37+
// m.NewBranch = m.createInput.Value()
38+
// m.createInput.Blur()
39+
// m.showConfirmInput = true
40+
// m.confirmInput.Focus()
41+
42+
// return m, nil
43+
// }
44+
// }
45+
46+
// func (m *Model) deleteBranch() (tea.Model, tea.Cmd) {
47+
// switch m.confirmInput.Value() {
48+
49+
// case "n":
50+
// m.confirmInput.SetValue("")
51+
// m.confirmInput.Blur()
52+
// m.showConfirmInput = false
53+
// m.actionState = idle
54+
55+
// return m, nil
56+
57+
// default:
58+
// branch := strings.TrimSuffix(m.branches[m.cursor].Branch, "*")
59+
// out := git.DeleteBranch(branch)
60+
61+
// fmt.Println("\n\n", out)
62+
// return m, tea.Quit
63+
// }
64+
// }
65+
66+
// // var (
67+
// // normalTitle = lipgloss.NewStyle().
68+
// // Foreground(lipgloss.AdaptiveColor{Light: "#1a1a1a", Dark: "#dddddd"}).
69+
// // Padding(0, 0, 0, 2)
70+
// // normalDesc = normalTitle.Copy().
71+
// // Foreground(lipgloss.AdaptiveColor{Light: "#A49FA5", Dark: "#777777"})
72+
73+
// // selectedTitle = lipgloss.NewStyle().
74+
// // Border(lipgloss.NormalBorder(), false, false, false, true).
75+
// // BorderForeground(lipgloss.AdaptiveColor{Light: "#F793FF", Dark: "#AD58B4"}).
76+
// // Foreground(lipgloss.AdaptiveColor{Light: "#EE6FF8", Dark: "#EE6FF8"}).
77+
// // Padding(0, 0, 0, 1)
78+
79+
// // selectedDesc = selectedTitle.Copy().
80+
// // Foreground(lipgloss.AdaptiveColor{Light: "#F793FF", Dark: "#AD58B4"})
81+
// // )
82+
83+
// // func (b *Branch) render(isSelected bool) string {
84+
// // var title, desc string
85+
// // // branch := lipgloss.NewStyle().
86+
// // // Foreground(lipgloss.AdaptiveColor{Light: "#1a1a1a", Dark: "#dddddd"}).
87+
// // // // Padding(0, 0, 0, 2).
88+
// // // Render(b.branch)
89+
// // // authorname := lipgloss.NewStyle().
90+
// // // Foreground(lipgloss.AdaptiveColor{Light: "#A49FA5", Dark: "#777777"}).
91+
// // // Render(fmt.Sprintf("%s (%s)", b.authorName, b.committerDate))
92+
93+
// // // remoteName := lipgloss.NewStyle().
94+
// // // Foreground(lipgloss.AdaptiveColor{Light: "#A49FA5", Dark: "#777777"}).
95+
// // // // Padding(0, 0, 0, 2).
96+
// // // Render(b.remoteName)
97+
98+
// // // track := lipgloss.NewStyle().
99+
// // // Foreground(lipgloss.AdaptiveColor{Light: "#A49FA5", Dark: "#777777"}).
100+
// // // // Padding(0, 0, 0, 2).
101+
// // // Render(b.track)
102+
103+
// // if isSelected {
104+
// // title = selectedTitle.Bold(true).Render(b.Branch)
105+
// // desc = selectedDesc.Render(fmt.Sprintf("%s (%s)", b.AuthorName, b.CommitterDate))
106+
// // } else {
107+
// // title = normalTitle.Render(b.Branch)
108+
// // desc = normalDesc.Render(fmt.Sprintf("%s (%s)", b.AuthorName, b.CommitterDate))
109+
// // }
110+
111+
// // return lipgloss.NewStyle().
112+
// // MarginBottom(1).
113+
// // Render(lipgloss.JoinVertical(lipgloss.Left, title, desc))
114+
// // }

0 commit comments

Comments
 (0)