From cc2d262b1d47748e92d436933509d7f5b78c2414 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Tue, 18 Aug 2026 12:39:26 +0800 Subject: fix: use porcelain diff for worktree cleanliness check Switch from `git diff-index --quiet` to `git diff --quiet` to refresh the index first, avoiding false change reports from stale stat records after compilation. --- mingling_ci/src/git.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'mingling_ci/src/git.rs') diff --git a/mingling_ci/src/git.rs b/mingling_ci/src/git.rs index 3d1404b..a6fab2c 100644 --- a/mingling_ci/src/git.rs +++ b/mingling_ci/src/git.rs @@ -42,12 +42,19 @@ where } } -/// Returns `true` when `git diff-index --quiet HEAD --` succeeds, i.e. the -/// working tree has no tracked changes. Git failures count as "not clean" so -/// the caller falls back to the marker-file path. +/// Returns `true` when the working tree has no tracked changes relative to +/// HEAD. Git failures count as "not clean" so the caller falls back to the +/// marker-file path. +/// +/// Uses the porcelain `git diff --quiet HEAD` rather than the plumbing +/// `git diff-index --quiet HEAD`: after a full compile the source files' +/// mtimes can be newer than the index stat records even though their content +/// is unchanged, and `diff-index` reports that stale stat as a change. The +/// porcelain diff refreshes the index first (via `diff.autoRefreshIndex`), +/// so it only reports real content differences. pub(crate) fn worktree_clean() -> bool { Command::new("git") - .args(["diff-index", "--quiet", "HEAD", "--"]) + .args(["diff", "--quiet", "HEAD", "--"]) .status() .is_ok_and(|status| status.success()) } -- cgit