🍰 Personal Multi-Git Remote Manager
go git
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: Initial commit

Fuwn 567e5b51

+1788
+3
.gitignore
··· 1 + /mugi 2 + config.yaml 3 + dev/
+202
LICENSE-APACHE
··· 1 + 2 + Apache License 3 + Version 2.0, January 2004 4 + http://www.apache.org/licenses/ 5 + 6 + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 + 8 + 1. Definitions. 9 + 10 + "License" shall mean the terms and conditions for use, reproduction, 11 + and distribution as defined by Sections 1 through 9 of this document. 12 + 13 + "Licensor" shall mean the copyright owner or entity authorized by 14 + the copyright owner that is granting the License. 15 + 16 + "Legal Entity" shall mean the union of the acting entity and all 17 + other entities that control, are controlled by, or are under common 18 + control with that entity. For the purposes of this definition, 19 + "control" means (i) the power, direct or indirect, to cause the 20 + direction or management of such entity, whether by contract or 21 + otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 + outstanding shares, or (iii) beneficial ownership of such entity. 23 + 24 + "You" (or "Your") shall mean an individual or Legal Entity 25 + exercising permissions granted by this License. 26 + 27 + "Source" form shall mean the preferred form for making modifications, 28 + including but not limited to software source code, documentation 29 + source, and configuration files. 30 + 31 + "Object" form shall mean any form resulting from mechanical 32 + transformation or translation of a Source form, including but 33 + not limited to compiled object code, generated documentation, 34 + and conversions to other media types. 35 + 36 + "Work" shall mean the work of authorship, whether in Source or 37 + Object form, made available under the License, as indicated by a 38 + copyright notice that is included in or attached to the work 39 + (an example is provided in the Appendix below). 40 + 41 + "Derivative Works" shall mean any work, whether in Source or Object 42 + form, that is based on (or derived from) the Work and for which the 43 + editorial revisions, annotations, elaborations, or other modifications 44 + represent, as a whole, an original work of authorship. For the purposes 45 + of this License, Derivative Works shall not include works that remain 46 + separable from, or merely link (or bind by name) to the interfaces of, 47 + the Work and Derivative Works thereof. 48 + 49 + "Contribution" shall mean any work of authorship, including 50 + the original version of the Work and any modifications or additions 51 + to that Work or Derivative Works thereof, that is intentionally 52 + submitted to Licensor for inclusion in the Work by the copyright owner 53 + or by an individual or Legal Entity authorized to submit on behalf of 54 + the copyright owner. For the purposes of this definition, "submitted" 55 + means any form of electronic, verbal, or written communication sent 56 + to the Licensor or its representatives, including but not limited to 57 + communication on electronic mailing lists, source code control systems, 58 + and issue tracking systems that are managed by, or on behalf of, the 59 + Licensor for the purpose of discussing and improving the Work, but 60 + excluding communication that is conspicuously marked or otherwise 61 + designated in writing by the copyright owner as "Not a Contribution." 62 + 63 + "Contributor" shall mean Licensor and any individual or Legal Entity 64 + on behalf of whom a Contribution has been received by Licensor and 65 + subsequently incorporated within the Work. 66 + 67 + 2. Grant of Copyright License. Subject to the terms and conditions of 68 + this License, each Contributor hereby grants to You a perpetual, 69 + worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 + copyright license to reproduce, prepare Derivative Works of, 71 + publicly display, publicly perform, sublicense, and distribute the 72 + Work and such Derivative Works in Source or Object form. 73 + 74 + 3. Grant of Patent License. Subject to the terms and conditions of 75 + this License, each Contributor hereby grants to You a perpetual, 76 + worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 + (except as stated in this section) patent license to make, have made, 78 + use, offer to sell, sell, import, and otherwise transfer the Work, 79 + where such license applies only to those patent claims licensable 80 + by such Contributor that are necessarily infringed by their 81 + Contribution(s) alone or by combination of their Contribution(s) 82 + with the Work to which such Contribution(s) was submitted. If You 83 + institute patent litigation against any entity (including a 84 + cross-claim or counterclaim in a lawsuit) alleging that the Work 85 + or a Contribution incorporated within the Work constitutes direct 86 + or contributory patent infringement, then any patent licenses 87 + granted to You under this License for that Work shall terminate 88 + as of the date such litigation is filed. 89 + 90 + 4. Redistribution. You may reproduce and distribute copies of the 91 + Work or Derivative Works thereof in any medium, with or without 92 + modifications, and in Source or Object form, provided that You 93 + meet the following conditions: 94 + 95 + (a) You must give any other recipients of the Work or 96 + Derivative Works a copy of this License; and 97 + 98 + (b) You must cause any modified files to carry prominent notices 99 + stating that You changed the files; and 100 + 101 + (c) You must retain, in the Source form of any Derivative Works 102 + that You distribute, all copyright, patent, trademark, and 103 + attribution notices from the Source form of the Work, 104 + excluding those notices that do not pertain to any part of 105 + the Derivative Works; and 106 + 107 + (d) If the Work includes a "NOTICE" text file as part of its 108 + distribution, then any Derivative Works that You distribute must 109 + include a readable copy of the attribution notices contained 110 + within such NOTICE file, excluding those notices that do not 111 + pertain to any part of the Derivative Works, in at least one 112 + of the following places: within a NOTICE text file distributed 113 + as part of the Derivative Works; within the Source form or 114 + documentation, if provided along with the Derivative Works; or, 115 + within a display generated by the Derivative Works, if and 116 + wherever such third-party notices normally appear. The contents 117 + of the NOTICE file are for informational purposes only and 118 + do not modify the License. You may add Your own attribution 119 + notices within Derivative Works that You distribute, alongside 120 + or as an addendum to the NOTICE text from the Work, provided 121 + that such additional attribution notices cannot be construed 122 + as modifying the License. 123 + 124 + You may add Your own copyright statement to Your modifications and 125 + may provide additional or different license terms and conditions 126 + for use, reproduction, or distribution of Your modifications, or 127 + for any such Derivative Works as a whole, provided Your use, 128 + reproduction, and distribution of the Work otherwise complies with 129 + the conditions stated in this License. 130 + 131 + 5. Submission of Contributions. Unless You explicitly state otherwise, 132 + any Contribution intentionally submitted for inclusion in the Work 133 + by You to the Licensor shall be under the terms and conditions of 134 + this License, without any additional terms or conditions. 135 + Notwithstanding the above, nothing herein shall supersede or modify 136 + the terms of any separate license agreement you may have executed 137 + with Licensor regarding such Contributions. 138 + 139 + 6. Trademarks. This License does not grant permission to use the trade 140 + names, trademarks, service marks, or product names of the Licensor, 141 + except as required for reasonable and customary use in describing the 142 + origin of the Work and reproducing the content of the NOTICE file. 143 + 144 + 7. Disclaimer of Warranty. Unless required by applicable law or 145 + agreed to in writing, Licensor provides the Work (and each 146 + Contributor provides its Contributions) on an "AS IS" BASIS, 147 + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 + implied, including, without limitation, any warranties or conditions 149 + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 + PARTICULAR PURPOSE. You are solely responsible for determining the 151 + appropriateness of using or redistributing the Work and assume any 152 + risks associated with Your exercise of permissions under this License. 153 + 154 + 8. Limitation of Liability. In no event and under no legal theory, 155 + whether in tort (including negligence), contract, or otherwise, 156 + unless required by applicable law (such as deliberate and grossly 157 + negligent acts) or agreed to in writing, shall any Contributor be 158 + liable to You for damages, including any direct, indirect, special, 159 + incidental, or consequential damages of any character arising as a 160 + result of this License or out of the use or inability to use the 161 + Work (including but not limited to damages for loss of goodwill, 162 + work stoppage, computer failure or malfunction, or any and all 163 + other commercial damages or losses), even if such Contributor 164 + has been advised of the possibility of such damages. 165 + 166 + 9. Accepting Warranty or Additional Liability. While redistributing 167 + the Work or Derivative Works thereof, You may choose to offer, 168 + and charge a fee for, acceptance of support, warranty, indemnity, 169 + or other liability obligations and/or rights consistent with this 170 + License. However, in accepting such obligations, You may act only 171 + on Your own behalf and on Your sole responsibility, not on behalf 172 + of any other Contributor, and only if You agree to indemnify, 173 + defend, and hold each Contributor harmless for any liability 174 + incurred by, or claims asserted against, such Contributor by reason 175 + of your accepting any such warranty or additional liability. 176 + 177 + END OF TERMS AND CONDITIONS 178 + 179 + APPENDIX: How to apply the Apache License to your work. 180 + 181 + To apply the Apache License to your work, attach the following 182 + boilerplate notice, with the fields enclosed by brackets "[]" 183 + replaced with your own identifying information. (Don't include 184 + the brackets!) The text should be enclosed in the appropriate 185 + comment syntax for the file format. We also recommend that a 186 + file or class name and description of purpose be included on the 187 + same "printed page" as the copyright notice for easier 188 + identification within third-party archives. 189 + 190 + Copyright [yyyy] [name of copyright owner] 191 + 192 + Licensed under the Apache License, Version 2.0 (the "License"); 193 + you may not use this file except in compliance with the License. 194 + You may obtain a copy of the License at 195 + 196 + http://www.apache.org/licenses/LICENSE-2.0 197 + 198 + Unless required by applicable law or agreed to in writing, software 199 + distributed under the License is distributed on an "AS IS" BASIS, 200 + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 + See the License for the specific language governing permissions and 202 + limitations under the License.
+5
LICENSE-MIT
··· 1 + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 2 + 3 + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 4 + 5 + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+95
README.md
··· 1 + # Mugi 2 + 3 + > Personal **Mu**lti-**Gi**t Remote Manager 4 + 5 + Mugi keeps your repositories in sync across multiple Git remotes (GitHub, Codeberg, SourceHut, etc.) 6 + with a single command. 7 + 8 + Mugi is written in [Go](https://go.dev) and uses [Bubble Tea](https://github.com/charmbracelet/bubbletea) 9 + for its terminal interface. 10 + 11 + ## Usage 12 + 13 + ```bash 14 + mugi pull # Pull all repos from all remotes 15 + mugi pull windmark # Pull Windmark from all remotes 16 + mugi push windmark gh cb # Push Windmark to GitHub and Codeberg 17 + mugi fetch gemrest/september # Fetch specific repository 18 + ``` 19 + 20 + ### Installation 21 + 22 + ```bash 23 + go install github.com/Fuwn/mugi/cmd/mugi@main 24 + ``` 25 + 26 + or 27 + 28 + ```bash 29 + git clone https://github.com/Fuwn/mugi.git 30 + cd mugi 31 + go build -o mugi ./cmd/mugi 32 + mv mugi ~/.local/bin/ # or anywhere in your PATH 33 + ``` 34 + 35 + ### Configuration 36 + 37 + Mugi uses a YAML config file at `~/.config/mugi/config.yaml`: 38 + 39 + ```yaml 40 + remotes: 41 + github: 42 + aliases: [gh] 43 + url: git@github.com:${user}/${repo}.git 44 + codeberg: 45 + aliases: [cb] 46 + url: git@codeberg.org:${user}/${repo}.git 47 + sourcehut: 48 + aliases: [sh] 49 + url: git@git.sr.ht:~fuwn/${repo} 50 + 51 + defaults: 52 + remotes: [github, codeberg, sourcehut] 53 + path_prefix: ~/Developer 54 + 55 + repos: 56 + gemrest/windmark: 57 + gemrest/september: 58 + ``` 59 + 60 + ### `--help` 61 + 62 + ``` 63 + Mugi - Personal Multi-Git Remote Manager 64 + 65 + Usage: 66 + mugi [flags] <command> [repo] [remotes...] 67 + 68 + Commands: 69 + pull Pull from remote(s) 70 + push Push to remote(s) 71 + fetch Fetch from remote(s) 72 + help Show this help 73 + version Show version 74 + 75 + Flags: 76 + -c, --config <path> Override config file path 77 + -V, --verbose Show detailed output 78 + 79 + Examples: 80 + mugi pull Pull all repositories from all remotes 81 + mugi pull windmark Pull Windmark from all remotes 82 + mugi pull windmark github Pull Windmark from GitHub only 83 + mugi push windmark gh cb Push Windmark to GitHub and Codeberg 84 + mugi fetch gemrest/september Fetch specific repository 85 + mugi -c ./test.yaml pull Use custom config 86 + ``` 87 + 88 + ## Licence 89 + 90 + Licensed under either of [Apache License, Version 2.0](LICENSE-APACHE) or 91 + [MIT license](LICENSE-MIT) at your option. 92 + 93 + Unless you explicitly state otherwise, any contribution intentionally submitted 94 + for inclusion in this crate by you, as defined in the Apache-2.0 license, shall 95 + be dual licensed as above, without any additional terms or conditions.
assets/example_output.png

