Skip to content

Commit bf8a7a4

Browse files
committed
Improve Mode::change_to_match_fs documentation
1 parent 9cb76e9 commit bf8a7a4

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

gix-index/src/entry/mode.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,29 @@ impl Mode {
2020
}
2121

2222
/// Compares this mode to the file system version ([`std::fs::symlink_metadata`])
23-
/// and returns the change needed to update this mode to match the file if
23+
/// and returns the change needed to update this mode to match the file.
24+
///
25+
/// * if `has_symlinks` is false symlink entries will simply check if there
26+
/// is a normal file on disk
27+
/// * if `executable_bit` is false the executable bit will not be compared
28+
/// `Change::ExecutableBit` will never be generated
29+
///
30+
/// If there is a type change then we will use whatever information is
31+
/// present on the FS. Specifically if `has_symlinks` is false we will
32+
/// never generate `Change::TypeChange { new_mode: Mode::SYMLINK }`. and
33+
/// iff `executable_bit` is false we will never generate `Change::TypeChange
34+
/// { new_mode: Mode::FILE_EXECUTABLE }` (all files are assumed to be not
35+
/// executable). That measn that unstaging and staging files can be a lossy
36+
/// operation on such file systems.
37+
///
38+
/// If a directory replaced a normal file/symlink we assume that the
39+
/// directory is a submodule. Normal (non-submodule) direcotires would
40+
/// cause a file to be deleted from the index and should be handled before
41+
/// calling this function.
42+
///
43+
/// If the stat information belongs to something other than a normal file/
44+
/// directory (like a socket) we just return an identity change (non-files
45+
/// can not be committed to git)
2446
pub fn change_to_match_fs(
2547
self,
2648
stat: &std::fs::Metadata,
@@ -37,7 +59,7 @@ impl Mode {
3759
_ => return None,
3860
};
3961
let new_mode = if stat.is_dir() {
40-
Mode::DIR
62+
Mode::COMMIT
4163
} else if executable_bit && is_executable(stat) {
4264
Mode::FILE_EXECUTABLE
4365
} else {

0 commit comments

Comments
 (0)