| 4106 | } |
| 4107 | |
| 4108 | void 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. |
no test coverage detected