# Avoid unnecessary git scan when the agent creates a checkpoint \(\#61271\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/50da8c40dcd596a91fe252537d8e4249f2fd3a50)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 50da8c40dcd596a91fe252537d8e4249f2fd3a50

Requested commit: 50da8c40dcd596a91fe252537d8e4249f2fd3a50

Commit: 50da8c40dcd596a91fe252537d8e4249f2fd3a50

Tree: f601d9e6478b2197c505e13db3efb1f63f5c18b5

Author: Cole Miller

Committer: GitHub

## Message

```
Avoid unnecessary git scan when the agent creates a checkpoint (#61271)

Agent checkpointing is implemented by staging selected files to a
temporary git index file, then creating a commit. To avoid checkpointing
commonly-excluded files even when the user doesn't have them in their
gitignore, we write a temporary override to .git/info/exclude while
running the staging. However, this causes us to do an unnecessary git
scan when a checkpoint happens, because in general we want to do this
when `.git/info/exclude` changes (the user might have edited it).

This PR fixes that by doing the staging in two steps:
- First, we stage any tracked files
- Then we get a list of untracked files to include and stage those
explicitly. The list is obtained by running `git ls-files` with a custom
ignore file in addition to the `--standard` ignores; we write that
custom ignore file to a path ending in `tmp` under .git, which means
that our worktree code will not start a git scan in response to its
events (the same way it already works for the temporary index file).
.git/info/exclude is never touched. Note that we already listed all
untracked files before this PR, in order to exclude the large ones.

Release Notes:
- Fixed Zed doing unnecessary work when the agent created a checkpoint.
```

## Parents

- [30730a305ae235f3be44643d5895e142048ef701](https://git.cafe/gitcafe/zed/commit/30730a305ae235f3be44643d5895e142048ef701?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/50da8c40dcd596a91fe252537d8e4249f2fd3a50?format=markdown)
