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

Function mcp_test_git

tests/test_mcp.c:261–337  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

259}
260
261static int mcp_test_git(const char *root, const char *const *arguments) {
262 char empty_config[CBM_SZ_4K];
263 int config_length =
264 snprintf(empty_config, sizeof(empty_config), "%s/.cbm-empty-gitconfig", root);
265 if (config_length <= 0 || (size_t)config_length >= sizeof(empty_config)) {
266 return -1;
267 }
268 FILE *config = cbm_fopen(empty_config, "wb");
269 if (!config) {
270 return -1;
271 }
272 if (fclose(config) != 0) {
273 return -1;
274 }
275
276 mcp_test_env_backup_t backups[] = {
277 {.name = "GIT_CONFIG_GLOBAL"}, {.name = "GIT_CONFIG_SYSTEM"},
278 {.name = "GIT_CONFIG_NOSYSTEM"}, {.name = "GIT_CONFIG_COUNT"},
279 {.name = "GIT_CONFIG_PARAMETERS"},
280 };
281 bool snapshot_ok = true;
282 for (size_t index = 0; index < sizeof(backups) / sizeof(backups[0]); index++) {
283 const char *value = getenv(backups[index].name);
284 backups[index].present = value != NULL;
285 backups[index].value = value ? strdup(value) : NULL;
286 snapshot_ok = snapshot_ok && (!value || backups[index].value);
287 }
288 if (!snapshot_ok) {
289 for (size_t index = 0; index < sizeof(backups) / sizeof(backups[0]); index++) {
290 free(backups[index].value);
291 }
292 return -1;
293 }
294 bool environment_ok = cbm_setenv("GIT_CONFIG_GLOBAL", empty_config, 1) == 0 &&
295 cbm_setenv("GIT_CONFIG_SYSTEM", empty_config, 1) == 0 &&
296 cbm_setenv("GIT_CONFIG_NOSYSTEM", "1", 1) == 0 &&
297 cbm_setenv("GIT_CONFIG_COUNT", "0", 1) == 0 &&
298 cbm_unsetenv("GIT_CONFIG_PARAMETERS") == 0;
299 if (!environment_ok) {
300 mcp_test_restore_env(backups, sizeof(backups) / sizeof(backups[0]));
301 return -1;
302 }
303
304 const char *git = "git";
305#ifdef _WIN32
306 char git_executable[CBM_SZ_4K];
307 const char *resolved = cbm_find_cli("git", cbm_get_home_dir());
308 int resolved_length =
309 resolved ? snprintf(git_executable, sizeof(git_executable), "%s", resolved) : -1;
310 if (resolved_length <= 0 || (size_t)resolved_length >= sizeof(git_executable)) {
311 mcp_test_restore_env(backups, sizeof(backups) / sizeof(backups[0]));
312 return -1;
313 }
314 git = git_executable;
315#endif
316 const char *argv[24] = {git, "-C", root};
317 size_t index = 3;
318 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