aboutsummaryrefslogtreecommitdiff
path: root/dir.c
diff options
context:
space:
mode:
authorStefan Beller <sbeller@google.com>2016-12-12 11:04:34 -0800
committerJunio C Hamano <gitster@pobox.com>2016-12-12 15:15:07 -0800
commit47e83eb3b7d5410769d7f4d3930ba7fa12915680 (patch)
tree5178ade037b710a5d67fe7ee9b4daf310ebffaee /dir.c
parent1a248cf21d450eb911d01a89c84412c2da365e66 (diff)
downloadgit-47e83eb3b7d5410769d7f4d3930ba7fa12915680.tar.gz
git-47e83eb3b7d5410769d7f4d3930ba7fa12915680.tar.xz
move connect_work_tree_and_git_dir to dir.h
That function was primarily used by submodule code, but the function itself is not inherently about submodules. In the next patch we'll introduce relocate_git_dir, which can be used by worktrees as well, so find a neutral middle ground in dir.h. Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'dir.c')
-rw-r--r--dir.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/dir.c b/dir.c
index bfa8c8a9a..e0efd3c2c 100644
--- a/dir.c
+++ b/dir.c
@@ -2748,3 +2748,28 @@ void untracked_cache_add_to_index(struct index_state *istate,
{
untracked_cache_invalidate_path(istate, path);
}
+
+/* Update gitfile and core.worktree setting to connect work tree and git dir */
+void connect_work_tree_and_git_dir(const char *work_tree_, const char *git_dir_)
+{
+ struct strbuf file_name = STRBUF_INIT;
+ struct strbuf rel_path = STRBUF_INIT;
+ char *git_dir = xstrdup(real_path(git_dir_));
+ char *work_tree = xstrdup(real_path(work_tree_));
+
+ /* Update gitfile */
+ strbuf_addf(&file_name, "%s/.git", work_tree);
+ write_file(file_name.buf, "gitdir: %s",
+ relative_path(git_dir, work_tree, &rel_path));
+
+ /* Update core.worktree setting */
+ strbuf_reset(&file_name);
+ strbuf_addf(&file_name, "%s/config", git_dir);
+ git_config_set_in_file(file_name.buf, "core.worktree",
+ relative_path(work_tree, git_dir, &rel_path));
+
+ strbuf_release(&file_name);
+ strbuf_release(&rel_path);
+ free(work_tree);
+ free(git_dir);
+}