* Determine if a submodule has been initialized at a given 'path' */ * NEEDSWORK: Emit a warning if submodule.active exists, but is valueless, * ie, the config looks like: "[submodule] active\n". * Since that is an invalid pathspec, we should inform the user. */
| 237 | * Since that is an invalid pathspec, we should inform the user. |
| 238 | */ |
| 239 | int is_tree_submodule_active(struct repository *repo, |
| 240 | const struct object_id *treeish_name, |
| 241 | const char *path) |
| 242 | { |
| 243 | int ret = 0; |
| 244 | char *key = NULL; |
| 245 | char *value = NULL; |
| 246 | const struct string_list *sl; |
| 247 | const struct submodule *module; |
| 248 | |
| 249 | module = submodule_from_path(repo, treeish_name, path); |
| 250 | |
| 251 | /* early return if there isn't a path->module mapping */ |
| 252 | if (!module) |
| 253 | return 0; |
| 254 | |
| 255 | /* submodule.<name>.active is set */ |
| 256 | key = xstrfmt("submodule.%s.active", module->name); |
| 257 | if (!repo_config_get_bool(repo, key, &ret)) { |
| 258 | free(key); |
| 259 | return ret; |
| 260 | } |
| 261 | free(key); |
| 262 | |
| 263 | /* submodule.active is set */ |
| 264 | if (!repo_config_get_string_multi(repo, "submodule.active", &sl)) { |
| 265 | struct pathspec ps; |
| 266 | struct strvec args = STRVEC_INIT; |
| 267 | const struct string_list_item *item; |
| 268 | |
| 269 | for_each_string_list_item(item, sl) { |
| 270 | strvec_push(&args, item->string); |
| 271 | } |
| 272 | |
| 273 | parse_pathspec(&ps, 0, 0, NULL, args.v); |
| 274 | ret = match_pathspec(repo->index, &ps, path, strlen(path), 0, NULL, 1); |
| 275 | |
| 276 | strvec_clear(&args); |
| 277 | clear_pathspec(&ps); |
| 278 | return ret; |
| 279 | } |
| 280 | |
| 281 | /* fallback to checking if the URL is set */ |
| 282 | key = xstrfmt("submodule.%s.url", module->name); |
| 283 | ret = !repo_config_get_string(repo, key, &value); |
| 284 | |
| 285 | free(value); |
| 286 | free(key); |
| 287 | return ret; |
| 288 | } |
| 289 | |
| 290 | int is_submodule_active(struct repository *repo, const char *path) |
| 291 | { |
no test coverage detected