Skip to content

Commit f76d81d

Browse files
committed
feat(settings): add new git global settings
1 parent 2446f3d commit f76d81d

5 files changed

Lines changed: 712 additions & 74 deletions

File tree

‎src-tauri/src/commands/settings.rs‎

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,51 @@ pub fn get_global_file_mode() -> Result<Option<bool>, String> {
338338
}
339339
}
340340

341+
#[tauri::command]
342+
pub fn get_global_pull_rebase() -> Result<Option<String>, String> {
343+
git_config_global_get("pull.rebase")
344+
}
345+
346+
#[tauri::command]
347+
pub fn get_global_pull_ff() -> Result<Option<String>, String> {
348+
git_config_global_get("pull.ff")
349+
}
350+
351+
#[tauri::command]
352+
pub fn get_global_pull_autostash() -> Result<Option<String>, String> {
353+
git_config_global_get("pull.autostash")
354+
}
355+
356+
#[tauri::command]
357+
pub fn get_global_fetch_prune() -> Result<Option<String>, String> {
358+
git_config_global_get("fetch.prune")
359+
}
360+
361+
#[tauri::command]
362+
pub fn get_global_push_default() -> Result<Option<String>, String> {
363+
git_config_global_get("push.default")
364+
}
365+
366+
#[tauri::command]
367+
pub fn get_global_push_auto_setup_remote() -> Result<Option<String>, String> {
368+
git_config_global_get("push.autoSetupRemote")
369+
}
370+
371+
#[tauri::command]
372+
pub fn get_global_core_editor() -> Result<Option<String>, String> {
373+
git_config_global_get("core.editor")
374+
}
375+
376+
#[tauri::command]
377+
pub fn get_global_core_autocrlf() -> Result<Option<String>, String> {
378+
git_config_global_get("core.autocrlf")
379+
}
380+
381+
#[tauri::command]
382+
pub fn get_global_credential_helper() -> Result<Option<String>, String> {
383+
git_config_global_get("credential.helper")
384+
}
385+
341386
#[tauri::command]
342387
pub fn get_active_git_executable_path() -> String {
343388
crate::resolve_active_git_executable_path()
@@ -695,6 +740,139 @@ pub fn set_global_default_branch(default_branch: String) -> Result<OperationResu
695740
})
696741
}
697742

