tenseleyflow/gitswitch / f814f4a

Browse files

fix: clear local git config when switching to global scope

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
f814f4a27f8f39f16c06fadd997280b6aac06744
Parents
2dad81e
Tree
fd9f0c5

1 changed file

StatusFile+-
M src/git_ops.c 8 1
src/git_ops.cmodified
@@ -73,8 +73,15 @@ int git_set_config(const account_t *account, git_scope_t scope) {
7373
         log_warning("Failed to backup git configuration");
7474
     }
7575
     
76
+    /* When setting global scope inside a repo, clear local config so stale
77
+     * values (e.g. signing key from a prior account) don't take precedence */
78
+    if (scope == GIT_SCOPE_GLOBAL && git_is_repository()) {
79
+        log_info("Clearing local git config to prevent stale overrides");
80
+        git_clear_config(GIT_SCOPE_LOCAL);
81
+    }
82
+
7683
     log_info("Setting git configuration for account: %s (%s scope)", account->name, scope_flag);
77
-    
84
+
7885
     /* Set user.name */
7986
     if (git_set_config_value(GIT_CONFIG_USER_NAME, account->name, scope) != 0) {
8087
         set_error(ERR_GIT_CONFIG_FAILED, "Failed to set user.name");