Skip to content

Commit 4138982

Browse files
committed
fix!: let the Change::Type carry the new type.
Previously it would just discard that information.
1 parent 18b2a97 commit 4138982

File tree

6 files changed

+61
-12
lines changed

6 files changed

+61
-12
lines changed

gix-status/src/index_as_worktree/function.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,14 @@ impl<'index> State<'_, 'index> {
397397
.mode
398398
.change_to_match_fs(&metadata, self.options.fs.symlink, self.options.fs.executable_bit)
399399
{
400-
Some(gix_index::entry::mode::Change::Type { .. }) => return Ok(Some(Change::Type.into())),
400+
Some(gix_index::entry::mode::Change::Type { new_mode }) => {
401+
return Ok(Some(
402+
Change::Type {
403+
worktree_mode: new_mode,
404+
}
405+
.into(),
406+
))
407+
}
401408
Some(gix_index::entry::mode::Change::ExecutableBit) => true,
402409
None => false,
403410
};

gix-status/src/index_as_worktree/types.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,11 @@ pub enum Change<T = (), U = ()> {
111111
///
112112
/// A change to a non-file is marked as `modification` in Git, but that's related to the content which we can't evaluate.
113113
/// Hence, a type-change is considered more appropriate.
114-
Type,
114+
Type {
115+
/// The mode the worktree file would have if it was added to the index, and the mode that differs compared
116+
/// to what's currently stored in the index.
117+
worktree_mode: gix_index::entry::Mode,
118+
},
115119
/// This worktree file was modified in some form, like a permission change or content change or both,
116120
/// as compared to this entry.
117121
Modification {

gix-status/src/index_as_worktree_with_renames/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ pub(super) mod function {
455455
}
456456
EntryStatus::Change(c) => match c {
457457
Change::Removed => ChangeKind::Deletion,
458-
Change::Type | Change::Modification { .. } | Change::SubmoduleModification(_) => {
458+
Change::Type { .. } | Change::Modification { .. } | Change::SubmoduleModification(_) => {
459459
ChangeKind::Modification
460460
}
461461
},

gix-status/src/index_as_worktree_with_renames/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ impl<ContentChange, SubmoduleStatus> Entry<'_, ContentChange, SubmoduleStatus> {
230230
..
231231
} => match change {
232232
Change::SubmoduleModification(_) | Change::Modification { .. } => Summary::Modified,
233-
Change::Type => Summary::TypeChange,
233+
Change::Type { .. } => Summary::TypeChange,
234234
Change::Removed => Summary::Removed,
235235
},
236236
Entry::DirectoryContents { entry, .. } => {

gix-status/tests/status/index_as_worktree.rs

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use bstr::BStr;
77
use filetime::{set_file_mtime, FileTime};
88
use gix_filter::eol::AutoCrlf;
99
use gix_index as index;
10-
use gix_index::Entry;
10+
use gix_index::{entry, Entry};
1111
use gix_status::index_as_worktree::Context;
1212
use gix_status::{
1313
index_as_worktree,
@@ -231,7 +231,7 @@ fn deracify_status(status: EntryStatus) -> Option<EntryStatus> {
231231
EntryStatus::Conflict(c) => EntryStatus::Conflict(c),
232232
EntryStatus::Change(c) => match c {
233233
Change::Removed => Change::Removed,
234-
Change::Type => Change::Type,
234+
Change::Type { worktree_mode } => Change::Type { worktree_mode },
235235
Change::Modification {
236236
executable_bit_changed,
237237
content_change,
@@ -284,7 +284,17 @@ fn nonfile_untracked_are_not_visible() {
284284
#[test]
285285
#[cfg(unix)]
286286
fn tracked_changed_to_non_file() {
287-
nonfile_fixture("tracked-swapped", &[(BStr::new(b"file"), 0, Change::Type.into())]);
287+
nonfile_fixture(
288+
"tracked-swapped",
289+
&[(
290+
BStr::new(b"file"),
291+
0,
292+
Change::Type {
293+
worktree_mode: entry::Mode::FILE,
294+
}
295+
.into(),
296+
)],
297+
);
288298
}
289299

290300
#[test]
@@ -384,7 +394,17 @@ fn subomdule_deleted_dir() {
384394
#[test]
385395
fn subomdule_typechange() {
386396
assert_eq!(
387-
submodule_fixture("type-change", &[(BStr::new(b"m1"), 1, Change::Type.into())]),
397+
submodule_fixture(
398+
"type-change",
399+
&[(
400+
BStr::new(b"m1"),
401+
1,
402+
Change::Type {
403+
worktree_mode: entry::Mode::FILE
404+
}
405+
.into()
406+
)]
407+
),
388408
Outcome {
389409
entries_to_process: 2,
390410
entries_processed: 2,
@@ -596,7 +616,14 @@ fn refresh() {
596616
}
597617
.into(),
598618
),
599-
(BStr::new(b"empty"), 3, Change::Type.into()),
619+
(
620+
BStr::new(b"empty"),
621+
3,
622+
Change::Type {
623+
worktree_mode: entry::Mode::FILE
624+
}
625+
.into()
626+
),
600627
(
601628
BStr::new(b"executable"),
602629
4,
@@ -669,7 +696,14 @@ fn modified() {
669696
}
670697
.into(),
671698
),
672-
(BStr::new(b"empty"), 3, Change::Type.into()),
699+
(
700+
BStr::new(b"empty"),
701+
3,
702+
Change::Type {
703+
worktree_mode: entry::Mode::FILE,
704+
}
705+
.into(),
706+
),
673707
(
674708
BStr::new(b"executable"),
675709
4,

gix-status/tests/status/index_as_worktree_with_renames.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::fixture_path;
22
use bstr::ByteSlice;
33
use gix_diff::blob::pipeline::WorktreeRoots;
44
use gix_diff::rewrites::CopySource;
5+
use gix_index::entry;
56
use gix_status::index_as_worktree::traits::FastEq;
67
use gix_status::index_as_worktree::{Change, EntryStatus};
78
use gix_status::index_as_worktree_with_renames;
@@ -123,7 +124,10 @@ fn tracked_changed_to_non_file() {
123124
&[],
124125
&[Expectation::Modification {
125126
rela_path: "file",
126-
status: Change::Type.into(),
127+
status: Change::Type {
128+
worktree_mode: entry::Mode::FILE,
129+
}
130+
.into(),
127131
}],
128132
None,
129133
Some(Default::default()),
@@ -393,7 +397,7 @@ impl Expectation<'_> {
393397
EntryStatus::Conflict(_) => Summary::Conflict,
394398
EntryStatus::Change(change) => match change {
395399
Change::Removed => Summary::Removed,
396-
Change::Type => Summary::TypeChange,
400+
Change::Type { .. } => Summary::TypeChange,
397401
Change::Modification { .. } | Change::SubmoduleModification(_) => Summary::Modified,
398402
},
399403
EntryStatus::NeedsUpdate(_) => return None,

0 commit comments

Comments
 (0)