True iff `commit` names an object that exists locally AND is a commit * (shallow/partial-clone guard). * * Deliberately `cat-file -t ` rather than `cat-file -e ^{commit}`: * the peel suffix contains `^`, which is cmd.exe's escape character. Quoting * cannot be relied on to neutralise it across both shells, and a mangled * argument here would silently disable reconciliation on Windo
| 456 | * argument here would silently disable reconciliation on Windows. `-t` needs |
| 457 | * no metacharacters at all — the oid is already hex-validated. */ |
| 458 | static bool git_commit_exists(const char *repo_path, const char *commit) { |
| 459 | char args[CBM_SZ_128]; |
| 460 | int n = snprintf(args, sizeof(args), "cat-file -t %s", commit); |
| 461 | if (n < 0 || (size_t)n >= sizeof(args)) { |
| 462 | return false; |
| 463 | } |
| 464 | char *type = NULL; |
| 465 | size_t type_len = 0; |
| 466 | if (git_capture_full(repo_path, args, &type, &type_len) != 0) { |
| 467 | return false; |
| 468 | } |
| 469 | static const char kCommit[] = "commit"; |
| 470 | size_t want = sizeof(kCommit) - ART_NUL; |
| 471 | bool is_commit = type_len >= want && memcmp(type, kCommit, want) == 0 && |
| 472 | (type_len == want || type[want] == '\n' || type[want] == '\r'); |
| 473 | free(type); |
| 474 | return is_commit; |
| 475 | } |
| 476 | |
| 477 | /* True iff the working tree has no tracked/staged/untracked changes outside |
| 478 | * .codebase-memory/. The export itself writes .codebase-memory/, so a blanket |
no test coverage detected