Skip to content

Commit 903cb2d

Browse files
Merge pull request #10635 from gitbutlerapp/fix-project-finding-by-path
Fix finding nested projects by path
2 parents 007f6b8 + d86341d commit 903cb2d

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

crates/gitbutler-project/src/project.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,17 @@ impl Project {
120120
}
121121
/// Finds an existing project by its path. Errors out if not found.
122122
pub fn find_by_path(path: &Path) -> anyhow::Result<Project> {
123-
let projects = crate::list()?;
123+
let mut projects = crate::list()?;
124+
// Sort projects by longest pathname to shortest.
125+
// We need to do this because users might have one gitbutler project
126+
// nexted insided of another via a gitignored folder.
127+
// We want to match on the longest project path.
128+
projects.sort_by(|a, b| {
129+
b.path
130+
.to_string_lossy()
131+
.len()
132+
.cmp(&a.path.to_string_lossy().len())
133+
});
124134
let resolved_path = if path.is_relative() {
125135
path.canonicalize().context("Failed to canonicalize path")?
126136
} else {

0 commit comments

Comments
 (0)