diff --git a/internal/git/client.go b/internal/git/client.go index 0d8330a..d276a30 100644 --- a/internal/git/client.go +++ b/internal/git/client.go @@ -38,6 +38,7 @@ func (g *GitClient) Run(path string, args ...string) (string, error) { argsArr := append(header, args...) log.Println(argsArr) cmd := exec.CommandContext(ctx, "git", argsArr...) + hideWindow(cmd) var stdout, stderr bytes.Buffer cmd.Stdout = &stdout cmd.Stderr = &stderr diff --git a/internal/git/hidewindow_other.go b/internal/git/hidewindow_other.go new file mode 100644 index 0000000..0c5ef5f --- /dev/null +++ b/internal/git/hidewindow_other.go @@ -0,0 +1,8 @@ +//go:build !windows + +package git + +import "os/exec" + +// hideWindow 非 Windows 平台无需处理 +func hideWindow(cmd *exec.Cmd) {} diff --git a/internal/git/hidewindow_windows.go b/internal/git/hidewindow_windows.go new file mode 100644 index 0000000..71ffb2d --- /dev/null +++ b/internal/git/hidewindow_windows.go @@ -0,0 +1,14 @@ +package git + +import ( + "os/exec" + "syscall" +) + +// hideWindow 在 Windows 上隐藏子进程的控制台窗口 +func hideWindow(cmd *exec.Cmd) { + cmd.SysProcAttr = &syscall.SysProcAttr{ + HideWindow: true, + CreationFlags: 0x08000000, // CREATE_NO_WINDOW + } +}