743+
fn validate_config_choice(value: &str, allowed: &[&str], label: &str) -> Result<String, String> {
744+
let value = value.trim();
745+
if allowed.contains(&value) {
746+
Ok(value.to_string())
747+
} else {
748+
Err(format!("Invalid {label}: {value}"))
749+
}
750+
}
751+
752+
fn set_optional_global_config(
753+
key: &str,
754+
value: &str,
755+
empty_message: &str,
756+
) -> Result<OperationResult, String> {
757+
let value = value.trim();
758+
let message = if value.is_empty() {
759+
git_config_global_unset(key)?;
760+
empty_message.to_string()
761+
} else {
762+
git_config_global_set(key, value)?;
763+
format!("Set git global {key}={value}")
764+
};
765+
766+
Ok(OperationResult {
767+
message,
768+
output: None,
769+
repo_path: None,
770+
backend_used: "git-cli".to_string(),
771+
})
772+
}
773+
774+
#[tauri::command]
775+
pub fn set_global_pull_rebase(pull_rebase: String) -> Result<OperationResult, String> {
776+
let value = validate_config_choice(
777+
&pull_rebase,
778+
&["", "false", "true", "merges", "interactive"],
779+
"pull.rebase",
780+
)?;
781+
set_optional_global_config(
782+
"pull.rebase",
783+
&value,
784+
"Cleared pull.rebase from global git config",
785+
)
786+
}
787+
788+
#[tauri::command]
789+
pub fn set_global_pull_ff(pull_ff: String) -> Result<OperationResult, String> {
790+
let value = validate_config_choice(&pull_ff, &["", "true", "false", "only"], "pull.ff")?;
791+
set_optional_global_config("pull.ff", &value, "Cleared pull.ff from global git config")
792+
}
793+
794+
#[tauri::command]
795+
pub fn set_global_pull_autostash(pull_autostash: String) -> Result<OperationResult, String> {
796+
let value = validate_config_choice(&pull_autostash, &["", "true", "false"], "pull.autostash")?;
797+
set_optional_global_config(
798+
"pull.autostash",
799+
&value,
800+
"Cleared pull.autostash from global git config",
801+
)
802+
}
803+
804+
#[tauri::command]
805+
pub fn set_global_fetch_prune(fetch_prune: String) -> Result<OperationResult, String> {
806+
let value = validate_config_choice(&fetch_prune, &["", "true", "false"], "fetch.prune")?;
807+
set_optional_global_config(
808+
"fetch.prune",
809+
&value,
810+
"Cleared fetch.prune from global git config",
811+
)
812+
}
813+
814+
#[tauri::command]
815+
pub fn set_global_push_default(push_default: String) -> Result<OperationResult, String> {
816+
let value = validate_config_choice(
817+
&push_default,
818+
&["", "nothing", "current", "upstream", "simple", "matching"],
819+
"push.default",
820+
)?;
821+
set_optional_global_config(
822+
"push.default",
823+
&value,
824+
"Cleared push.default from global git config",
825+
)
826+
}
827+
828+
#[tauri::command]
829+
pub fn set_global_push_auto_setup_remote(
830+
push_auto_setup_remote: String,
831+
) -> Result<OperationResult, String> {
832+
let value = validate_config_choice(
833+
&push_auto_setup_remote,
834+
&["", "true", "false"],
835+
"push.autoSetupRemote",
836+
)?;
837+
set_optional_global_config(
838+
"push.autoSetupRemote",
839+
&value,
840+
"Cleared push.autoSetupRemote from global git config",
841+
)
842+
}
843+
844+
#[tauri::command]
845+
pub fn set_global_core_editor(core_editor: String) -> Result<OperationResult, String> {
846+
set_optional_global_config(
847+
"core.editor",
848+
&core_editor,
849+
"Cleared core.editor from global git config",
850+
)
851+
}
852+
853+
#[tauri::command]
854+
pub fn set_global_core_autocrlf(core_autocrlf: String) -> Result<OperationResult, String> {
855+
let value = validate_config_choice(
856+
&core_autocrlf,
857+
&["", "false", "true", "input"],
858+
"core.autocrlf",
859+
)?;
860+
set_optional_global_config(
861+
"core.autocrlf",
862+
&value,
863+
"Cleared core.autocrlf from global git config",
864+
)
865+
}
866+
867+
#[tauri::command]
868+
pub fn set_global_credential_helper(credential_helper: String) -> Result<OperationResult, String> {
869+
set_optional_global_config(
870+
"credential.helper",
871+
&credential_helper,
872+
"Cleared credential.helper from global git config",
873+
)
874+
}
875+
698876
#[tauri::command]
699877
pub fn set_global_file_mode(file_mode: bool) -> Result<OperationResult, String> {
700878
let value = if file_mode { "true" } else { "false" };

‎src-tauri/src/lib.rs‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,12 +1038,30 @@ pub fn run() {
10381038
commands::settings::get_global_diff_tool_path,
10391039
commands::settings::get_global_default_branch,
10401040
commands::settings::get_global_file_mode,
1041+
commands::settings::get_global_pull_rebase,
1042+
commands::settings::get_global_pull_ff,
1043+
commands::settings::get_global_pull_autostash,
1044+
commands::settings::get_global_fetch_prune,
1045+
commands::settings::get_global_push_default,
1046+
commands::settings::get_global_push_auto_setup_remote,
1047+
commands::settings::get_global_core_editor,
1048+
commands::settings::get_global_core_autocrlf,
1049+
commands::settings::get_global_credential_helper,
10411050
commands::settings::get_active_git_executable_path,
10421051
commands::settings::get_active_git_version,
10431052
commands::settings::get_global_gpg_program,
10441053
commands::settings::get_global_gpg_program_path,
10451054
commands::settings::set_global_diff_tool,
10461055
commands::settings::set_global_default_branch,
1056+
commands::settings::set_global_pull_rebase,
1057+
commands::settings::set_global_pull_ff,
1058+
commands::settings::set_global_pull_autostash,
1059+
commands::settings::set_global_fetch_prune,
1060+
commands::settings::set_global_push_default,
1061+
commands::settings::set_global_push_auto_setup_remote,
1062+
commands::settings::set_global_core_editor,
1063+
commands::settings::set_global_core_autocrlf,
1064+
commands::settings::set_global_credential_helper,
10471065
commands::settings::set_global_file_mode,
10481066
commands::settings::set_git_executable_path,
10491067
commands::settings::set_global_gpg_program,

‎src/components/settings/SettingsWindow.css‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,49 @@
160160
font-weight: 500;
161161
}
162162

163+
.settings-window__label-content {
164+
display: inline-flex;
165+
align-items: center;
166+
gap: 6px;
167+
flex-wrap: wrap;
168+
}
169+
170+
.settings-window__git-config-key {
171+
display: inline-flex;
172+
align-items: center;
173+
min-height: 16px;
174+
padding: 1px 5px;
175+
border: 1px solid var(--border-subtle);
176+
border-radius: 4px;
177+
background: var(--bg-elevated);
178+
color: var(--text-muted);
179+
font-family: var(--font-mono);
180+
font-size: var(--font-size-xxs);
181+
font-weight: 500;
182+
}
183+
184+
.settings-window__config-group-title {
185+
margin-top: 4px;
186+
padding-top: 8px;
187+
border-top: 1px solid var(--border-subtle);
188+
color: var(--text-muted);
189+
font-size: var(--font-size-xxs);
190+
font-weight: 700;
191+
text-transform: uppercase;
192+
}
193+
194+
.settings-window__section-note + .settings-window__config-group-title {
195+
margin-top: 0;
196+
padding-top: 0;
197+
border-top: none;
198+
}
199+
200+
.settings-window__sub-section > .settings-window__config-group-title:first-child {
201+
margin-top: 0;
202+
padding-top: 0;
203+
border-top: none;
204+
}
205+
163206
.settings-window__input {
164207
flex: 1;
165208
min-width: 0;

0 commit comments

Comments
 (0)