mirror of
https://github.com/Dasemu/Grove.git
synced 2026-11-26 07:16:11 +00:00
Merge pull request #14 from Dasemu/fix/ignored-conflicts-real-files
fix(core): only existing files count as ignored conflicts
This commit is contained in:
2 files changed
+63
No files matched your search
@@ -45,6 +45,7 @@ pub(crate) fn ignored_conflicts(g: &Git, target: &str) -> Result<Vec<String>, Gi
|
||||
"-z",
|
||||
])?;
|
||||
let ignored: Vec<&str> = ignored.split('\0').filter(|p| !p.is_empty()).collect();
|
||||
let top = std::path::PathBuf::from(g.run(&["rev-parse", "--show-toplevel"])?);
|
||||
Ok(added
|
||||
.into_iter()
|
||||
.filter(|a| {
|
||||
@@ -52,10 +53,26 @@ pub(crate) fn ignored_conflicts(g: &Git, target: &str) -> Result<Vec<String>, Gi
|
||||
.iter()
|
||||
.any(|i| a == i || (i.ends_with('/') && a.starts_with(i)))
|
||||
})
|
||||
// An ignored directory (`.claude/`) only covers the path: there is something to
|
||||
// overwrite only if the file, or a file where one of its parent directories goes, exists.
|
||||
.filter(|a| occupied(&top, a))
|
||||
.map(String::from)
|
||||
.collect())
|
||||
}
|
||||
|
||||
/// True when writing `rel` under `top` would replace something on disk: the path itself
|
||||
/// exists, or one of its parents exists as something other than a directory.
|
||||
fn occupied(top: &Path, rel: &str) -> bool {
|
||||
let path = top.join(rel);
|
||||
if path.symlink_metadata().is_ok() {
|
||||
return true;
|
||||
}
|
||||
path.ancestors()
|
||||
.skip(1)
|
||||
.take_while(|p| p.starts_with(top) && *p != top)
|
||||
.any(|p| p.symlink_metadata().is_ok_and(|m| !m.is_dir()))
|
||||
}
|
||||
|
||||
fn current_branch(g: &Git) -> Result<String, GitError> {
|
||||
g.probe(&["symbolic-ref", "--short", "-q", "HEAD"])?
|
||||
.ok_or_else(|| GitError::Other("detached HEAD".into()))
|
||||
|
||||
@@ -353,6 +353,52 @@ fn fast_forward_declines_instead_of_overwriting_local_ignored_file() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn files_new_in_an_ignored_directory_do_not_block_a_fast_forward() {
|
||||
let w = world();
|
||||
commit(&w.g1, "tool/settings.json", "{}\n");
|
||||
w.g1.run(&["push", "-q"]).unwrap();
|
||||
// The whole directory is ignored and exists locally, but not the incoming file.
|
||||
fs::write(w.d2.join(".git/info/exclude"), "tool/\n").unwrap();
|
||||
fs::create_dir_all(w.d2.join("tool/cache")).unwrap();
|
||||
fs::write(w.d2.join("tool/cache/x"), "local\n").unwrap();
|
||||
fetch(&w.d2, REMOTE).unwrap();
|
||||
assert!(
|
||||
matches!(
|
||||
receive(&w.d2, "m2", "t").unwrap(),
|
||||
Received::FastForwarded { .. }
|
||||
),
|
||||
"nothing local would be overwritten"
|
||||
);
|
||||
assert_eq!(
|
||||
fs::read_to_string(w.d2.join("tool/settings.json")).unwrap(),
|
||||
"{}\n"
|
||||
);
|
||||
assert_eq!(
|
||||
fs::read_to_string(w.d2.join("tool/cache/x")).unwrap(),
|
||||
"local\n"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_existing_file_in_an_ignored_directory_still_blocks_a_fast_forward() {
|
||||
let w = world();
|
||||
commit(&w.g1, "tool/settings.json", "theirs\n");
|
||||
w.g1.run(&["push", "-q"]).unwrap();
|
||||
fs::write(w.d2.join(".git/info/exclude"), "tool/\n").unwrap();
|
||||
fs::create_dir_all(w.d2.join("tool")).unwrap();
|
||||
fs::write(w.d2.join("tool/settings.json"), "mine\n").unwrap();
|
||||
fetch(&w.d2, REMOTE).unwrap();
|
||||
assert!(matches!(
|
||||
receive(&w.d2, "m2", "t").unwrap(),
|
||||
Received::Declined(_)
|
||||
));
|
||||
assert_eq!(
|
||||
fs::read_to_string(w.d2.join("tool/settings.json")).unwrap(),
|
||||
"mine\n"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn snapshot_apply_declines_instead_of_overwriting_local_ignored_file() {
|
||||
let w = world();
|
||||
|
||||
Reference in new issue
Block a user