Skip to content

Commit

Permalink
fix!: let the Change::Type carry the new type.
Browse files Browse the repository at this point in the history
Previously it would just discard that information.
  • Loading branch information
Byron committed Jan 15, 2025
1 parent 18b2a97 commit 77ecdb5
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 14 deletions.
9 changes: 8 additions & 1 deletion gix-status/src/index_as_worktree/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,14 @@ impl<'index> State<'_, 'index> {
.mode
.change_to_match_fs(&metadata, self.options.fs.symlink, self.options.fs.executable_bit)
{
Some(gix_index::entry::mode::Change::Type { .. }) => return Ok(Some(Change::Type.into())),
Some(gix_index::entry::mode::Change::Type { new_mode }) => {
return Ok(Some(
Change::Type {
worktree_mode: new_mode,
}
.into(),
))
}
Some(gix_index::entry::mode::Change::ExecutableBit) => true,
None => false,
};
Expand Down
6 changes: 5 additions & 1 deletion gix-status/src/index_as_worktree/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ pub enum Change<T = (), U = ()> {
///
/// A change to a non-file is marked as `modification` in Git, but that's related to the content which we can't evaluate.
/// Hence, a type-change is considered more appropriate.
Type,
Type {
/// The mode the worktree file would have if it was added to the index, and the mode that differs compared
/// to what's currently stored in the index.
worktree_mode: gix_index::entry::Mode,
},
/// This worktree file was modified in some form, like a permission change or content change or both,
/// as compared to this entry.
Modification {
Expand Down
2 changes: 1 addition & 1 deletion gix-status/src/index_as_worktree_with_renames/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ pub(super) mod function {
}
EntryStatus::Change(c) => match c {
Change::Removed => ChangeKind::Deletion,
Change::Type | Change::Modification { .. } | Change::SubmoduleModification(_) => {
Change::Type { .. } | Change::Modification { .. } | Change::SubmoduleModification(_) => {
ChangeKind::Modification
}
},
Expand Down
2 changes: 1 addition & 1 deletion gix-status/src/index_as_worktree_with_renames/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ impl<ContentChange, SubmoduleStatus> Entry<'_, ContentChange, SubmoduleStatus> {
..
} => match change {
Change::SubmoduleModification(_) | Change::Modification { .. } => Summary::Modified,
Change::Type => Summary::TypeChange,
Change::Type { .. } => Summary::TypeChange,
Change::Removed => Summary::Removed,
},
Entry::DirectoryContents { entry, .. } => {
Expand Down
64 changes: 56 additions & 8 deletions gix-status/tests/status/index_as_worktree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use bstr::BStr;
use filetime::{set_file_mtime, FileTime};
use gix_filter::eol::AutoCrlf;
use gix_index as index;
use gix_index::Entry;
use gix_index::{entry, Entry};
use gix_status::index_as_worktree::Context;
use gix_status::{
index_as_worktree,
Expand Down Expand Up @@ -231,7 +231,7 @@ fn deracify_status(status: EntryStatus) -> Option<EntryStatus> {
EntryStatus::Conflict(c) => EntryStatus::Conflict(c),
EntryStatus::Change(c) => match c {
Change::Removed => Change::Removed,
Change::Type => Change::Type,
Change::Type { worktree_mode } => Change::Type { worktree_mode },
Change::Modification {
executable_bit_changed,
content_change,
Expand Down Expand Up @@ -284,7 +284,17 @@ fn nonfile_untracked_are_not_visible() {
#[test]
#[cfg(unix)]
fn tracked_changed_to_non_file() {
nonfile_fixture("tracked-swapped", &[(BStr::new(b"file"), 0, Change::Type.into())]);
nonfile_fixture(
"tracked-swapped",
&[(
BStr::new(b"file"),
0,
Change::Type {
worktree_mode: entry::Mode::FILE,
}
.into(),
)],
);
}

#[test]
Expand Down Expand Up @@ -384,7 +394,17 @@ fn subomdule_deleted_dir() {
#[test]
fn subomdule_typechange() {
assert_eq!(
submodule_fixture("type-change", &[(BStr::new(b"m1"), 1, Change::Type.into())]),
submodule_fixture(
"type-change",
&[(
BStr::new(b"m1"),
1,
Change::Type {
worktree_mode: entry::Mode::FILE
}
.into()
)]
),
Outcome {
entries_to_process: 2,
entries_processed: 2,
Expand Down Expand Up @@ -596,7 +616,14 @@ fn refresh() {
}
.into(),
),
(BStr::new(b"empty"), 3, Change::Type.into()),
(
BStr::new(b"empty"),
3,
Change::Type {
worktree_mode: entry::Mode::FILE
}
.into()
),
(
BStr::new(b"executable"),
4,
Expand All @@ -620,7 +647,14 @@ fn refresh() {
}
.into(),
),
(BStr::new("empty"), 3, Change::Type.into()),
(
BStr::new("empty"),
3,
Change::Type {
worktree_mode: entry::Mode::FILE
}
.into()
),
(
BStr::new("executable"),
4,
Expand Down Expand Up @@ -669,7 +703,14 @@ fn modified() {
}
.into(),
),
(BStr::new(b"empty"), 3, Change::Type.into()),
(
BStr::new(b"empty"),
3,
Change::Type {
worktree_mode: entry::Mode::FILE,
}
.into(),
),
(
BStr::new(b"executable"),
4,
Expand All @@ -693,7 +734,14 @@ fn modified() {
}
.into(),
),
(BStr::new("empty"), 3, Change::Type.into()),
(
BStr::new("empty"),
3,
Change::Type {
worktree_mode: entry::Mode::FILE,
}
.into(),
),
(
BStr::new("executable"),
4,
Expand Down
8 changes: 6 additions & 2 deletions gix-status/tests/status/index_as_worktree_with_renames.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::fixture_path;
use bstr::ByteSlice;
use gix_diff::blob::pipeline::WorktreeRoots;
use gix_diff::rewrites::CopySource;
use gix_index::entry;
use gix_status::index_as_worktree::traits::FastEq;
use gix_status::index_as_worktree::{Change, EntryStatus};
use gix_status::index_as_worktree_with_renames;
Expand Down Expand Up @@ -123,7 +124,10 @@ fn tracked_changed_to_non_file() {
&[],
&[Expectation::Modification {
rela_path: "file",
status: Change::Type.into(),
status: Change::Type {
worktree_mode: entry::Mode::FILE,
}
.into(),
}],
None,
Some(Default::default()),
Expand Down Expand Up @@ -393,7 +397,7 @@ impl Expectation<'_> {
EntryStatus::Conflict(_) => Summary::Conflict,
EntryStatus::Change(change) => match change {
Change::Removed => Summary::Removed,
Change::Type => Summary::TypeChange,
Change::Type { .. } => Summary::TypeChange,
Change::Modification { .. } | Change::SubmoduleModification(_) => Summary::Modified,
},
EntryStatus::NeedsUpdate(_) => return None,
Expand Down

0 comments on commit 77ecdb5

Please sign in to comment.