mirror of
https://github.com/Dasemu/Grove.git
synced 2026-11-27 07:46:13 +00:00
fix(core): only existing files count as ignored conflicts
A whole ignored directory (e.g. .claude/) made every incoming file under it a 'would overwrite ignored local files' conflict, even when the file did not exist locally, so such branches never fast-forwarded. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
933ad65cf0
commit
7ed5675a00
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()))
|
||||
|
||||
Reference in new issue
Block a user