Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 updating gitignore by adding a new line #186 #187

Merged
merged 2 commits into from
Aug 16, 2024

Conversation

hetdagli234
Copy link

A small but important change to the update_gitignore function in the TestGenerator struct.

Modified the writeln! macro call in the update_gitignore function to add the changes in a new line.

@st22nestrel
Copy link

@hetdagli234 Could you please adjust the function you made changes in to this 📝:

#[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:

  1. last entry in .gitignore file ends with EOF
  2. last entry in .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.

@lukacan lukacan changed the base branch from master to develop August 15, 2024 20:01
Copy link

@st22nestrel st22nestrel left a comment

Choose a reason for hiding this comment

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

Change fixes the issue, I approve it.

@lukacan lukacan added the no changelog Lable to skip `check changelog` in CI pipeline. label Aug 16, 2024
@lukacan lukacan merged commit 41066bd into Ackee-Blockchain:develop Aug 16, 2024
8 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no changelog Lable to skip `check changelog` in CI pipeline.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants