Skip to content

Commit a37a829

Browse files
committed
Implement get_or_init_project
1 parent b58cc47 commit a37a829

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

crates/but/src/main.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,26 @@ async fn main() -> Result<()> {
219219
}
220220
}
221221

222+
fn get_or_init_project(
223+
current_dir: &std::path::Path,
224+
) -> anyhow::Result<gitbutler_project::Project> {
225+
let repo = gix::discover(current_dir)?;
226+
if let Some(path) = repo.workdir() {
227+
let project = match gitbutler_project::Project::find_by_path(path) {
228+
Ok(p) => Ok(p),
229+
Err(_e) => {
230+
crate::init::repo(path, false, false)?;
231+
gitbutler_project::Project::find_by_path(path)
232+
}
233+
}?;
234+
Ok(project)
235+
} else {
236+
let error_desc = "Bare repositories are not supported.";
237+
println!("{error_desc}");
238+
anyhow::bail!(error_desc);
239+
}
240+
}
241+
222242
pub(crate) fn props<E, T, R>(start: std::time::Instant, result: R) -> Props
223243
where
224244
R: std::ops::Deref<Target = Result<T, E>>,

0 commit comments

Comments
 (0)