MCPcopy Create free account
hub / github.com/git/git / verify_clean_subdirectory

Function verify_clean_subdirectory

unpack-trees.c:2320–2393  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2318}
2319
2320static int verify_clean_subdirectory(const struct cache_entry *ce,
2321 struct unpack_trees_options *o)
2322{
2323 /*
2324 * we are about to extract "ce->name"; we would not want to lose
2325 * anything in the existing directory there.
2326 */
2327 int namelen;
2328 int i;
2329 struct dir_struct d;
2330 char *pathbuf;
2331 int cnt = 0;
2332
2333 if (S_ISGITLINK(ce->ce_mode)) {
2334 struct object_id oid;
2335 int sub_head = repo_resolve_gitlink_ref(the_repository, ce->name,
2336 "HEAD", &oid);
2337 /*
2338 * If we are not going to update the submodule, then
2339 * we don't care.
2340 */
2341 if (!sub_head && oideq(&oid, &ce->oid))
2342 return 0;
2343 return verify_clean_submodule(sub_head ? NULL : oid_to_hex(&oid),
2344 ce, o);
2345 }
2346
2347 /*
2348 * First let's make sure we do not have a local modification
2349 * in that directory.
2350 */
2351 namelen = ce_namelen(ce);
2352 for (i = locate_in_src_index(ce, o);
2353 i < o->src_index->cache_nr;
2354 i++) {
2355 struct cache_entry *ce2 = o->src_index->cache[i];
2356 int len = ce_namelen(ce2);
2357 if (len < namelen ||
2358 strncmp(ce->name, ce2->name, namelen) ||
2359 ce2->name[namelen] != '/')
2360 break;
2361 /*
2362 * ce2->name is an entry in the subdirectory to be
2363 * removed.
2364 */
2365 if (!ce_stage(ce2)) {
2366 if (verify_uptodate(ce2, o))
2367 return -1;
2368 add_entry(o, ce2, CE_REMOVE, 0);
2369 invalidate_ce_path(ce, o);
2370 mark_ce_used(ce2, o);
2371 }
2372 cnt++;
2373 }
2374
2375 /* Do not lose a locally present file that is not ignored. */
2376 pathbuf = xstrfmt("%.*s/", namelen, ce->name);
2377

Callers 1

check_ok_to_removeFunction · 0.85

Calls 14

repo_resolve_gitlink_refFunction · 0.85
oideqFunction · 0.85
verify_clean_submoduleFunction · 0.85
oid_to_hexFunction · 0.85
locate_in_src_indexFunction · 0.85
verify_uptodateFunction · 0.85
invalidate_ce_pathFunction · 0.85
mark_ce_usedFunction · 0.85
xstrfmtFunction · 0.85
setup_standard_excludesFunction · 0.85
read_directoryFunction · 0.85
dir_clearFunction · 0.85

Tested by

no test coverage detected