Closed hetdagli234 closed 1 month ago
@hetdagli234 Could you please adjust the function you made changes in to this :pencil::
#[throws]
fn update_gitignore(&self, ignored_path: &str) {
let gitignore_path = construct_path!(self.root, GIT_IGNORE);
if gitignore_path.exists() {
let file = File::open(&gitignore_path)?;
for line in io::BufReader::new(file).lines().map_while(Result::ok) {
if line == ignored_path {
// INFO do not add the ignored path again if it is already in the .gitignore file
println!("{SKIP} [{GIT_IGNORE}], already contains [{ignored_path}]");
return;
}
}
// Check if the file ends with a newline
let mut file = File::open(&gitignore_path)?;
let mut buf = [0; 1];
file.seek(io::SeekFrom::End(-1))?;
file.read_exact(&mut buf)?;
let file = OpenOptions::new().append(true).open(gitignore_path);
if let Ok(mut file) = file {
if buf[0] == b'\n' {
writeln!(file, "{}", ignored_path)?;
} else {
writeln!(file, "\n{}", ignored_path)?;
}
println!("{FINISH} [{GIT_IGNORE}] update with [{ignored_path}]");
}
} else {
println!("{SKIP} [{GIT_IGNORE}], not found")
}
}
This change provides consistent output for both cases when:
.gitignore
file ends with EOF.gitignore
file ends with EOL (and after follows EOF)With your proposed change there will be an empty line in 2., which we would like to avoid.
A small but important change to the
update_gitignore
function in theTestGenerator
struct.Modified the
writeln!
macro call in theupdate_gitignore
function to add the changes in a new line.