* Has the work tree entity been removed? * * Return 1 if it was removed from the work tree, 0 if an entity to be * compared with the cache entry ce still exists (the latter includes * the case where a directory that is not a submodule repository * exists for ce that is a submodule -- it is a submodule that is not * checked out). Return negative for an error. */
| 40 | * checked out). Return negative for an error. |
| 41 | */ |
| 42 | static int check_removed(const struct cache_entry *ce, struct stat *st) |
| 43 | { |
| 44 | int stat_err; |
| 45 | |
| 46 | if (!(ce->ce_flags & CE_FSMONITOR_VALID)) |
| 47 | stat_err = lstat(ce->name, st); |
| 48 | else |
| 49 | stat_err = fake_lstat(ce, st); |
| 50 | if (stat_err < 0) { |
| 51 | if (!is_missing_file_error(errno)) |
| 52 | return -1; |
| 53 | return 1; |
| 54 | } |
| 55 | |
| 56 | if (has_symlink_leading_path(ce->name, ce_namelen(ce))) |
| 57 | return 1; |
| 58 | if (S_ISDIR(st->st_mode)) { |
| 59 | struct object_id sub; |
| 60 | |
| 61 | /* |
| 62 | * If ce is already a gitlink, we can have a plain |
| 63 | * directory (i.e. the submodule is not checked out), |
| 64 | * or a checked out submodule. Either case this is not |
| 65 | * a case where something was removed from the work tree, |
| 66 | * so we will return 0. |
| 67 | * |
| 68 | * Otherwise, if the directory is not a submodule |
| 69 | * repository, that means ce which was a blob turned into |
| 70 | * a directory --- the blob was removed! |
| 71 | */ |
| 72 | if (!S_ISGITLINK(ce->ce_mode) && |
| 73 | repo_resolve_gitlink_ref(the_repository, ce->name, |
| 74 | "HEAD", &sub)) |
| 75 | return 1; |
| 76 | } |
| 77 | return 0; |
| 78 | } |
| 79 | |
| 80 | /* |
| 81 | * Has a file changed or has a submodule new commits or a dirty work tree? |
no test coverage detected