Skip to content

A read that rewrites the index

git
 1 min Spice disables Git’s optional refresh locks in its internal child processes so observation does not replace the index a hook is checking.
Published

Aug 16, 2026

A command asking Git about a worktree can refresh index metadata as a side effect. That can replace the index file even when the user has not changed the staged content.

This mattered when a Spice hook was validating the index generation while another internal probe inspected the repository. The observation itself could move the artifact being checked.

The shared subprocess boundary sets an environment policy for Python-managed Git children:

child_env[GIT_OPTIONAL_LOCKS_ENV] = "0"

It copies the child’s environment before setting the value. It does not modify the parent process’s environment or the user’s shell configuration. The command’s executable basename identifies the Git children to which the policy applies.

This disables optional locking work such as an opportunistic index refresh. It does not remove the mandatory locks needed by actual Git mutations. The scope is every internal Git child passing through this boundary, not a list of commands guessed to be read-only.

The distinction is useful whenever observation and mutation run concurrently. “This command does not change my files” is weaker than “this command cannot change the identity of an artifact another process is validating.” The index is maintained state even when the visible question is only about status.