fix: files can be forced added even if gitignored - #209
Conversation
Signed-off-by: tison <wander4096@gmail.com>
There was a problem hiding this comment.
Pull request overview
This PR addresses GitoxideLabs/gitoxide#2562 by ensuring files (and directories containing tracked entries) are still considered during traversal even if they are gitignored, as long as they exist in the Git index (e.g., force-added via git add -f).
Changes:
- Load the repository index and use it to decide whether gitignored paths should still be traversed/selected.
- For gitignored directories, continue traversal when the index indicates the path is a directory (i.e., contains tracked entries).
- For gitignored files, include them when an index entry exists for the path.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| fmt/src/selection.rs | Uses the Git index to avoid skipping force-added gitignored files/dirs during file selection. |
| fmt/src/git.rs | Uses the Git index to avoid skipping force-added gitignored paths when scanning dirty working tree directory contents for attribute updates. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -243,8 +251,13 @@ fn select_files_with_git( | |||
| } | |||
| } else if file_type.is_file() { | |||
| if platform.is_excluded() { | |||
| log::debug!(path:?, rela_path:?; "skip git ignored file"); | |||
| continue; | |||
| let rela = gix::path::try_into_bstr(rela_path) | |||
| .or_raise(|| Error::new("cannot convert path to git path"))?; | |||
|
|
|||
| if index.entry_by_path(rela.as_ref()).is_none() { | |||
| log::debug!(path:?, rela_path:?; "skip git ignored file"); | |||
| continue; | |||
| } | |||
There was a problem hiding this comment.
The gix::path::try_into_bstr(rela_path) conversion and the associated error message are duplicated in both the dir and file branches. Consider converting once (e.g., inside the platform.is_excluded() block) and reusing the result to reduce repetition and avoid doing the same conversion logic in two places.
| if file_type.is_dir() { | ||
| if platform.is_excluded() { | ||
| log::debug!(path:?, rela_path:?; "skip git ignored directory"); | ||
| it.skip_current_dir(); | ||
| continue; | ||
| let rela = | ||
| gix::path::try_into_bstr(rela_path).or_raise(|| { | ||
| Error::new("cannot convert path to git path") | ||
| })?; | ||
|
|
||
| if !index.path_is_directory(rela.as_ref()) { | ||
| log::debug!(path:?, rela_path:?; "skip git ignored directory"); | ||
| it.skip_current_dir(); | ||
| continue; | ||
| } | ||
| } | ||
| } else if file_type.is_file() { | ||
| if platform.is_excluded() { | ||
| log::debug!(path:?, rela_path:?; "skip git ignored file"); | ||
| continue; | ||
| let rela = | ||
| gix::path::try_into_bstr(rela_path).or_raise(|| { | ||
| Error::new("cannot convert path to git path") | ||
| })?; | ||
|
|
||
| if index.entry_by_path(rela.as_ref()).is_none() { | ||
| log::debug!(path:?, rela_path:?; "skip git ignored file"); | ||
| continue; | ||
| } |
There was a problem hiding this comment.
The conversion gix::path::try_into_bstr(rela_path) (and its error handling) is repeated for both directories and files. Consider factoring this into a small helper/closure or converting once inside the platform.is_excluded() block to reduce duplication and keep the ignore/index logic consistent across branches.
71e22d8 to
87bf335
Compare
This refers to GitoxideLabs/gitoxide#2562.