| 329 | } |
| 330 | |
| 331 | int cbm_git_branch_resolve(const char *path, bool *is_git, char *branch, size_t branch_size) { |
| 332 | if (!is_git || !branch || branch_size == 0) { |
| 333 | return CBM_NOT_FOUND; |
| 334 | } |
| 335 | *is_git = false; |
| 336 | branch[0] = '\0'; |
| 337 | if (!path || !path[0]) { |
| 338 | return CBM_NOT_FOUND; |
| 339 | } |
| 340 | if (!cbm_is_dir(path)) { |
| 341 | return 0; |
| 342 | } |
| 343 | char worktree_root[GIT_OUTPUT_MAX]; |
| 344 | if (git_capture_into(path, "rev-parse --show-toplevel", worktree_root, sizeof(worktree_root)) != |
| 345 | 0) { |
| 346 | return 0; |
| 347 | } |
| 348 | *is_git = true; |
| 349 | if (git_capture_into(path, "symbolic-ref --quiet --short HEAD", branch, branch_size) != 0) { |
| 350 | snprintf(branch, branch_size, "%s", "DETACHED"); |
| 351 | } |
| 352 | return 0; |
| 353 | } |
| 354 | |
| 355 | char *cbm_git_context_branch_qn(const char *project_name, const cbm_git_context_t *ctx) { |
| 356 | const char *project = project_name && project_name[0] ? project_name : "project"; |