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

Function mcp_test_git

tests/test_mcp.c:292–368  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

test_mcp.cFile · 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