nsuite / refreshGitIndex
Function: refreshGitIndex()
refreshGitIndex(
options?):RefreshGitIndexResult
Defined in: UtilsGit.ts:65
Refreshes the Git index stat cache and reports the remaining real differences.
Formatters such as Prettier or oxfmt rewrite files in write mode, which updates the file inode/ctime even when the content is unchanged. Git's stat cache then becomes stale and git status falsely reports those files as modified. Running git update-index --refresh re-checks the stat information: files with identical content have their flags cleared automatically, while files with real content changes are kept and reported by git status --short.
Note: git update-index --refresh exits with a non-zero status when real differences exist; that exit code is intentionally ignored because the subsequent git status --short reports the details.
Parameters
options?
Options for the refresh operation.
Returns
An object describing whether real differences remain and the raw short status output.
Examples
import { refreshGitIndex } from "nsuite";
// After running formatters in write mode
const { hasRealChanges, status } = refreshGitIndex();
if (hasRealChanges) {
console.log("Remaining real changes:");
console.log(status);
} else {
console.log("Working tree content matches the index, no real changes.");
}import { refreshGitIndex } from "nsuite";
// Target a specific repository directory
const result = refreshGitIndex({ cwd: "/path/to/repo" });