MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / mcp_test_git

Function mcp_test_git

tests/test_mcp.c:303–379  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

301}
302
303static int mcp_test_git(const char *root, const char *const *arguments) {
304 char empty_config[CBM_SZ_4K];
305 int config_length =
306 snprintf(empty_config, sizeof(empty_config), "%s/.cbm-empty-gitconfig", root);
307 if (config_length <= 0 || (size_t)config_length >= sizeof(empty_config)) {
308 return -1;
309 }
310 FILE *config = cbm_fopen(empty_config, "wb");
311 if (!config) {
312 return -1;
313 }
314 if (fclose(config) != 0) {
315 return -1;
316 }
317
318 mcp_test_env_backup_t backups[] = {
319 {.name = "GIT_CONFIG_GLOBAL"}, {.name = "GIT_CONFIG_SYSTEM"},
320 {.name = "GIT_CONFIG_NOSYSTEM"}, {.name = "GIT_CONFIG_COUNT"},
321 {.name = "GIT_CONFIG_PARAMETERS"},
322 };
323 bool snapshot_ok = true;
324 for (size_t index = 0; index < sizeof(backups) / sizeof(backups[0]); index++) {
325 const char *value = getenv(backups[index].name);
326 backups[index].present = value != NULL;
327 backups[index].value = value ? strdup(value) : NULL;
328 snapshot_ok = snapshot_ok && (!value || backups[index].value);
329 }
330 if (!snapshot_ok) {
331 for (size_t index = 0; index < sizeof(backups) / sizeof(backups[0]); index++) {
332 free(backups[index].value);
333 }
334 return -1;
335 }
336 bool environment_ok = cbm_setenv("GIT_CONFIG_GLOBAL", empty_config, 1) == 0 &&
337 cbm_setenv("GIT_CONFIG_SYSTEM", empty_config, 1) == 0 &&
338 cbm_setenv("GIT_CONFIG_NOSYSTEM", "1", 1) == 0 &&
339 cbm_setenv("GIT_CONFIG_COUNT", "0", 1) == 0 &&
340 cbm_unsetenv("GIT_CONFIG_PARAMETERS") == 0;
341 if (!environment_ok) {
342 mcp_test_restore_env(backups, sizeof(backups) / sizeof(backups[0]));
343 return -1;
344 }
345
346 const char *git = "git";
347#ifdef _WIN32
348 char git_executable[CBM_SZ_4K];
349 const char *resolved = cbm_find_cli("git", cbm_get_home_dir());
350 int resolved_length =
351 resolved ? snprintf(git_executable, sizeof(git_executable), "%s", resolved) : -1;
352 if (resolved_length <= 0 || (size_t)resolved_length >= sizeof(git_executable)) {
353 mcp_test_restore_env(backups, sizeof(backups) / sizeof(backups[0]));
354 return -1;
355 }
356 git = git_executable;
357#endif
358 const char *argv[24] = {git, "-C", root};
359 size_t index = 3;
360 while (arguments && *arguments && index + 1 < sizeof(argv) / sizeof(argv[0])) {

Callers 2

test_mcp.cFile · 0.85
detect_default_base_repoFunction · 0.85

Calls 7

cbm_fopenFunction · 0.85
cbm_setenvFunction · 0.85
cbm_unsetenvFunction · 0.85
mcp_test_restore_envFunction · 0.85
cbm_find_cliFunction · 0.85
cbm_get_home_dirFunction · 0.85
cbm_subprocess_runFunction · 0.85

Tested by

no test coverage detected