Skip to content

feat(git): auto-fetch on an interval so behind counts detect remote updates - #1310

Open
Michael-py001 wants to merge 1 commit into
baocode-dev:mainfrom
Michael-py001:feat/autofetch
Open

Michael-py001 wants to merge 1 commit into
baocode-dev:mainfrom
Michael-py001:feat/autofetch

Conversation

@Michael-py001

Copy link
Copy Markdown

关联

Fixes #1307

问题

远端有新提交时,BaoCode 的 behind 计数不更新,必须手动 Fetch 才知道有更新。根因是 behind 来自 git status --porcelain --branch 读的本地 remote-tracking ref,而代码库没有任何自动 fetch;状态刷新只由文件监听触发,不会 fetch。

改动

加入可配置的后台自动 fetch,沿用 VS Code git.autofetch 的思路:

  • git.autofetchInterval(settings.json):两次后台 fetch 的间隔秒数,正整数生效,缺省/0 为关闭。通过 followSettingsFiles 的静态回调读取,设置变更时重新布防计时器。
  • IdeGitRepository 为每个仓库(工作区、worktree、子模块、SSH 远端仓库)各自布防一个周期计时器;仅当当前分支有 upstream 时才 fetch,避免无跟踪分支对每个 remote 做无用的 git fetch --all。fetch 走已有的 fetch(),串行排队并强制刷新状态,因此 behind 计数随之更新。
  • dispose() 取消计时器并移除监听。
  • 新增两个单测:有 upstream 时按间隔 fetch 并刷新 behind;无 upstream 时不 fetch。

验证

  • dart analyze:3 个改动文件无问题。
  • flutter test --no-pub test/ide/git/git_repository_test.dart:10/10 通过(含 2 个新测试)。
  • flutter test --no-pub test/ide/git/:220 通过、3 失败;3 个失败均为未改动文件中的既有 Windows 平台问题(CRLF 行尾与 \ / / 路径分隔符),已单独复核:ask_ai_test.dart、git_blame_test.dart、git_service_test.dart。

说明

按 CONTRIBUTING.md,大改动应先在 issue 讨论再提 PR。本 PR 对应 #1307,如有不同设计倾向(例如改成窗口聚焦时 fetch、或默认开启),我按 maintainer 意见调整。

@github-actions github-actions Bot added the needs-issue Pull request without an accepted issue (PR gate) label Nov 25, 2026
@github-actions

Copy link
Copy Markdown

Thanks for the pull request! It doesn't follow CONTRIBUTING.md yet:

感谢提交!这个 PR 还不符合 CONTRIBUTING.md:

Without an accepted issue, it is closed after 7 days. Docs, translations and small fixes (a fix(…) title, at most 100 lines) need none; for other typos and obvious fixes, a maintainer labels the pull request trivial.

7 天内仍没有被认可的 Issue,会自动关闭。文档、翻译和小修复(标题为 fix(…)、不超过 100 行)不需要 Issue;其他错别字和明显的修复,维护者会给 PR 打上 trivial 标签。

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-issue Pull request without an accepted issue (PR gate)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] 拉取不识别远端更新:需手动 Fetch 才能看到落后提交

1 participant