feat: implement default Git identity management and local identity check

This commit is contained in:
Bohdan Triapitsyn
2026-01-14 22:34:17 +02:00
parent e0cc212823
commit e0279e59b0
18 changed files with 310 additions and 25 deletions
+1 -1
View File
@@ -2977,7 +2977,7 @@ dependencies = [
[[package]]
name = "openchamber-desktop"
version = "1.4.8"
version = "1.4.9"
dependencies = [
"anyhow",
"axum",
@@ -2029,6 +2029,27 @@ pub async fn get_current_git_identity(
})
}
#[tauri::command]
pub async fn has_local_identity(
directory: String,
state: State<'_, DesktopRuntime>,
) -> Result<bool, String> {
let root = validate_git_path(&directory, state.settings())
.await
.map_err(|e| e.to_string())?;
let user_name = run_git(&["config", "--local", "--get", "user.name"], &root)
.await
.ok()
.filter(|s| !s.is_empty());
let user_email = run_git(&["config", "--local", "--get", "user.email"], &root)
.await
.ok()
.filter(|s| !s.is_empty());
Ok(user_name.is_some() || user_email.is_some())
}
#[tauri::command]
pub async fn get_global_git_identity() -> Result<GitIdentitySummary, String> {
let user_name = tokio::process::Command::new("git")
@@ -257,6 +257,14 @@ fn sanitize_settings_update(payload: &Value) -> Value {
result_obj.insert("defaultAgent".to_string(), json!(trimmed));
}
}
if let Some(Value::String(s)) = obj.get("defaultGitIdentityId") {
let trimmed = s.trim();
if trimmed.is_empty() {
result_obj.insert("defaultGitIdentityId".to_string(), Value::Null);
} else {
result_obj.insert("defaultGitIdentityId".to_string(), json!(trimmed));
}
}
if let Some(Value::String(s)) = obj.get("commitMessageModel") {
let trimmed = s.trim();
if trimmed.is_empty() {
+2 -1
View File
@@ -33,7 +33,7 @@ use commands::git::{
add_git_worktree, check_is_git_repository, checkout_branch, create_branch, create_git_commit, rename_branch,
create_git_identity, delete_git_branch, delete_git_identity, delete_remote_branch,
discover_git_credentials, ensure_openchamber_ignored, generate_commit_message, get_commit_files,
get_current_git_identity, get_git_branches, get_git_diff, get_git_file_diff,
get_current_git_identity, has_local_identity, get_git_branches, get_git_diff, get_git_file_diff,
get_git_identities, get_git_log, get_git_status, get_global_git_identity, get_remote_url,
git_fetch, git_pull, git_push, is_linked_worktree, list_git_worktrees, remove_git_worktree,
revert_git_file, set_git_identity, update_git_identity,
@@ -871,6 +871,7 @@ fn main() {
update_git_identity,
delete_git_identity,
get_current_git_identity,
has_local_identity,
get_global_git_identity,
get_remote_url,
set_git_identity,
+8
View File
@@ -218,6 +218,14 @@ export const createDesktopGitAPI = (): GitAPI => ({
}
},
async hasLocalIdentity(directory: string): Promise<boolean> {
try {
return await safeGitInvoke<boolean>('has_local_identity', { directory });
} catch {
return false;
}
},
async setGitIdentity(directory: string, profileId: string): Promise<{ success: boolean; profile: GitIdentityProfile }> {
const profile = await safeGitInvoke<GitIdentityProfile>('set_git_identity', { directory, profileId });
return { success: true, profile };