| 1 | /* Git configuration operations */ |
| 2 | |
| 3 | #ifndef GIT_OPS_H |
| 4 | #define GIT_OPS_H |
| 5 | |
| 6 | #include "gitswitch.h" |
| 7 | |
| 8 | /* Git configuration keys */ |
| 9 | #define GIT_CONFIG_USER_NAME "user.name" |
| 10 | #define GIT_CONFIG_USER_EMAIL "user.email" |
| 11 | #define GIT_CONFIG_USER_SIGNINGKEY "user.signingkey" |
| 12 | #define GIT_CONFIG_COMMIT_GPGSIGN "commit.gpgsign" |
| 13 | #define GIT_CONFIG_GPG_PROGRAM "gpg.program" |
| 14 | #define GIT_CONFIG_CORE_SSHCOMMAND "core.sshcommand" |
| 15 | |
| 16 | /* Current git configuration */ |
| 17 | typedef struct { |
| 18 | char name[MAX_NAME_LEN]; |
| 19 | char email[MAX_EMAIL_LEN]; |
| 20 | char signing_key[MAX_KEY_ID_LEN]; |
| 21 | bool gpg_signing_enabled; |
| 22 | git_scope_t scope; |
| 23 | bool valid; |
| 24 | } git_current_config_t; |
| 25 | |
| 26 | /* Function prototypes */ |
| 27 | |
| 28 | /** |
| 29 | * Initialize git operations |
| 30 | * - Verify git is available |
| 31 | * - Check git version compatibility |
| 32 | * - Validate current repository if in local scope |
| 33 | */ |
| 34 | int git_ops_init(void); |
| 35 | |
| 36 | /** |
| 37 | * Set git configuration for account |
| 38 | * - Sets user.name and user.email |
| 39 | * - Configures GPG signing if enabled |
| 40 | * - Sets SSH command if custom SSH configuration needed |
| 41 | * - Validates configuration was set correctly |
| 42 | */ |
| 43 | int git_set_config(const account_t *account, git_scope_t scope); |
| 44 | |
| 45 | /** |
| 46 | * Get current git configuration |
| 47 | * - Reads current user.name and user.email |
| 48 | * - Gets GPG signing configuration |
| 49 | * - Determines configuration scope |
| 50 | * - Returns structured configuration data |
| 51 | */ |
| 52 | int git_get_current_config(git_current_config_t *config); |
| 53 | |
| 54 | /** |
| 55 | * Clear git configuration (unset values) |
| 56 | */ |
| 57 | int git_clear_config(git_scope_t scope); |
| 58 | |
| 59 | /** |
| 60 | * Validate git repository |
| 61 | * - Checks if current directory is a git repository |
| 62 | * - Verifies repository is not bare |
| 63 | * - Checks repository health |
| 64 | */ |
| 65 | int git_validate_repository(void); |
| 66 | |
| 67 | /** |
| 68 | * Get git configuration scope (local, global, system) |
| 69 | * Returns the scope where the configuration is currently set |
| 70 | */ |
| 71 | git_scope_t git_get_config_scope(const char *config_key); |
| 72 | |
| 73 | /** |
| 74 | * Test git configuration |
| 75 | * - Creates a test commit (dry-run) |
| 76 | * - Validates signing if enabled |
| 77 | * - Verifies SSH access to remotes if applicable |
| 78 | */ |
| 79 | int git_test_config(const account_t *account, git_scope_t scope); |
| 80 | |
| 81 | /** |
| 82 | * Set single git configuration value |
| 83 | */ |
| 84 | int git_set_config_value(const char *key, const char *value, git_scope_t scope); |
| 85 | |
| 86 | /** |
| 87 | * Get single git configuration value |
| 88 | */ |
| 89 | int git_get_config_value(const char *key, char *value, size_t value_size, |
| 90 | git_scope_t scope); |
| 91 | |
| 92 | /** |
| 93 | * Unset git configuration value |
| 94 | */ |
| 95 | int git_unset_config_value(const char *key, git_scope_t scope); |
| 96 | |
| 97 | /** |
| 98 | * List all git configuration values for debugging |
| 99 | */ |
| 100 | int git_list_config(git_scope_t scope, char *output, size_t output_size); |
| 101 | |
| 102 | /** |
| 103 | * Configure SSH command for git operations |
| 104 | * - Sets core.sshCommand to use specific SSH key |
| 105 | * - Handles SSH agent socket specification |
| 106 | * - Configures SSH options for security |
| 107 | */ |
| 108 | int git_configure_ssh(const account_t *account, git_scope_t scope); |
| 109 | |
| 110 | /** |
| 111 | * Configure GPG for git operations |
| 112 | * - Sets user.signingkey |
| 113 | * - Enables/disables commit.gpgsign |
| 114 | * - Sets gpg.program if using custom GPG |
| 115 | */ |
| 116 | int git_configure_gpg(const account_t *account, git_scope_t scope); |
| 117 | |
| 118 | /** |
| 119 | * Check if current directory is a git repository |
| 120 | */ |
| 121 | bool git_is_repository(void); |
| 122 | |
| 123 | /** |
| 124 | * Get repository root directory |
| 125 | */ |
| 126 | int git_get_repo_root(char *path, size_t path_size); |
| 127 | |
| 128 | /** |
| 129 | * Convert scope enum to git config scope string |
| 130 | */ |
| 131 | const char *git_scope_to_flag(git_scope_t scope); |
| 132 | |
| 133 | #endif /* GIT_OPS_H */ |