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

Function relocate_single_git_dir_into_superproject

submodule.c:2487–2527  ·  view source on GitHub ↗

* Embeds a single submodules git directory into the superprojects git dir, * non recursively. */

Source from the content-addressed store, hash-verified

2485 * non recursively.
2486 */
2487static void relocate_single_git_dir_into_superproject(const char *path,
2488 const char *super_prefix)
2489{
2490 char *old_git_dir = NULL, *real_old_git_dir = NULL, *real_new_git_dir = NULL;
2491 struct strbuf new_gitdir = STRBUF_INIT;
2492 const struct submodule *sub;
2493
2494 if (validate_submodule_path(path) < 0)
2495 exit(128);
2496
2497 if (submodule_uses_worktrees(path))
2498 die(_("relocate_gitdir for submodule '%s' with "
2499 "more than one worktree not supported"), path);
2500
2501 old_git_dir = xstrfmt("%s/.git", path);
2502 if (read_gitfile(old_git_dir))
2503 /* If it is an actual gitfile, it doesn't need migration. */
2504 return;
2505
2506 real_old_git_dir = real_pathdup(old_git_dir, 1);
2507
2508 sub = submodule_from_path(the_repository, null_oid(the_hash_algo), path);
2509 if (!sub)
2510 die(_("could not lookup name for submodule '%s'"), path);
2511
2512 submodule_name_to_gitdir(&new_gitdir, the_repository, sub->name);
2513 if (safe_create_leading_directories_const(the_repository, new_gitdir.buf) < 0)
2514 die(_("could not create directory '%s'"), new_gitdir.buf);
2515 real_new_git_dir = real_pathdup(new_gitdir.buf, 1);
2516
2517 fprintf(stderr, _("Migrating git directory of '%s%s' from\n'%s' to\n'%s'\n"),
2518 super_prefix ? super_prefix : "", path,
2519 real_old_git_dir, real_new_git_dir);
2520
2521 relocate_gitdir(path, real_old_git_dir, real_new_git_dir);
2522
2523 free(old_git_dir);
2524 free(real_old_git_dir);
2525 free(real_new_git_dir);
2526 strbuf_release(&new_gitdir);
2527}
2528
2529static void absorb_git_dir_into_superproject_recurse(const char *path,
2530 const char *super_prefix)

Callers 1

Calls 11

validate_submodule_pathFunction · 0.85
submodule_uses_worktreesFunction · 0.85
xstrfmtFunction · 0.85
real_pathdupFunction · 0.85
submodule_from_pathFunction · 0.85
null_oidFunction · 0.85
submodule_name_to_gitdirFunction · 0.85
relocate_gitdirFunction · 0.85
strbuf_releaseFunction · 0.85
dieFunction · 0.70

Tested by

no test coverage detected