| 479 | } |
| 480 | |
| 481 | int checkout_entry_ca(struct cache_entry *ce, struct conv_attrs *ca, |
| 482 | const struct checkout *state, char *topath, |
| 483 | int *nr_checkouts) |
| 484 | { |
| 485 | static struct strbuf path = STRBUF_INIT; |
| 486 | struct stat st; |
| 487 | struct conv_attrs ca_buf; |
| 488 | |
| 489 | if (ce->ce_flags & CE_WT_REMOVE) { |
| 490 | if (topath) |
| 491 | /* |
| 492 | * No content and thus no path to create, so we have |
| 493 | * no pathname to return. |
| 494 | */ |
| 495 | BUG("Can't remove entry to a path"); |
| 496 | unlink_entry(ce, state->super_prefix); |
| 497 | return 0; |
| 498 | } |
| 499 | |
| 500 | if (topath) { |
| 501 | if (S_ISREG(ce->ce_mode) && !ca) { |
| 502 | convert_attrs(state->istate, &ca_buf, ce->name); |
| 503 | ca = &ca_buf; |
| 504 | } |
| 505 | return write_entry(ce, topath, ca, state, 1, nr_checkouts); |
| 506 | } |
| 507 | |
| 508 | strbuf_reset(&path); |
| 509 | strbuf_add(&path, state->base_dir, state->base_dir_len); |
| 510 | strbuf_add(&path, ce->name, ce_namelen(ce)); |
| 511 | |
| 512 | if (!check_path(path.buf, path.len, &st, state->base_dir_len)) { |
| 513 | const struct submodule *sub; |
| 514 | unsigned changed = ie_match_stat(state->istate, ce, &st, |
| 515 | CE_MATCH_IGNORE_VALID | CE_MATCH_IGNORE_SKIP_WORKTREE); |
| 516 | /* |
| 517 | * Needs to be checked before !changed returns early, |
| 518 | * as the possibly empty directory was not changed |
| 519 | */ |
| 520 | sub = submodule_from_ce(ce); |
| 521 | if (sub) { |
| 522 | int err; |
| 523 | if (!is_submodule_populated_gently(ce->name, &err)) { |
| 524 | struct stat sb; |
| 525 | if (lstat(ce->name, &sb)) |
| 526 | die(_("could not stat file '%s'"), ce->name); |
| 527 | if (!(st.st_mode & S_IFDIR)) |
| 528 | unlink_or_warn(ce->name); |
| 529 | |
| 530 | return submodule_move_head(ce->name, state->super_prefix, |
| 531 | NULL, oid_to_hex(&ce->oid), 0); |
| 532 | } else |
| 533 | return submodule_move_head(ce->name, state->super_prefix, |
| 534 | "HEAD", oid_to_hex(&ce->oid), |
| 535 | state->force ? SUBMODULE_MOVE_HEAD_FORCE : 0); |
| 536 | } |
| 537 | |
| 538 | if (!changed) |
no test coverage detected