This is a binary file and will not be displayed.

+50
cmd/mugi/main.go
··· 1 + package main 2 + 3 + import ( 4 + "fmt" 5 + "os" 6 + 7 + "github.com/ebisu/mugi/internal/cli" 8 + "github.com/ebisu/mugi/internal/config" 9 + "github.com/ebisu/mugi/internal/ui" 10 + ) 11 + 12 + const version = "0.1.0" 13 + 14 + func main() { 15 + if err := run(); err != nil { 16 + fmt.Fprintln(os.Stderr, err) 17 + os.Exit(1) 18 + } 19 + } 20 + 21 + func run() error { 22 + cmd, err := cli.Parse(os.Args[1:]) 23 + if err != nil { 24 + return err 25 + } 26 + 27 + if cmd.Help { 28 + fmt.Println(cli.Usage()) 29 + 30 + return nil 31 + } 32 + 33 + if cmd.Version { 34 + fmt.Printf("mugi %s\n", version) 35 + 36 + return nil 37 + } 38 + 39 + cfg, err := config.Load(cmd.ConfigPath) 40 + if err != nil { 41 + return fmt.Errorf("config: %w", err) 42 + } 43 + 44 + tasks := ui.BuildTasks(cfg, cmd.Repo, cmd.Remotes) 45 + if len(tasks) == 0 { 46 + return fmt.Errorf("no matching repositories or remotes found") 47 + } 48 + 49 + return ui.Run(cmd.Operation, tasks, cmd.Verbose) 50 + }
+30
config.example.yaml
··· 1 + remotes: 2 + github: 3 + aliases: [gh] 4 + url: git@github.com:${user}/${repo}.git 5 + codeberg: 6 + aliases: [cb] 7 + url: git@codeberg.org:${user}/${repo}.git 8 + sourcehut: 9 + aliases: [srht, sh] 10 + url: git@git.sr.ht:~${user}/${repo} 11 + 12 + defaults: 13 + remotes: [github, codeberg, sourcehut] 14 + path_prefix: ~/Developer 15 + 16 + repos: 17 + gemrest/windmark: {} 18 + 19 + gemrest/september: 20 + sourcehut: 21 + user: fuwn 22 + 23 + fuwn/dotfiles: 24 + path: ~/.dotfiles 25 + 26 + fuwn/private-project: 27 + remotes: [github] 28 + 29 + fuwn/fork: 30 + github: git@github.com:upstream/original.git
+27
go.mod
··· 1 + module github.com/ebisu/mugi 2 + 3 + go 1.24.3 4 + 5 + require ( 6 + github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect 7 + github.com/charmbracelet/bubbles v0.21.0 // indirect 8 + github.com/charmbracelet/bubbletea v1.3.10 // indirect 9 + github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc // indirect 10 + github.com/charmbracelet/lipgloss v1.1.0 // indirect 11 + github.com/charmbracelet/x/ansi v0.10.1 // indirect 12 + github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd // indirect 13 + github.com/charmbracelet/x/term v0.2.1 // indirect 14 + github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect 15 + github.com/lucasb-eyer/go-colorful v1.2.0 // indirect 16 + github.com/mattn/go-isatty v0.0.20 // indirect 17 + github.com/mattn/go-localereader v0.0.1 // indirect 18 + github.com/mattn/go-runewidth v0.0.16 // indirect 19 + github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect 20 + github.com/muesli/cancelreader v0.2.2 // indirect 21 + github.com/muesli/termenv v0.16.0 // indirect 22 + github.com/rivo/uniseg v0.4.7 // indirect 23 + github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect 24 + golang.org/x/sys v0.36.0 // indirect 25 + golang.org/x/text v0.3.8 // indirect 26 + gopkg.in/yaml.v3 v3.0.1 // indirect 27 + )
+46
go.sum
··· 1 + github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k= 2 + github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8= 3 + github.com/charmbracelet/bubbles v0.21.0 h1:9TdC97SdRVg/1aaXNVWfFH3nnLAwOXr8Fn6u6mfQdFs= 4 + github.com/charmbracelet/bubbles v0.21.0/go.mod h1:HF+v6QUR4HkEpz62dx7ym2xc71/KBHg+zKwJtMw+qtg= 5 + github.com/charmbracelet/bubbletea v1.3.10 h1:otUDHWMMzQSB0Pkc87rm691KZ3SWa4KUlvF9nRvCICw= 6 + github.com/charmbracelet/bubbletea v1.3.10/go.mod h1:ORQfo0fk8U+po9VaNvnV95UPWA1BitP1E0N6xJPlHr4= 7 + github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc h1:4pZI35227imm7yK2bGPcfpFEmuY1gc2YSTShr4iJBfs= 8 + github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc/go.mod h1:X4/0JoqgTIPSFcRA/P6INZzIuyqdFY5rm8tb41s9okk= 9 + github.com/charmbracelet/lipgloss v1.1.0 h1:vYXsiLHVkK7fp74RkV7b2kq9+zDLoEU4MZoFqR/noCY= 10 + github.com/charmbracelet/lipgloss v1.1.0/go.mod h1:/6Q8FR2o+kj8rz4Dq0zQc3vYf7X+B0binUUBwA0aL30= 11 + github.com/charmbracelet/x/ansi v0.10.1 h1:rL3Koar5XvX0pHGfovN03f5cxLbCF2YvLeyz7D2jVDQ= 12 + github.com/charmbracelet/x/ansi v0.10.1/go.mod h1:3RQDQ6lDnROptfpWuUVIUG64bD2g2BgntdxH0Ya5TeE= 13 + github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd h1:vy0GVL4jeHEwG5YOXDmi86oYw2yuYUGqz6a8sLwg0X8= 14 + github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd/go.mod h1:xe0nKWGd3eJgtqZRaN9RjMtK7xUYchjzPr7q6kcvCCs= 15 + github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ= 16 + github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg= 17 + github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4= 18 + github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM= 19 + github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= 20 + github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= 21 + github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= 22 + github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= 23 + github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4= 24 + github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88= 25 + github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc= 26 + github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= 27 + github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI= 28 + github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo= 29 + github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA= 30 + github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo= 31 + github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc= 32 + github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk= 33 + github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= 34 + github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= 35 + github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= 36 + github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no= 37 + github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM= 38 + golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 39 + golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 40 + golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k= 41 + golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= 42 + golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY= 43 + golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= 44 + gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 45 + gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= 46 + gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+176
internal/cli/cli.go
··· 1 + package cli 2 + 3 + import ( 4 + "errors" 5 + "fmt" 6 + "os" 7 + "strings" 8 + 9 + "github.com/ebisu/mugi/internal/remote" 10 + ) 11 + 12 + type Command struct { 13 + Operation remote.Operation 14 + Repo string 15 + Remotes []string 16 + ConfigPath string 17 + Verbose bool 18 + Help bool 19 + Version bool 20 + } 21 + 22 + var ErrUnknownCommand = errors.New("unknown command") 23 + 24 + func Parse(args []string) (Command, error) { 25 + cmd := Command{ 26 + Remotes: []string{remote.All}, 27 + } 28 + 29 + if len(args) == 0 { 30 + cmd.Help = true 31 + 32 + return cmd, nil 33 + } 34 + 35 + args, cmd.ConfigPath = extractConfigFlag(args) 36 + args, cmd.Verbose = extractVerboseFlag(args) 37 + 38 + for _, arg := range args { 39 + if arg == "-h" || arg == "--help" || arg == "help" { 40 + cmd.Help = true 41 + 42 + return cmd, nil 43 + } 44 + 45 + if arg == "-v" || arg == "--version" || arg == "version" { 46 + cmd.Version = true 47 + 48 + return cmd, nil 49 + } 50 + } 51 + 52 + if len(args) == 0 { 53 + cmd.Help = true 54 + 55 + return cmd, nil 56 + } 57 + 58 + switch args[0] { 59 + case "pull": 60 + cmd.Operation = remote.Pull 61 + case "push": 62 + cmd.Operation = remote.Push 63 + case "fetch": 64 + cmd.Operation = remote.Fetch 65 + default: 66 + return cmd, fmt.Errorf("%w: %s", ErrUnknownCommand, args[0]) 67 + } 68 + 69 + remaining := args[1:] 70 + 71 + if len(remaining) == 0 { 72 + cmd.Repo = remote.All 73 + 74 + return cmd, nil 75 + } 76 + 77 + cmd.Repo = remaining[0] 78 + remaining = remaining[1:] 79 + 80 + if len(remaining) > 0 { 81 + cmd.Remotes = remaining 82 + } 83 + 84 + return cmd, nil 85 + } 86 + 87 + func Usage() string { 88 + return `Mugi - Personal Multi-Git Remote Manager 89 + 90 + Usage: 91 + mugi [flags] <command> [repo] [remotes...] 92 + 93 + Commands: 94 + pull Pull from remote(s) 95 + push Push to remote(s) 96 + fetch Fetch from remote(s) 97 + help Show this help 98 + version Show version 99 + 100 + Flags: 101 + -c, --config <path> Override config file path 102 + -V, --verbose Show detailed output 103 + 104 + Examples: 105 + mugi pull Pull all repositories from all remotes 106 + mugi pull windmark Pull Windmark from all remotes 107 + mugi pull windmark github Pull Windmark from GitHub only 108 + mugi push windmark gh cb Push Windmark to GitHub and Codeberg 109 + mugi fetch gemrest/september Fetch specific repository 110 + mugi -c ./test.yaml pull Use custom config 111 + 112 + Config: ` + configPath() 113 + } 114 + 115 + func configPath() string { 116 + xdg := os.Getenv("XDG_CONFIG_HOME") 117 + 118 + if xdg == "" { 119 + home, _ := os.UserHomeDir() 120 + 121 + return home + "/.config/mugi/config.yaml" 122 + } 123 + 124 + return xdg + "/mugi/config.yaml" 125 + } 126 + 127 + func extractConfigFlag(args []string) ([]string, string) { 128 + var remaining []string 129 + var configPath string 130 + 131 + for i := 0; i < len(args); i++ { 132 + arg := args[i] 133 + 134 + if arg == "-c" || arg == "--config" { 135 + if i+1 < len(args) { 136 + configPath = args[i+1] 137 + i++ 138 + } 139 + 140 + continue 141 + } 142 + 143 + if v, ok := strings.CutPrefix(arg, "--config="); ok { 144 + configPath = v 145 + 146 + continue 147 + } 148 + 149 + if v, ok := strings.CutPrefix(arg, "-c"); ok && v != "" { 150 + configPath = v 151 + 152 + continue 153 + } 154 + 155 + remaining = append(remaining, arg) 156 + } 157 + 158 + return remaining, configPath 159 + } 160 + 161 + func extractVerboseFlag(args []string) ([]string, bool) { 162 + var remaining []string 163 + var verbose bool 164 + 165 + for _, arg := range args { 166 + if arg == "-V" || arg == "--verbose" { 167 + verbose = true 168 + 169 + continue 170 + } 171 + 172 + remaining = append(remaining, arg) 173 + } 174 + 175 + return remaining, verbose 176 + }
+250
internal/config/config.go
··· 1 + package config 2 + 3 + import ( 4 + "os" 5 + "path/filepath" 6 + "slices" 7 + "strings" 8 + 9 + "gopkg.in/yaml.v3" 10 + ) 11 + 12 + type RemoteDefinition struct { 13 + Aliases []string `yaml:"aliases"` 14 + URL string `yaml:"url"` 15 + } 16 + 17 + type Defaults struct { 18 + Remotes []string `yaml:"remotes"` 19 + PathPrefix string `yaml:"path_prefix"` 20 + } 21 + 22 + type RepoRemotes map[string]string 23 + 24 + type Repo struct { 25 + Path string 26 + Remotes RepoRemotes 27 + } 28 + 29 + type Config struct { 30 + Remotes map[string]RemoteDefinition 31 + Defaults Defaults 32 + Repos map[string]Repo 33 + } 34 + 35 + type rawConfig struct { 36 + Remotes map[string]RemoteDefinition `yaml:"remotes"` 37 + Defaults Defaults `yaml:"defaults"` 38 + Repos map[string]yaml.Node `yaml:"repos"` 39 + } 40 + 41 + type remoteOverride struct { 42 + User string `yaml:"user"` 43 + Repo string `yaml:"repo"` 44 + } 45 + 46 + func Load(override string) (Config, error) { 47 + path := override 48 + 49 + if path == "" { 50 + var err error 51 + 52 + path, err = Path() 53 + if err != nil { 54 + return Config{}, err 55 + } 56 + } 57 + 58 + data, err := os.ReadFile(path) 59 + if err != nil { 60 + return Config{}, err 61 + } 62 + 63 + var raw rawConfig 64 + 65 + if err := yaml.Unmarshal(data, &raw); err != nil { 66 + return Config{}, err 67 + } 68 + 69 + return expand(raw) 70 + } 71 + 72 + func expand(raw rawConfig) (Config, error) { 73 + cfg := Config{ 74 + Remotes: raw.Remotes, 75 + Defaults: raw.Defaults, 76 + Repos: make(map[string]Repo), 77 + } 78 + 79 + for name, node := range raw.Repos { 80 + repo, err := expandRepo(name, node, raw) 81 + if err != nil { 82 + return Config{}, err 83 + } 84 + 85 + cfg.Repos[name] = repo 86 + } 87 + 88 + return cfg, nil 89 + } 90 + 91 + func expandRepo(name string, node yaml.Node, raw rawConfig) (Repo, error) { 92 + user, repoName := splitRepoName(name) 93 + repo := Repo{ 94 + Remotes: make(RepoRemotes), 95 + } 96 + 97 + var parsed map[string]yaml.Node 98 + 99 + if err := node.Decode(&parsed); err != nil { 100 + parsed = make(map[string]yaml.Node) 101 + } 102 + 103 + if pathNode, ok := parsed["path"]; ok { 104 + var path string 105 + 106 + pathNode.Decode(&path) 107 + 108 + repo.Path = path 109 + } else if raw.Defaults.PathPrefix != "" { 110 + repo.Path = filepath.Join(raw.Defaults.PathPrefix, repoName) 111 + } 112 + 113 + remoteList := raw.Defaults.Remotes 114 + 115 + if remotesNode, ok := parsed["remotes"]; ok { 116 + var list []string 117 + 118 + if err := remotesNode.Decode(&list); err == nil { 119 + remoteList = list 120 + } else { 121 + var oldStyle map[string]string 122 + 123 + if err := remotesNode.Decode(&oldStyle); err == nil { 124 + repo.Remotes = oldStyle 125 + 126 + return repo, nil 127 + } 128 + } 129 + } 130 + 131 + for _, remoteName := range remoteList { 132 + remoteUser, remoteRepo := user, repoName 133 + 134 + if overrideNode, ok := parsed[remoteName]; ok { 135 + var override remoteOverride 136 + 137 + if err := overrideNode.Decode(&override); err == nil { 138 + if override.User != "" { 139 + remoteUser = override.User 140 + } 141 + 142 + if override.Repo != "" { 143 + remoteRepo = override.Repo 144 + } 145 + } else { 146 + var urlOverride string 147 + 148 + if err := overrideNode.Decode(&urlOverride); err == nil { 149 + repo.Remotes[remoteName] = urlOverride 150 + 151 + continue 152 + } 153 + } 154 + } 155 + 156 + if def, ok := raw.Remotes[remoteName]; ok && def.URL != "" { 157 + url := expandURL(def.URL, remoteUser, remoteRepo) 158 + 159 + repo.Remotes[remoteName] = url 160 + } 161 + } 162 + 163 + return repo, nil 164 + } 165 + 166 + func expandURL(template, user, repo string) string { 167 + url := strings.ReplaceAll(template, "${user}", user) 168 + url = strings.ReplaceAll(url, "${repo}", repo) 169 + 170 + return url 171 + } 172 + 173 + func splitRepoName(name string) (user, repo string) { 174 + parts := strings.SplitN(name, "/", 2) 175 + 176 + if len(parts) == 2 { 177 + return parts[0], parts[1] 178 + } 179 + 180 + return "", parts[0] 181 + } 182 + 183 + func Path() (string, error) { 184 + configDir := os.Getenv("XDG_CONFIG_HOME") 185 + 186 + if configDir == "" { 187 + home, err := os.UserHomeDir() 188 + if err != nil { 189 + return "", err 190 + } 191 + 192 + configDir = filepath.Join(home, ".config") 193 + } 194 + 195 + return filepath.Join(configDir, "mugi", "config.yaml"), nil 196 + } 197 + 198 + func (c Config) FindRepo(name string) (string, Repo, bool) { 199 + if repo, ok := c.Repos[name]; ok { 200 + return name, repo, true 201 + } 202 + 203 + var matches []string 204 + 205 + for fullName := range c.Repos { 206 + repoName := filepath.Base(fullName) 207 + 208 + if repoName == name { 209 + matches = append(matches, fullName) 210 + } 211 + } 212 + 213 + if len(matches) == 1 { 214 + return matches[0], c.Repos[matches[0]], true 215 + } 216 + 217 + return "", Repo{}, false 218 + } 219 + 220 + func (c Config) AllRepos() []string { 221 + repos := make([]string, 0, len(c.Repos)) 222 + 223 + for name := range c.Repos { 224 + repos = append(repos, name) 225 + } 226 + 227 + return repos 228 + } 229 + 230 + func (c Config) ResolveAlias(alias string) string { 231 + for name, def := range c.Remotes { 232 + if name == alias || slices.Contains(def.Aliases, alias) { 233 + return name 234 + } 235 + } 236 + 237 + return alias 238 + } 239 + 240 + func (r Repo) ExpandPath() string { 241 + path := r.Path 242 + 243 + if len(path) > 0 && path[0] == '~' { 244 + if home, err := os.UserHomeDir(); err == nil { 245 + path = filepath.Join(home, path[1:]) 246 + } 247 + } 248 + 249 + return path 250 + }
+214
internal/git/git.go
··· 1 + package git 2 + 3 + import ( 4 + "bytes" 5 + "context" 6 + "errors" 7 + "os" 8 + "os/exec" 9 + "strings" 10 + 11 + "github.com/ebisu/mugi/internal/remote" 12 + ) 13 + 14 + const sshEnv = "GIT_SSH_COMMAND=ssh -o StrictHostKeyChecking=accept-new" 15 + 16 + func gitEnv() []string { 17 + return append(os.Environ(), sshEnv) 18 + } 19 + 20 + type Result struct { 21 + Repo string 22 + Remote string 23 + Output string 24 + Error error 25 + ExitCode int 26 + } 27 + 28 + func (r *Result) setError(err error) { 29 + r.Error = err 30 + 31 + var exitErr *exec.ExitError 32 + 33 + if errors.As(err, &exitErr) { 34 + r.ExitCode = exitErr.ExitCode() 35 + } else { 36 + r.ExitCode = 1 37 + } 38 + 39 + if r.Output == "" { 40 + r.Output = err.Error() 41 + } 42 + } 43 + 44 + func Execute(ctx context.Context, op remote.Operation, repoPath, remoteName string) Result { 45 + result := Result{ 46 + Repo: repoPath, 47 + Remote: remoteName, 48 + } 49 + 50 + args := buildArgs(op, remoteName, repoPath) 51 + cmd := exec.CommandContext(ctx, "git", args...) 52 + cmd.Dir = repoPath 53 + cmd.Env = gitEnv() 54 + 55 + var stdout, stderr bytes.Buffer 56 + cmd.Stdout = &stdout 57 + cmd.Stderr = &stderr 58 + 59 + err := cmd.Run() 60 + result.Output = strings.TrimSpace(stdout.String() + stderr.String()) 61 + 62 + if err != nil { 63 + result.setError(err) 64 + } 65 + 66 + return result 67 + } 68 + 69 + func buildArgs(op remote.Operation, remoteName, repoPath string) []string { 70 + switch op { 71 + case remote.Pull: 72 + branch := currentBranch(repoPath) 73 + if branch == "" { 74 + branch = "HEAD" 75 + } 76 + return []string{"pull", remoteName, branch} 77 + case remote.Push: 78 + return []string{"push", remoteName} 79 + case remote.Fetch: 80 + return []string{"fetch", remoteName} 81 + default: 82 + return []string{} 83 + } 84 + } 85 + 86 + func currentBranch(repoPath string) string { 87 + cmd := exec.Command("git", "rev-parse", "--abbrev-ref", "HEAD") 88 + cmd.Dir = repoPath 89 + 90 + out, err := cmd.Output() 91 + if err != nil { 92 + return "" 93 + } 94 + 95 + return strings.TrimSpace(string(out)) 96 + } 97 + 98 + func IsRepo(path string) bool { 99 + cmd := exec.Command("git", "rev-parse", "--git-dir") 100 + cmd.Dir = path 101 + 102 + return cmd.Run() == nil 103 + } 104 + 105 + func Clone(ctx context.Context, url, path string) Result { 106 + result := Result{ 107 + Repo: path, 108 + Remote: "origin", 109 + } 110 + 111 + cmd := exec.CommandContext(ctx, "git", "clone", url, path) 112 + cmd.Env = gitEnv() 113 + 114 + var stdout, stderr bytes.Buffer 115 + cmd.Stdout = &stdout 116 + cmd.Stderr = &stderr 117 + 118 + err := cmd.Run() 119 + result.Output = strings.TrimSpace(stdout.String() + stderr.String()) 120 + 121 + if err != nil { 122 + result.setError(err) 123 + } 124 + 125 + return result 126 + } 127 + 128 + func AddRemote(ctx context.Context, repoPath, name, url string) Result { 129 + result := Result{ 130 + Repo: repoPath, 131 + Remote: name, 132 + } 133 + 134 + cmd := exec.CommandContext(ctx, "git", "remote", "add", name, url) 135 + cmd.Dir = repoPath 136 + 137 + var stdout, stderr bytes.Buffer 138 + cmd.Stdout = &stdout 139 + cmd.Stderr = &stderr 140 + 141 + err := cmd.Run() 142 + result.Output = strings.TrimSpace(stdout.String() + stderr.String()) 143 + 144 + if err != nil { 145 + result.setError(err) 146 + } 147 + 148 + return result 149 + } 150 + 151 + func RenameRemote(ctx context.Context, repoPath, oldName, newName string) Result { 152 + result := Result{ 153 + Repo: repoPath, 154 + Remote: newName, 155 + } 156 + 157 + cmd := exec.CommandContext(ctx, "git", "remote", "rename", oldName, newName) 158 + cmd.Dir = repoPath 159 + 160 + var stdout, stderr bytes.Buffer 161 + cmd.Stdout = &stdout 162 + cmd.Stderr = &stderr 163 + 164 + err := cmd.Run() 165 + result.Output = strings.TrimSpace(stdout.String() + stderr.String()) 166 + 167 + if err != nil { 168 + result.setError(err) 169 + } 170 + 171 + return result 172 + } 173 + 174 + func HasRemote(repoPath, name string) bool { 175 + cmd := exec.Command("git", "remote", "get-url", name) 176 + cmd.Dir = repoPath 177 + 178 + return cmd.Run() == nil 179 + } 180 + 181 + func SetRemoteURL(ctx context.Context, repoPath, name, url string) Result { 182 + result := Result{ 183 + Repo: repoPath, 184 + Remote: name, 185 + } 186 + 187 + cmd := exec.CommandContext(ctx, "git", "remote", "set-url", name, url) 188 + cmd.Dir = repoPath 189 + 190 + var stdout, stderr bytes.Buffer 191 + cmd.Stdout = &stdout 192 + cmd.Stderr = &stderr 193 + 194 + err := cmd.Run() 195 + result.Output = strings.TrimSpace(stdout.String() + stderr.String()) 196 + 197 + if err != nil { 198 + result.setError(err) 199 + } 200 + 201 + return result 202 + } 203 + 204 + func GetRemoteURL(repoPath, name string) string { 205 + cmd := exec.Command("git", "remote", "get-url", name) 206 + cmd.Dir = repoPath 207 + 208 + out, err := cmd.Output() 209 + if err != nil { 210 + return "" 211 + } 212 + 213 + return strings.TrimSpace(string(out)) 214 + }
+50
internal/remote/remote.go
··· 1 + package remote 2 + 3 + type Operation int 4 + 5 + const ( 6 + Pull Operation = iota 7 + Push 8 + Fetch 9 + ) 10 + 11 + func (o Operation) String() string { 12 + switch o { 13 + case Pull: 14 + return "pull" 15 + case Push: 16 + return "push" 17 + case Fetch: 18 + return "fetch" 19 + default: 20 + return "unknown" 21 + } 22 + } 23 + 24 + func (o Operation) Verb() string { 25 + switch o { 26 + case Pull: 27 + return "Pulling" 28 + case Push: 29 + return "Pushing" 30 + case Fetch: 31 + return "Fetching" 32 + default: 33 + return "Operating" 34 + } 35 + } 36 + 37 + func (o Operation) PastTense() string { 38 + switch o { 39 + case Pull: 40 + return "Pulled" 41 + case Push: 42 + return "Pushed" 43 + case Fetch: 44 + return "Fetched" 45 + default: 46 + return "Completed" 47 + } 48 + } 49 + 50 + const All = "all"
+626
internal/ui/ui.go
··· 1 + package ui 2 + 3 + import ( 4 + "context" 5 + "fmt" 6 + "os" 7 + "path/filepath" 8 + "strings" 9 + 10 + "github.com/charmbracelet/bubbles/spinner" 11 + tea "github.com/charmbracelet/bubbletea" 12 + "github.com/charmbracelet/lipgloss" 13 + "github.com/ebisu/mugi/internal/config" 14 + "github.com/ebisu/mugi/internal/git" 15 + "github.com/ebisu/mugi/internal/remote" 16 + ) 17 + 18 + type Task struct { 19 + RepoName string 20 + RemoteName string 21 + RemoteURL string 22 + RepoPath string 23 + Op remote.Operation 24 + } 25 + 26 + type taskState int 27 + 28 + const ( 29 + taskPending taskState = iota 30 + taskRunning 31 + taskSuccess 32 + taskFailed 33 + ) 34 + 35 + type taskResult struct { 36 + task Task 37 + result git.Result 38 + } 39 + 40 + type Model struct { 41 + tasks []Task 42 + states map[string]taskState 43 + results map[string]git.Result 44 + spinner spinner.Model 45 + operation remote.Operation 46 + verbose bool 47 + done bool 48 + } 49 + 50 + func NewModel(op remote.Operation, tasks []Task, verbose bool) Model { 51 + s := spinner.New() 52 + s.Spinner = spinner.Dot 53 + s.Style = lipgloss.NewStyle().Foreground(lipgloss.Color("205")) 54 + 55 + states := make(map[string]taskState) 56 + 57 + for _, t := range tasks { 58 + states[taskKey(t)] = taskPending 59 + } 60 + 61 + return Model{ 62 + tasks: tasks, 63 + states: states, 64 + results: make(map[string]git.Result), 65 + spinner: s, 66 + operation: op, 67 + verbose: verbose, 68 + } 69 + } 70 + 71 + func taskKey(t Task) string { 72 + return t.RepoName + ":" + t.RemoteName 73 + } 74 + 75 + func (m Model) Init() tea.Cmd { 76 + cmds := []tea.Cmd{m.spinner.Tick} 77 + 78 + for _, task := range m.tasks { 79 + cmds = append(cmds, m.runTask(task)) 80 + } 81 + 82 + return tea.Batch(cmds...) 83 + } 84 + 85 + func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { 86 + switch msg := msg.(type) { 87 + case tea.KeyMsg: 88 + switch msg.String() { 89 + case "q", "ctrl+c": 90 + return m, tea.Quit 91 + } 92 + 93 + case spinner.TickMsg: 94 + var cmd tea.Cmd 95 + m.spinner, cmd = m.spinner.Update(msg) 96 + 97 + return m, cmd 98 + 99 + case taskResult: 100 + key := taskKey(msg.task) 101 + if msg.result.Error != nil { 102 + m.states[key] = taskFailed 103 + } else { 104 + m.states[key] = taskSuccess 105 + } 106 + m.results[key] = msg.result 107 + 108 + if m.allDone() { 109 + m.done = true 110 + return m, tea.Quit 111 + } 112 + } 113 + 114 + return m, nil 115 + } 116 + 117 + func (m Model) View() string { 118 + var b strings.Builder 119 + 120 + title := lipgloss.NewStyle(). 121 + Bold(true). 122 + Foreground(lipgloss.Color("212")). 123 + Render(fmt.Sprintf("%s repositories", m.operation.Verb())) 124 + 125 + b.WriteString(title + "\n\n") 126 + 127 + successStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("42")) 128 + failStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("196")) 129 + dimStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("241")) 130 + 131 + for _, task := range m.tasks { 132 + key := taskKey(task) 133 + state := m.states[key] 134 + 135 + var status string 136 + switch state { 137 + case taskPending: 138 + status = dimStyle.Render("○") 139 + case taskRunning: 140 + status = m.spinner.View() 141 + case taskSuccess: 142 + status = successStyle.Render("✓") 143 + case taskFailed: 144 + status = failStyle.Render("✗") 145 + } 146 + 147 + repoName := filepath.Base(task.RepoName) 148 + line := fmt.Sprintf("%s %s → %s", status, repoName, task.RemoteName) 149 + 150 + if result, ok := m.results[key]; ok && result.Output != "" { 151 + if m.verbose { 152 + line += "\n" + indentOutput(result.Output, dimStyle) 153 + } else if state == taskFailed { 154 + line += dimStyle.Render(" " + firstLine(result.Output)) 155 + } 156 + } 157 + 158 + b.WriteString(line + "\n") 159 + } 160 + 161 + if m.done { 162 + b.WriteString("\n") 163 + success, failed := m.summary() 164 + if failed > 0 { 165 + b.WriteString(failStyle.Render(fmt.Sprintf("%d failed", failed))) 166 + b.WriteString(", ") 167 + } 168 + b.WriteString(successStyle.Render(fmt.Sprintf("%d succeeded", success))) 169 + b.WriteString("\n") 170 + } 171 + 172 + return b.String() 173 + } 174 + 175 + func (m *Model) runTask(task Task) tea.Cmd { 176 + return func() tea.Msg { 177 + op := task.Op 178 + 179 + if op == 0 { 180 + op = m.operation 181 + } 182 + 183 + result := git.Execute(context.Background(), op, task.RepoPath, task.RemoteName) 184 + 185 + return taskResult{task: task, result: result} 186 + } 187 + } 188 + 189 + func (m Model) allDone() bool { 190 + for _, state := range m.states { 191 + if state == taskPending || state == taskRunning { 192 + return false 193 + } 194 + } 195 + 196 + return true 197 + } 198 + 199 + func (m Model) summary() (success, failed int) { 200 + for _, state := range m.states { 201 + switch state { 202 + case taskSuccess: 203 + success++ 204 + case taskFailed: 205 + failed++ 206 + } 207 + } 208 + return 209 + } 210 + 211 + func firstLine(s string) string { 212 + if idx := strings.Index(s, "\n"); idx != -1 { 213 + return s[:idx] 214 + } 215 + 216 + return s 217 + } 218 + 219 + func indentOutput(s string, style lipgloss.Style) string { 220 + lines := strings.Split(s, "\n") 221 + 222 + for i, line := range lines { 223 + lines[i] = " " + style.Render(line) 224 + } 225 + 226 + return strings.Join(lines, "\n") 227 + } 228 + 229 + func Run(op remote.Operation, tasks []Task, verbose bool) error { 230 + if op == remote.Pull { 231 + inits := NeedsInit(tasks) 232 + if len(inits) > 0 { 233 + if err := runInit(inits, verbose); err != nil { 234 + return err 235 + } 236 + } 237 + } 238 + 239 + syncRemotes(tasks) 240 + 241 + if op == remote.Pull { 242 + tasks = adjustPullTasks(tasks) 243 + } 244 + 245 + model := NewModel(op, tasks, verbose) 246 + p := tea.NewProgram(model) 247 + 248 + _, err := p.Run() 249 + 250 + return err 251 + } 252 + 253 + func syncRemotes(tasks []Task) { 254 + ctx := context.Background() 255 + seen := make(map[string]bool) 256 + 257 + for _, task := range tasks { 258 + key := task.RepoPath + ":" + task.RemoteName 259 + 260 + if seen[key] { 261 + continue 262 + } 263 + 264 + seen[key] = true 265 + 266 + if !git.IsRepo(task.RepoPath) { 267 + continue 268 + } 269 + 270 + currentURL := git.GetRemoteURL(task.RepoPath, task.RemoteName) 271 + 272 + if currentURL == "" { 273 + git.AddRemote(ctx, task.RepoPath, task.RemoteName, task.RemoteURL) 274 + } else if currentURL != task.RemoteURL { 275 + git.SetRemoteURL(ctx, task.RepoPath, task.RemoteName, task.RemoteURL) 276 + } 277 + } 278 + } 279 + 280 + func adjustPullTasks(tasks []Task) []Task { 281 + firstPerRepo := make(map[string]bool) 282 + result := make([]Task, len(tasks)) 283 + 284 + for i, task := range tasks { 285 + result[i] = task 286 + 287 + if firstPerRepo[task.RepoPath] { 288 + result[i].Op = remote.Fetch 289 + } else { 290 + result[i].Op = remote.Pull 291 + firstPerRepo[task.RepoPath] = true 292 + } 293 + } 294 + 295 + return result 296 + } 297 + 298 + func runInit(inits []RepoInit, verbose bool) error { 299 + model := NewInitModel(inits, verbose) 300 + p := tea.NewProgram(model) 301 + 302 + m, err := p.Run() 303 + if err != nil { 304 + return err 305 + } 306 + 307 + if initModel, ok := m.(InitModel); ok { 308 + for _, state := range initModel.states { 309 + if state == taskFailed { 310 + return fmt.Errorf("repository initialisation failed") 311 + } 312 + } 313 + } 314 + 315 + return nil 316 + } 317 + 318 + func BuildTasks(cfg config.Config, repoName string, remoteNames []string) []Task { 319 + var tasks []Task 320 + 321 + repos := resolveRepos(cfg, repoName) 322 + 323 + for _, fullName := range repos { 324 + repo := cfg.Repos[fullName] 325 + remotes := resolveRemotes(cfg, repo, remoteNames) 326 + 327 + for _, remoteName := range remotes { 328 + if url, ok := repo.Remotes[remoteName]; ok { 329 + tasks = append(tasks, Task{ 330 + RepoName: fullName, 331 + RemoteName: remoteName, 332 + RemoteURL: url, 333 + RepoPath: repo.ExpandPath(), 334 + }) 335 + } 336 + } 337 + } 338 + 339 + return tasks 340 + } 341 + 342 + type RepoInit struct { 343 + Name string 344 + Path string 345 + Remotes map[string]string 346 + } 347 + 348 + type InitResult struct { 349 + Repo string 350 + Output string 351 + Error error 352 + Success bool 353 + } 354 + 355 + type initTaskResult struct { 356 + init RepoInit 357 + result InitResult 358 + } 359 + 360 + type InitModel struct { 361 + inits []RepoInit 362 + states map[string]taskState 363 + results map[string]InitResult 364 + spinner spinner.Model 365 + verbose bool 366 + done bool 367 + } 368 + 369 + func NewInitModel(inits []RepoInit, verbose bool) InitModel { 370 + s := spinner.New() 371 + s.Spinner = spinner.Dot 372 + s.Style = lipgloss.NewStyle().Foreground(lipgloss.Color("205")) 373 + 374 + states := make(map[string]taskState) 375 + 376 + for _, init := range inits { 377 + states[init.Path] = taskPending 378 + } 379 + 380 + return InitModel{ 381 + inits: inits, 382 + states: states, 383 + results: make(map[string]InitResult), 384 + spinner: s, 385 + verbose: verbose, 386 + } 387 + } 388 + 389 + func (m InitModel) Init() tea.Cmd { 390 + cmds := []tea.Cmd{m.spinner.Tick} 391 + 392 + for _, init := range m.inits { 393 + cmds = append(cmds, m.runInit(init)) 394 + } 395 + 396 + return tea.Batch(cmds...) 397 + } 398 + 399 + func (m InitModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { 400 + switch msg := msg.(type) { 401 + case tea.KeyMsg: 402 + switch msg.String() { 403 + case "q", "ctrl+c": 404 + return m, tea.Quit 405 + } 406 + 407 + case spinner.TickMsg: 408 + var cmd tea.Cmd 409 + m.spinner, cmd = m.spinner.Update(msg) 410 + 411 + return m, cmd 412 + 413 + case initTaskResult: 414 + if msg.result.Success { 415 + m.states[msg.init.Path] = taskSuccess 416 + } else { 417 + m.states[msg.init.Path] = taskFailed 418 + } 419 + m.results[msg.init.Path] = msg.result 420 + 421 + if m.allDone() { 422 + m.done = true 423 + return m, tea.Quit 424 + } 425 + } 426 + 427 + return m, nil 428 + } 429 + 430 + func (m InitModel) View() string { 431 + var b strings.Builder 432 + 433 + title := lipgloss.NewStyle(). 434 + Bold(true). 435 + Foreground(lipgloss.Color("212")). 436 + Render("Initialising repositories") 437 + 438 + b.WriteString(title + "\n\n") 439 + 440 + successStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("42")) 441 + failStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("196")) 442 + dimStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("241")) 443 + 444 + for _, init := range m.inits { 445 + state := m.states[init.Path] 446 + 447 + var status string 448 + switch state { 449 + case taskPending: 450 + status = dimStyle.Render("○") 451 + case taskRunning: 452 + status = m.spinner.View() 453 + case taskSuccess: 454 + status = successStyle.Render("✓") 455 + case taskFailed: 456 + status = failStyle.Render("✗") 457 + } 458 + 459 + repoName := filepath.Base(init.Name) 460 + line := fmt.Sprintf("%s %s", status, repoName) 461 + 462 + if result, ok := m.results[init.Path]; ok && result.Output != "" { 463 + if m.verbose || !result.Success { 464 + line += "\n" + indentOutput(result.Output, dimStyle) 465 + } 466 + } 467 + 468 + b.WriteString(line + "\n") 469 + } 470 + 471 + if m.done { 472 + b.WriteString("\n") 473 + } 474 + 475 + return b.String() 476 + } 477 + 478 + func (m *InitModel) runInit(init RepoInit) tea.Cmd { 479 + return func() tea.Msg { 480 + result := InitRepo(context.Background(), init) 481 + 482 + return initTaskResult{init: init, result: result} 483 + } 484 + } 485 + 486 + func (m InitModel) allDone() bool { 487 + for _, state := range m.states { 488 + if state == taskPending || state == taskRunning { 489 + return false 490 + } 491 + } 492 + 493 + return true 494 + } 495 + 496 + func NeedsInit(tasks []Task) []RepoInit { 497 + seen := make(map[string]bool) 498 + 499 + var inits []RepoInit 500 + 501 + for _, task := range tasks { 502 + if seen[task.RepoPath] { 503 + continue 504 + } 505 + 506 + seen[task.RepoPath] = true 507 + 508 + if _, err := os.Stat(task.RepoPath); os.IsNotExist(err) { 509 + inits = append(inits, collectRepoInit(tasks, task.RepoPath, task.RepoName)) 510 + 511 + continue 512 + } 513 + 514 + if !git.IsRepo(task.RepoPath) { 515 + inits = append(inits, collectRepoInit(tasks, task.RepoPath, task.RepoName)) 516 + } 517 + } 518 + 519 + return inits 520 + } 521 + 522 + func collectRepoInit(tasks []Task, path, name string) RepoInit { 523 + remotes := make(map[string]string) 524 + 525 + for _, t := range tasks { 526 + if t.RepoPath == path { 527 + remotes[t.RemoteName] = t.RemoteURL 528 + } 529 + } 530 + 531 + return RepoInit{Name: name, Path: path, Remotes: remotes} 532 + } 533 + 534 + func InitRepo(ctx context.Context, init RepoInit) InitResult { 535 + result := InitResult{Repo: init.Name} 536 + 537 + var firstRemote, firstURL string 538 + 539 + for name, url := range init.Remotes { 540 + firstRemote = name 541 + firstURL = url 542 + 543 + break 544 + } 545 + 546 + if err := os.MkdirAll(filepath.Dir(init.Path), 0o755); err != nil { 547 + result.Error = err 548 + result.Output = err.Error() 549 + 550 + return result 551 + } 552 + 553 + cloneResult := git.Clone(ctx, firstURL, init.Path) 554 + 555 + if cloneResult.Error != nil { 556 + result.Error = cloneResult.Error 557 + result.Output = cloneResult.Output 558 + 559 + return result 560 + } 561 + 562 + outputs := []string{fmt.Sprintf("Cloned from %s", firstRemote)} 563 + 564 + renameResult := git.RenameRemote(ctx, init.Path, "origin", firstRemote) 565 + 566 + if renameResult.Error != nil { 567 + result.Error = renameResult.Error 568 + result.Output = renameResult.Output 569 + 570 + return result 571 + } 572 + 573 + for name, url := range init.Remotes { 574 + if name == firstRemote { 575 + continue 576 + } 577 + 578 + addResult := git.AddRemote(ctx, init.Path, name, url) 579 + 580 + if addResult.Error != nil { 581 + result.Error = addResult.Error 582 + result.Output = addResult.Output 583 + 584 + return result 585 + } 586 + 587 + outputs = append(outputs, fmt.Sprintf("Added remote %s", name)) 588 + } 589 + 590 + result.Success = true 591 + result.Output = strings.Join(outputs, "\n") 592 + 593 + return result 594 + } 595 + 596 + func resolveRepos(cfg config.Config, name string) []string { 597 + if name == remote.All { 598 + return cfg.AllRepos() 599 + } 600 + 601 + if fullName, _, ok := cfg.FindRepo(name); ok { 602 + return []string{fullName} 603 + } 604 + 605 + return nil 606 + } 607 + 608 + func resolveRemotes(cfg config.Config, repo config.Repo, names []string) []string { 609 + if len(names) == 1 && names[0] == remote.All { 610 + remotes := make([]string, 0, len(repo.Remotes)) 611 + 612 + for name := range repo.Remotes { 613 + remotes = append(remotes, name) 614 + } 615 + 616 + return remotes 617 + } 618 + 619 + resolved := make([]string, 0, len(names)) 620 + 621 + for _, name := range names { 622 + resolved = append(resolved, cfg.ResolveAlias(name)) 623 + } 624 + 625 + return resolved 626 + }
+14
justfile
··· 1 + name := "mugi" 2 + format_command := "~/go/bin/gofumpt -l -w ." 3 + 4 + default: 5 + just --list 6 + 7 + fmt: 8 + {{ format_command }} 9 + 10 + run *arguments="": 11 + go run ./cmd/{{ name }} {{ arguments }} 12 + 13 + build: 14 + go build -o {{ name }} ./cmd/{{ name }}