git-sync-web 自动提交 2026-09-08 17:51:15
This commit is contained in:
@@ -14,13 +14,22 @@ import (
|
||||
)
|
||||
|
||||
// gitRun 在指定仓库目录执行 git 命令,返回合并后的输出。
|
||||
// GIT_TERMINAL_PROMPT=0 避免认证弹窗卡死后台进程。
|
||||
// 非交互环境:GIT_TERMINAL_PROMPT=0 只能挡住终端提示,挡不住 Windows 凭据管理器(GCM)弹窗,
|
||||
// 因此额外禁用 GCM 交互、askpass 和 ssh 交互,避免后台同步被凭据弹窗永久卡死。
|
||||
// WaitDelay 保证超时 Kill 后即使 git 的子进程仍占用管道,Wait() 也能强制返回(Windows 上
|
||||
// CommandContext 只杀主进程,不杀 git-remote-https / 凭据 helper 等子进程)。
|
||||
func gitRun(repoPath string, timeout time.Duration, args ...string) (string, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||
defer cancel()
|
||||
full := append([]string{"-C", repoPath}, args...)
|
||||
cmd := exec.CommandContext(ctx, "git", full...)
|
||||
cmd.Env = append(os.Environ(), "GIT_TERMINAL_PROMPT=0")
|
||||
cmd.Env = append(os.Environ(),
|
||||
"GIT_TERMINAL_PROMPT=0",
|
||||
"GIT_ASKPASS=echo",
|
||||
"GCM_INTERACTIVE=never",
|
||||
"GIT_SSH_COMMAND=ssh -oBatchMode=yes -oStrictHostKeyChecking=accept-new",
|
||||
)
|
||||
cmd.WaitDelay = 10 * time.Second
|
||||
var buf bytes.Buffer
|
||||
cmd.Stdout = &buf
|
||||
cmd.Stderr = &buf
|
||||
|
||||
Reference in New Issue
Block a user