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

Function connect_work_tree_and_git_dir

dir.c:4108–4146  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4106}
4107
4108void connect_work_tree_and_git_dir(const char *work_tree_,
4109 const char *git_dir_,
4110 int recurse_into_nested)
4111{
4112 struct strbuf gitfile_sb = STRBUF_INIT;
4113 struct strbuf cfg_sb = STRBUF_INIT;
4114 struct strbuf rel_path = STRBUF_INIT;
4115 char *git_dir, *work_tree;
4116
4117 /* Prepare .git file */
4118 strbuf_addf(&gitfile_sb, "%s/.git", work_tree_);
4119 if (safe_create_leading_directories_const(the_repository, gitfile_sb.buf))
4120 die(_("could not create directories for %s"), gitfile_sb.buf);
4121
4122 /* Prepare config file */
4123 strbuf_addf(&cfg_sb, "%s/config", git_dir_);
4124 if (safe_create_leading_directories_const(the_repository, cfg_sb.buf))
4125 die(_("could not create directories for %s"), cfg_sb.buf);
4126
4127 git_dir = real_pathdup(git_dir_, 1);
4128 work_tree = real_pathdup(work_tree_, 1);
4129
4130 /* Write .git file */
4131 write_file(gitfile_sb.buf, "gitdir: %s",
4132 relative_path(git_dir, work_tree, &rel_path));
4133 /* Update core.worktree setting */
4134 repo_config_set_in_file(the_repository, cfg_sb.buf, "core.worktree",
4135 relative_path(work_tree, git_dir, &rel_path));
4136
4137 strbuf_release(&gitfile_sb);
4138 strbuf_release(&cfg_sb);
4139 strbuf_release(&rel_path);
4140
4141 if (recurse_into_nested)
4142 connect_wt_gitdir_in_nested(work_tree, git_dir);
4143
4144 free(work_tree);
4145 free(git_dir);
4146}
4147
4148/*
4149 * Migrate the git directory of the given path from old_git_dir to new_git_dir.

Callers 6

submodule_move_headFunction · 0.85
relocate_gitdirFunction · 0.85
cmd_mvFunction · 0.85
clone_submoduleFunction · 0.85

Calls 9

strbuf_addfFunction · 0.85
real_pathdupFunction · 0.85
write_fileFunction · 0.85
relative_pathFunction · 0.85
repo_config_set_in_fileFunction · 0.85
strbuf_releaseFunction · 0.85
dieFunction · 0.70

Tested by

no test coverage detected