Skip to content

Commit 08d28f5

Browse files
authored
feat: git init + GitHub remote setup on latest main (#420)
1 parent 267d0da commit 08d28f5

35 files changed

Lines changed: 2202 additions & 610 deletions

src-tauri/src/bin/codex_monitor_daemon.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,26 @@ impl DaemonState {
890890
git_ui_core::get_git_status_core(&self.workspaces, workspace_id).await
891891
}
892892

893+
async fn init_git_repo(
894+
&self,
895+
workspace_id: String,
896+
branch: String,
897+
force: bool,
898+
) -> Result<Value, String> {
899+
git_ui_core::init_git_repo_core(&self.workspaces, workspace_id, branch, force).await
900+
}
901+
902+
async fn create_github_repo(
903+
&self,
904+
workspace_id: String,
905+
repo: String,
906+
visibility: String,
907+
branch: Option<String>,
908+
) -> Result<Value, String> {
909+
git_ui_core::create_github_repo_core(&self.workspaces, workspace_id, repo, visibility, branch)
910+
.await
911+
}
912+
893913
async fn list_git_roots(
894914
&self,
895915
workspace_id: String,

src-tauri/src/bin/codex_monitor_daemon/rpc/git.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,38 @@ pub(super) async fn try_handle(
1313
};
1414
Some(state.get_git_status(workspace_id).await)
1515
}
16+
"init_git_repo" => {
17+
let workspace_id = match parse_string(params, "workspaceId") {
18+
Ok(value) => value,
19+
Err(err) => return Some(Err(err)),
20+
};
21+
let branch = match parse_string(params, "branch") {
22+
Ok(value) => value,
23+
Err(err) => return Some(Err(err)),
24+
};
25+
let force = parse_optional_bool(params, "force").unwrap_or(false);
26+
Some(state.init_git_repo(workspace_id, branch, force).await)
27+
}
28+
"create_github_repo" => {
29+
let workspace_id = match parse_string(params, "workspaceId") {
30+
Ok(value) => value,
31+
Err(err) => return Some(Err(err)),
32+
};
33+
let repo = match parse_string(params, "repo") {
34+
Ok(value) => value,
35+
Err(err) => return Some(Err(err)),
36+
};
37+
let visibility = match parse_string(params, "visibility") {
38+
Ok(value) => value,
39+
Err(err) => return Some(Err(err)),
40+
};
41+
let branch = parse_optional_string(params, "branch");
42+
Some(
43+
state
44+
.create_github_repo(workspace_id, repo, visibility, branch)
45+
.await,
46+
)
47+
}
1648
"list_git_roots" => {
1749
let workspace_id = match parse_string(params, "workspaceId") {
1850
Ok(value) => value,

src-tauri/src/git/mod.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,43 @@ pub(crate) async fn get_git_status(
8484
git_ui_core::get_git_status_core(&state.workspaces, workspace_id).await
8585
}
8686

87+
#[tauri::command]
88+
pub(crate) async fn init_git_repo(
89+
workspace_id: String,
90+
branch: String,
91+
force: Option<bool>,
92+
state: State<'_, AppState>,
93+
app: AppHandle,
94+
) -> Result<Value, String> {
95+
try_remote_value!(
96+
state,
97+
app,
98+
"init_git_repo",
99+
json!({ "workspaceId": &workspace_id, "branch": &branch, "force": force })
100+
);
101+
git_ui_core::init_git_repo_core(&state.workspaces, workspace_id, branch, force.unwrap_or(false))
102+
.await
103+
}
104+
105+
#[tauri::command]
106+
pub(crate) async fn create_github_repo(
107+
workspace_id: String,
108+
repo: String,
109+
visibility: String,
110+
branch: Option<String>,
111+
state: State<'_, AppState>,
112+
app: AppHandle,
113+
) -> Result<Value, String> {
114+
try_remote_value!(
115+
state,
116+
app,
117+
"create_github_repo",
118+
json!({ "workspaceId": &workspace_id, "repo": &repo, "visibility": &visibility, "branch": branch })
119+
);
120+
git_ui_core::create_github_repo_core(&state.workspaces, workspace_id, repo, visibility, branch)
121+
.await
122+
}
123+
87124
#[tauri::command]
88125
pub(crate) async fn stage_git_file(
89126
workspace_id: String,

src-tauri/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@ pub fn run() {
252252
codex::collaboration_mode_list,
253253
workspaces::connect_workspace,
254254
git::get_git_status,
255+
git::init_git_repo,
256+
git::create_github_repo,
255257
git::list_git_roots,
256258
git::get_git_diffs,
257259
git::get_git_log,

src-tauri/src/shared/git_ui_core.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,25 @@ pub(crate) async fn get_git_status_core(
4242
diff::get_git_status_inner(workspaces, workspace_id).await
4343
}
4444

45+
pub(crate) async fn init_git_repo_core(
46+
workspaces: &Mutex<HashMap<String, WorkspaceEntry>>,
47+
workspace_id: String,
48+
branch: String,
49+
force: bool,
50+
) -> Result<Value, String> {
51+
commands::init_git_repo_inner(workspaces, workspace_id, branch, force).await
52+
}
53+
54+
pub(crate) async fn create_github_repo_core(
55+
workspaces: &Mutex<HashMap<String, WorkspaceEntry>>,
56+
workspace_id: String,
57+
repo: String,
58+
visibility: String,
59+
branch: Option<String>,
60+
) -> Result<Value, String> {
61+
commands::create_github_repo_inner(workspaces, workspace_id, repo, visibility, branch).await
62+
}
63+
4564
pub(crate) async fn list_git_roots_core(
4665
workspaces: &Mutex<HashMap<String, WorkspaceEntry>>,
4766
workspace_id: String,

0 commit comments

Comments
 (0)