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

Function detect_default_base_repo

tests/test_mcp.c:15972–16007  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15970} detect_default_base_probe_t;
15971
15972static bool detect_default_base_repo(const char *repo, const char *default_branch,
15973 bool set_origin_head) {
15974 char head_ref[CBM_SZ_256];
15975 snprintf(head_ref, sizeof(head_ref), "refs/heads/%s", default_branch);
15976 char remote_ref[CBM_SZ_256];
15977 snprintf(remote_ref, sizeof(remote_ref), "refs/remotes/origin/%s", default_branch);
15978 char base_file[CBM_SZ_4K];
15979 char feature_file[CBM_SZ_4K];
15980 snprintf(base_file, sizeof(base_file), "%s/base.c", repo);
15981 snprintf(feature_file, sizeof(feature_file), "%s/feature.c", repo);
15982 const char *const init_args[] = {"init", "-q", NULL};
15983 const char *const head_args[] = {"symbolic-ref", "HEAD", head_ref, NULL};
15984 const char *const add_base_args[] = {"add", "base.c", NULL};
15985 const char *const add_feature_args[] = {"add", "feature.c", NULL};
15986 const char *const commit_args[] = {
15987 "-c", "user.name=cbm-test",
15988 "-c", "user.email=cbm-test@example.invalid",
15989 "-c", "commit.gpgsign=false",
15990 "commit", "-q",
15991 "-m", "fixture",
15992 NULL,
15993 };
15994 const char *const remote_args[] = {"update-ref", remote_ref, "HEAD", NULL};
15995 const char *const origin_head_args[] = {"symbolic-ref", "refs/remotes/origin/HEAD", remote_ref,
15996 NULL};
15997 const char *const feature_args[] = {"checkout", "-q", "-b", "feature", NULL};
15998 bool ok = mcp_test_git(repo, init_args) == 0 && mcp_test_git(repo, head_args) == 0 &&
15999 th_write_file(base_file, "int base_value = 1;\n") == 0 &&
16000 mcp_test_git(repo, add_base_args) == 0 && mcp_test_git(repo, commit_args) == 0;
16001 if (ok && set_origin_head) {
16002 ok = mcp_test_git(repo, remote_args) == 0 && mcp_test_git(repo, origin_head_args) == 0;
16003 }
16004 return ok && mcp_test_git(repo, feature_args) == 0 &&
16005 th_write_file(feature_file, "int feature_value = 2;\n") == 0 &&
16006 mcp_test_git(repo, add_feature_args) == 0 && mcp_test_git(repo, commit_args) == 0;
16007}
16008
16009static bool detect_default_base_run(const char *default_branch, bool set_origin_head,
16010 const char *base_arg, detect_default_base_probe_t *probe) {

Callers 1

detect_default_base_runFunction · 0.85

Calls 2

mcp_test_gitFunction · 0.85
th_write_fileFunction · 0.85

Tested by

no test coverage detected