aboutsummaryrefslogtreecommitdiff
path: root/internal/git/git.go
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-01-26 05:51:25 +0000
committerFuwn <[email protected]>2026-01-26 05:51:25 +0000
commit58efa86227d91981f38b8b51d73b8716acd749d8 (patch)
treead986a1d85a81be6830bcb10392c7d6e5c8b773e /internal/git/git.go
parentdocs(README): Add example output screenshot (diff)
downloadmugi-58efa86227d91981f38b8b51d73b8716acd749d8.tar.xz
mugi-58efa86227d91981f38b8b51d73b8716acd749d8.zip
feat: Add force push flag
Diffstat (limited to 'internal/git/git.go')
-rw-r--r--internal/git/git.go11
1 files changed, 8 insertions, 3 deletions
diff --git a/internal/git/git.go b/internal/git/git.go
index 13e9cb2..2455977 100644
--- a/internal/git/git.go
+++ b/internal/git/git.go
@@ -41,13 +41,13 @@ func (r *Result) setError(err error) {
}
}
-func Execute(ctx context.Context, op remote.Operation, repoPath, remoteName string) Result {
+func Execute(ctx context.Context, op remote.Operation, repoPath, remoteName string, force bool) Result {
result := Result{
Repo: repoPath,
Remote: remoteName,
}
- args := buildArgs(op, remoteName, repoPath)
+ args := buildArgs(op, remoteName, repoPath, force)
cmd := exec.CommandContext(ctx, "git", args...)
cmd.Dir = repoPath
cmd.Env = gitEnv()
@@ -66,15 +66,20 @@ func Execute(ctx context.Context, op remote.Operation, repoPath, remoteName stri
return result
}
-func buildArgs(op remote.Operation, remoteName, repoPath string) []string {
+func buildArgs(op remote.Operation, remoteName, repoPath string, force bool) []string {
switch op {
case remote.Pull:
branch := currentBranch(repoPath)
if branch == "" {
branch = "HEAD"
}
+
return []string{"pull", remoteName, branch}
case remote.Push:
+ if force {
+ return []string{"push", "--force", remoteName}
+ }
+
return []string{"push", remoteName}
case remote.Fetch:
return []string{"fetch", remoteName}