| 131 | } |
| 132 | |
| 133 | static int git_head(const char *root_path, char *out, size_t out_size) { |
| 134 | char cmd[CBM_SZ_1K]; |
| 135 | snprintf(cmd, sizeof(cmd), "git -C \"%s\" rev-parse HEAD 2>%s", root_path, WATCHER_NULDEV); |
| 136 | FILE *fp = cbm_popen(cmd, "r"); |
| 137 | if (!fp) { |
| 138 | return CBM_NOT_FOUND; |
| 139 | } |
| 140 | |
| 141 | if (fgets(out, (int)out_size, fp)) { |
| 142 | size_t len = strlen(out); |
| 143 | while (len > 0 && (out[len - SKIP_ONE] == '\n' || out[len - SKIP_ONE] == '\r')) { |
| 144 | out[--len] = '\0'; |
| 145 | } |
| 146 | cbm_pclose(fp); |
| 147 | return 0; |
| 148 | } |
| 149 | cbm_pclose(fp); |
| 150 | return CBM_NOT_FOUND; |
| 151 | } |
| 152 | |
| 153 | /* Returns true if working tree has changes (modified, untracked, etc.). |
| 154 | * Also checks submodules via `git submodule foreach` to detect uncommitted |
no test coverage detected