Skip to content

Commit a0621e2

Browse files
committed
Move the repo initialization to the API
Move the method for initializing a repository by its path to the shared API module, so that the server can have this as well
1 parent 92478b7 commit a0621e2

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

crates/but-api/src/commands/projects.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::error::Error;
2+
use anyhow::Context;
23
use but_api_macros::api_cmd;
34
use gitbutler_project::{self as projects, ProjectId};
45
use std::path::PathBuf;
@@ -40,3 +41,14 @@ pub fn get_project(
4041
pub fn delete_project(project_id: ProjectId) -> Result<(), Error> {
4142
gitbutler_project::delete(project_id).map_err(Into::into)
4243
}
44+
45+
/// Initialize a Git repository at the given path
46+
#[api_cmd]
47+
#[tauri::command(async)]
48+
#[instrument(err(Debug))]
49+
pub fn init_git_repository(path: String) -> Result<(), Error> {
50+
let path: PathBuf = path.into();
51+
git2::Repository::init(&path)
52+
.with_context(|| format!("Failed to initialize Git repository at {}", path.display()))?;
53+
Ok(())
54+
}

crates/but-server/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ async fn handle_command(
233233
"add_project" => iprojects::add_project_cmd(request.params),
234234
"get_project" => iprojects::get_project_cmd(request.params),
235235
"delete_project" => iprojects::delete_project_cmd(request.params),
236+
"init_git_repository" => iprojects::init_git_repository_cmd(request.params),
236237
"list_projects" => projects::list_projects(&extra).await,
237238
"set_project_active" => {
238239
projects::set_project_active(&app, &extra, app_settings_sync, request.params).await

crates/gitbutler-tauri/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,10 @@ fn main() {
224224
but_api::projects::get_project,
225225
but_api::projects::update_project,
226226
but_api::projects::delete_project,
227+
but_api::projects::init_git_repository,
227228
projects::list_projects,
228229
projects::set_project_active,
229230
projects::open_project_in_window,
230-
projects::init_git_repository,
231231
repo::git_get_local_config,
232232
repo::git_set_local_config,
233233
repo::check_signing_settings,

crates/gitbutler-tauri/src/projects.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,3 @@ Ensure these aren't touched by GitButler or avoid using it in this repository.",
212212
}
213213
Ok(Some(msg))
214214
}
215-
216-
/// Initialize a Git repository at the given path
217-
#[tauri::command]
218-
#[instrument(err(Debug))]
219-
pub fn init_git_repository(path: String) -> Result<(), Error> {
220-
let path: PathBuf = path.into();
221-
git2::Repository::init(&path)
222-
.with_context(|| format!("Failed to initialize Git repository at {}", path.display()))?;
223-
Ok(())
224-
}

0 commit comments

Comments
 (0)