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

Function git_head

src/watcher/watcher.c:455–483  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

453}
454
455static watcher_git_status_t git_head(cbm_watcher_t *w, project_state_t *state, char *out,
456 size_t out_size) {
457 if (!out || out_size < 2) {
458 return WATCHER_GIT_SUPERVISION_FAILED;
459 }
460 out[0] = '\0';
461 const char *argv[] = {"git", "-C", state->root_path, "rev-parse", "HEAD", NULL};
462 watcher_git_output_t output;
463 watcher_git_status_t status = watcher_git_run(w, state, argv, WATCHER_GIT_HEAD_MAX, &output);
464 if (status != WATCHER_GIT_OK) {
465 return status;
466 }
467 FILE *file = cbm_fopen(output.path, "rb");
468 bool read = file && fgets(out, (int)out_size, file) != NULL;
469 int extra = file ? fgetc(file) : EOF;
470 if (file) {
471 read = fclose(file) == 0 && read;
472 }
473 watcher_git_output_cleanup(&output);
474 if (!read || extra != EOF) {
475 out[0] = '\0';
476 return WATCHER_GIT_SUPERVISION_FAILED;
477 }
478 size_t len = strlen(out);
479 while (len > 0 && (out[len - SKIP_ONE] == '\n' || out[len - SKIP_ONE] == '\r')) {
480 out[--len] = '\0';
481 }
482 return len > 0 ? WATCHER_GIT_OK : WATCHER_GIT_COMMAND_FAILED;
483}
484
485/* ── Dirty-state signature (#937) ───────────────────────────────── */
486

Callers 2

init_baselineFunction · 0.85
check_changesFunction · 0.85

Calls 3

watcher_git_runFunction · 0.85
cbm_fopenFunction · 0.85

Tested by

no test coverage detected