mirror of
https://github.com/extrawurst/gitui.git
synced 2024-11-23 03:32:30 +03:00
do not allow to ignore gitignore (fixes #825)
This commit is contained in:
parent
d6f43f063e
commit
29f71f50d4
@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## Unreleased
|
||||
|
||||
## Fixed
|
||||
- do not allow to ignore .gitignore files ([#825](https://github.com/extrawurst/gitui/issues/825))
|
||||
|
||||
## [0.16.2] - 2021-07-10
|
||||
|
||||
**undo last commit**
|
||||
|
@ -1,5 +1,5 @@
|
||||
use super::utils::{repo, work_dir};
|
||||
use crate::error::Result;
|
||||
use crate::error::{Error, Result};
|
||||
use scopetime::scope_time;
|
||||
use std::{
|
||||
fs::{File, OpenOptions},
|
||||
@ -18,6 +18,14 @@ pub fn add_to_ignore(
|
||||
|
||||
let repo = repo(repo_path)?;
|
||||
|
||||
if Path::new(path_to_ignore).file_name()
|
||||
== Path::new(GITIGNORE).file_name()
|
||||
{
|
||||
return Err(Error::Generic(String::from(
|
||||
"cannot ignore gitignore",
|
||||
)));
|
||||
}
|
||||
|
||||
let ignore_file = work_dir(&repo)?.join(GITIGNORE);
|
||||
|
||||
let optional_newline = ignore_file.exists()
|
||||
@ -52,8 +60,9 @@ fn file_ends_with_newline(file: &Path) -> Result<bool> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sync::tests::repo_init;
|
||||
use crate::sync::{tests::repo_init, utils::repo_write_file};
|
||||
use io::BufRead;
|
||||
use pretty_assertions::assert_eq;
|
||||
use std::{fs::File, io, path::Path};
|
||||
|
||||
#[test]
|
||||
@ -124,4 +133,20 @@ mod tests {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ignore_ignore() {
|
||||
let ignore_file_path = Path::new(".gitignore");
|
||||
let (_td, repo) = repo_init().unwrap();
|
||||
let root = repo.path().parent().unwrap();
|
||||
let repo_path = root.as_os_str().to_str().unwrap();
|
||||
|
||||
repo_write_file(&repo, ".gitignore", "#foo").unwrap();
|
||||
|
||||
let res = add_to_ignore(repo_path, ".gitignore");
|
||||
assert!(res.is_err());
|
||||
|
||||
let lines = read_lines(&root.join(ignore_file_path)).unwrap();
|
||||
assert_eq!(lines.count(), 1);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user