# git: Fix panic in git panel when \`sort_by_path\` is \`true\` \(\#39678\) · gitcafe/zed

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

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

Visibility: public

Requested revision: 85985fe9608ea59907b673b53f563019da1917b9

Requested commit: 85985fe9608ea59907b673b53f563019da1917b9

Commit: 85985fe9608ea59907b673b53f563019da1917b9

Tree: b7323b6e547010fb695f0283f82e4c6747698778

Author: Bennet Bo Fenner

Committer: GitHub

## Message

````
git: Fix panic in git panel when `sort_by_path` is `true` (#39678)

Fixes ZED-1NX

This panic could occur when an `bulk_staging` was set to `Some(...)` and
`sort_by_path` was set to `true`.
When setting `sort_by_path: true`, we call `update_visible_entries(...)`
which then checks if `bulk_staging ` is `Some(...)` and calls
`entry_by_path`. That function accesses `entries`, which still consists
of both headers and entries. But the code
(`entry.status_entry().unwrap()`) assumes that there are no headers in
the entry list if `sort_by_path: true`.

```rust
if GitPanelSettings::get_global(cx).sort_by_path {
    return self
        .entries
        .binary_search_by(|entry| entry.status_entry().unwrap().repo_path.cmp(path)) //This unwrap() would panic
        .ok();
}
```

This has now been fixed by clearing all the entries when `sort_by_path`
changes, as this is the only case where our assumptions are invalid. I
also added a test which 1) actually tests the sort_by_path logic 2)
ensures that we do not re-introduce this panic in the future.


Release Notes:

- Fixed a panic that could occur when using `sort_by_path: true` in the
git panel
````

## Parents

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

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