Skip to content

fix: files can be forced added even if gitignored - #209

Merged
tisonkun merged 2 commits into
mainfrom
recheck-indexed-file
May 8, 2026
Merged

fix: files can be forced added even if gitignored#209
tisonkun merged 2 commits into
mainfrom
recheck-indexed-file

Conversation

@tisonkun

Copy link
Copy Markdown
Member

This refers to GitoxideLabs/gitoxide#2562.

Signed-off-by: tison <wander4096@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread fmt/src/selection.rs
Comment on lines 237 to +260
@@ -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;
}

Copilot AI Apr 30, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment thread fmt/src/git.rs
Comment on lines 243 to +266
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;
}

Copilot AI Apr 30, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Signed-off-by: tison <wander4096@gmail.com>
@tisonkun
tisonkun force-pushed the recheck-indexed-file branch from 71e22d8 to 87bf335 Compare May 8, 2026 00:44
@tisonkun
tisonkun merged commit 3c39666 into main May 8, 2026
17 checks passed
@tisonkun
tisonkun deleted the recheck-indexed-file branch May 8, 2026 00:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants