From 423a6a8b425082e894a7945addb8e24ecb0a38ca Mon Sep 17 00:00:00 2001 From: zyj Date: Tue, 10 Mar 2026 09:26:18 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=9A=90=E8=97=8F=20Windows=20=E4=B8=8A?= =?UTF-8?q?=20git=20=E5=AD=90=E8=BF=9B=E7=A8=8B=E7=9A=84=E6=8E=A7=E5=88=B6?= =?UTF-8?q?=E5=8F=B0=E7=AA=97=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/git/client.go | 1 + internal/git/hidewindow_other.go | 8 ++++++++ internal/git/hidewindow_windows.go | 14 ++++++++++++++ 3 files changed, 23 insertions(+) create mode 100644 internal/git/hidewindow_other.go create mode 100644 internal/git/hidewindow_windows.go 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 + } +}