git-sync-web 自动提交 2026-09-08 17:51:15
This commit is contained in:
@@ -14,13 +14,22 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// gitRun 在指定仓库目录执行 git 命令,返回合并后的输出。
|
// 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) {
|
func gitRun(repoPath string, timeout time.Duration, args ...string) (string, error) {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
full := append([]string{"-C", repoPath}, args...)
|
full := append([]string{"-C", repoPath}, args...)
|
||||||
cmd := exec.CommandContext(ctx, "git", full...)
|
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
|
var buf bytes.Buffer
|
||||||
cmd.Stdout = &buf
|
cmd.Stdout = &buf
|
||||||
cmd.Stderr = &buf
|
cmd.Stderr = &buf
|
||||||
|
|||||||
@@ -110,3 +110,8 @@ error: failed to push some refs to 'https://git.shiroko.one/tamakyi/github-auto-
|
|||||||
[2026-09-08 17:41:09] === 开始同步(启动检查,模式 push)===
|
[2026-09-08 17:41:09] === 开始同步(启动检查,模式 push)===
|
||||||
[2026-09-08 17:41:20] 本地与远程均无分支 main,已基于当前 HEAD(master)创建
|
[2026-09-08 17:41:20] 本地与远程均无分支 main,已基于当前 HEAD(master)创建
|
||||||
[2026-09-08 17:41:21] 检测到 2 个未提交改动,执行自动提交
|
[2026-09-08 17:41:21] 检测到 2 个未提交改动,执行自动提交
|
||||||
|
[2026-09-08 17:41:24] 自动提交完成,将随本轮同步推送
|
||||||
|
[2026-09-08 17:41:26] 远程分支 origin/main 不存在(远程仓库可能为空或分支名不一致),将推送本地 16 个提交以建立远程分支
|
||||||
|
[2026-09-08 17:51:06] 监控已启动
|
||||||
|
[2026-09-08 17:51:06] === 开始同步(启动检查,模式 push)===
|
||||||
|
[2026-09-08 17:51:15] 检测到 2 个未提交改动,执行自动提交
|
||||||
|
|||||||
Reference in New Issue
Block a user