| 322 | #define FOREACH_CB_INIT { 0 } |
| 323 | |
| 324 | static void runcommand_in_submodule_cb(const struct cache_entry *list_item, |
| 325 | void *cb_data) |
| 326 | { |
| 327 | struct foreach_cb *info = cb_data; |
| 328 | const char *path = list_item->name; |
| 329 | const struct object_id *ce_oid = &list_item->oid; |
| 330 | const struct submodule *sub; |
| 331 | struct child_process cp = CHILD_PROCESS_INIT; |
| 332 | char *displaypath; |
| 333 | |
| 334 | if (validate_submodule_path(path) < 0) |
| 335 | die(NULL); |
| 336 | |
| 337 | displaypath = get_submodule_displaypath(path, info->prefix, |
| 338 | info->super_prefix); |
| 339 | |
| 340 | sub = submodule_from_path(the_repository, null_oid(the_hash_algo), path); |
| 341 | |
| 342 | if (!sub) |
| 343 | die(_("No url found for submodule path '%s' in .gitmodules"), |
| 344 | displaypath); |
| 345 | |
| 346 | if (!is_submodule_populated_gently(path, NULL)) |
| 347 | goto cleanup; |
| 348 | |
| 349 | prepare_submodule_repo_env(&cp.env); |
| 350 | |
| 351 | /* |
| 352 | * For the purpose of executing <command> in the submodule, |
| 353 | * separate shell is used for the purpose of running the |
| 354 | * child process. |
| 355 | */ |
| 356 | cp.use_shell = 1; |
| 357 | cp.dir = path; |
| 358 | |
| 359 | /* |
| 360 | * NEEDSWORK: the command currently has access to the variables $name, |
| 361 | * $sm_path, $displaypath, $sha1 and $toplevel only when the command |
| 362 | * contains a single argument. This is done for maintaining a faithful |
| 363 | * translation from shell script. |
| 364 | */ |
| 365 | if (info->argc == 1) { |
| 366 | char *toplevel = xgetcwd(); |
| 367 | struct strbuf sb = STRBUF_INIT; |
| 368 | |
| 369 | strvec_pushf(&cp.env, "name=%s", sub->name); |
| 370 | strvec_pushf(&cp.env, "sm_path=%s", path); |
| 371 | strvec_pushf(&cp.env, "displaypath=%s", displaypath); |
| 372 | strvec_pushf(&cp.env, "sha1=%s", |
| 373 | oid_to_hex(ce_oid)); |
| 374 | strvec_pushf(&cp.env, "toplevel=%s", toplevel); |
| 375 | |
| 376 | /* |
| 377 | * Since the path variable was accessible from the script |
| 378 | * before porting, it is also made available after porting. |
| 379 | * The environment variable "PATH" has a very special purpose |
| 380 | * on windows. And since environment variables are |
| 381 | * case-insensitive in windows, it interferes with the |
nothing calls this directly
no test coverage detected