summaryrefslogtreecommitdiff
path: root/dir.c
diff options
context:
space:
mode:
authorStefan Beller <sbeller@google.com>2016-12-12 19:04:35 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-12-12 23:15:07 (GMT)
commitf6f858614003a3da794385cefdbddf00b85f7501 (patch)
treee62a35068d126bc51f6ab83651b57077ba794e29 /dir.c
parent47e83eb3b7d5410769d7f4d3930ba7fa12915680 (diff)
downloadgit-f6f858614003a3da794385cefdbddf00b85f7501.zip
git-f6f858614003a3da794385cefdbddf00b85f7501.tar.gz
git-f6f858614003a3da794385cefdbddf00b85f7501.tar.bz2
submodule: add absorb-git-dir function
When a submodule has its git dir inside the working dir, the submodule support for checkout that we plan to add in a later patch will fail. Add functionality to migrate the git directory to be absorbed into the superprojects git directory. The newly added code in this patch is structured such that other areas of Git can also make use of it. The code in the submodule--helper is a mere wrapper and option parser for the function `absorb_git_dir_into_superproject`, that takes care of embedding the submodules git directory into the superprojects git dir. That function makes use of the more abstract function for this use case `relocate_gitdir`, which can be used by e.g. the worktree code eventually to move around a git directory. 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.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/dir.c b/dir.c
index e0efd3c..d872cc1 100644
--- a/dir.c
+++ b/dir.c
@@ -2773,3 +2773,15 @@ void connect_work_tree_and_git_dir(const char *work_tree_, const char *git_dir_)
free(work_tree);
free(git_dir);
}
+
+/*
+ * Migrate the git directory of the given path from old_git_dir to new_git_dir.
+ */
+void relocate_gitdir(const char *path, const char *old_git_dir, const char *new_git_dir)
+{
+ if (rename(old_git_dir, new_git_dir) < 0)
+ die_errno(_("could not migrate git directory from '%s' to '%s'"),
+ old_git_dir, new_git_dir);
+
+ connect_work_tree_and_git_dir(path, new_git_dir);
+}