🍰 Personal Multi-Git Remote Manager
go git
0
fork

Configure Feed

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

feat: Add force push flag

Fuwn 58efa862 5ee6ca9b

+35 -8
+1 -1
cmd/mugi/main.go
··· 46 46 return fmt.Errorf("no matching repositories or remotes found") 47 47 } 48 48 49 - return ui.Run(cmd.Operation, tasks, cmd.Verbose) 49 + return ui.Run(cmd.Operation, tasks, cmd.Verbose, cmd.Force) 50 50 }
+20
internal/cli/cli.go
··· 15 15 Remotes []string 16 16 ConfigPath string 17 17 Verbose bool 18 + Force bool 18 19 Help bool 19 20 Version bool 20 21 } ··· 34 35 35 36 args, cmd.ConfigPath = extractConfigFlag(args) 36 37 args, cmd.Verbose = extractVerboseFlag(args) 38 + args, cmd.Force = extractForceFlag(args) 37 39 38 40 for _, arg := range args { 39 41 if arg == "-h" || arg == "--help" || arg == "help" { ··· 100 102 Flags: 101 103 -c, --config <path> Override config file path 102 104 -V, --verbose Show detailed output 105 + -f, --force Force push (use with caution) 103 106 104 107 Examples: 105 108 mugi pull Pull all repositories from all remotes ··· 174 177 175 178 return remaining, verbose 176 179 } 180 + 181 + func extractForceFlag(args []string) ([]string, bool) { 182 + var remaining []string 183 + var force bool 184 + 185 + for _, arg := range args { 186 + if arg == "-f" || arg == "--force" { 187 + force = true 188 + 189 + continue 190 + } 191 + 192 + remaining = append(remaining, arg) 193 + } 194 + 195 + return remaining, force 196 + }
+8 -3
internal/git/git.go
··· 41 41 } 42 42 } 43 43 44 - func Execute(ctx context.Context, op remote.Operation, repoPath, remoteName string) Result { 44 + func Execute(ctx context.Context, op remote.Operation, repoPath, remoteName string, force bool) Result { 45 45 result := Result{ 46 46 Repo: repoPath, 47 47 Remote: remoteName, 48 48 } 49 49 50 - args := buildArgs(op, remoteName, repoPath) 50 + args := buildArgs(op, remoteName, repoPath, force) 51 51 cmd := exec.CommandContext(ctx, "git", args...) 52 52 cmd.Dir = repoPath 53 53 cmd.Env = gitEnv() ··· 66 66 return result 67 67 } 68 68 69 - func buildArgs(op remote.Operation, remoteName, repoPath string) []string { 69 + func buildArgs(op remote.Operation, remoteName, repoPath string, force bool) []string { 70 70 switch op { 71 71 case remote.Pull: 72 72 branch := currentBranch(repoPath) 73 73 if branch == "" { 74 74 branch = "HEAD" 75 75 } 76 + 76 77 return []string{"pull", remoteName, branch} 77 78 case remote.Push: 79 + if force { 80 + return []string{"push", "--force", remoteName} 81 + } 82 + 78 83 return []string{"push", remoteName} 79 84 case remote.Fetch: 80 85 return []string{"fetch", remoteName}
+6 -4
internal/ui/ui.go
··· 44 44 spinner spinner.Model 45 45 operation remote.Operation 46 46 verbose bool 47 + force bool 47 48 done bool 48 49 } 49 50 50 - func NewModel(op remote.Operation, tasks []Task, verbose bool) Model { 51 + func NewModel(op remote.Operation, tasks []Task, verbose, force bool) Model { 51 52 s := spinner.New() 52 53 s.Spinner = spinner.Dot 53 54 s.Style = lipgloss.NewStyle().Foreground(lipgloss.Color("205")) ··· 65 66 spinner: s, 66 67 operation: op, 67 68 verbose: verbose, 69 + force: force, 68 70 } 69 71 } 70 72 ··· 180 182 op = m.operation 181 183 } 182 184 183 - result := git.Execute(context.Background(), op, task.RepoPath, task.RemoteName) 185 + result := git.Execute(context.Background(), op, task.RepoPath, task.RemoteName, m.force) 184 186 185 187 return taskResult{task: task, result: result} 186 188 } ··· 226 228 return strings.Join(lines, "\n") 227 229 } 228 230 229 - func Run(op remote.Operation, tasks []Task, verbose bool) error { 231 + func Run(op remote.Operation, tasks []Task, verbose, force bool) error { 230 232 if op == remote.Pull { 231 233 inits := NeedsInit(tasks) 232 234 if len(inits) > 0 { ··· 242 244 tasks = adjustPullTasks(tasks) 243 245 } 244 246 245 - model := NewModel(op, tasks, verbose) 247 + model := NewModel(op, tasks, verbose, force) 246 248 p := tea.NewProgram(model) 247 249 248 250 _, err := p.Run()