19
#include "varint.h"
20
#include "ewah/ewok.h"
21
#include "fsmonitor.h"
22
+#include "submodule-config.h"
23
24
/*
25
* Tells read_directory_recursive how a file or directory should be treated.
2989
untracked_cache_invalidate_path(istate, path);
2990
}
2991
2991
-/* Update gitfile and core.worktree setting to connect work tree and git dir */
2992
-void connect_work_tree_and_git_dir(const char *work_tree_, const char *git_dir_)
2992
+static void connect_wt_gitdir_in_nested(const char *sub_worktree,
2993
+ const char *sub_gitdir)
2994
+{
2995
+ int i;
2996
+ struct repository subrepo;
2997
+ struct strbuf sub_wt = STRBUF_INIT;
2998
+ struct strbuf sub_gd = STRBUF_INIT;
2999
+
3000
+ const struct submodule *sub;
3001
+
3002
+ /* If the submodule has no working tree, we can ignore it. */
3003
+ if (repo_init(&subrepo, sub_gitdir, sub_worktree))
3004
+ return;
3005
+
3006
+ if (repo_read_index(&subrepo) < 0)
3007
+ die("index file corrupt in repo %s", subrepo.gitdir);
3008
+
3009
+ for (i = 0; i < subrepo.index->cache_nr; i++) {
3010
+ const struct cache_entry *ce = subrepo.index->cache[i];
3011
+
3012
+ if (!S_ISGITLINK(ce->ce_mode))
3013
+ continue;
3014
+
3015
+ while (i + 1 < subrepo.index->cache_nr &&
3016
+ !strcmp(ce->name, subrepo.index->cache[i + 1]->name))
3017
+ /*
3018
+ * Skip entries with the same name in different stages
3019
+ * to make sure an entry is returned only once.
3020
+ */
3021
+ i++;
3022
+
3023
+ sub = submodule_from_path(&subrepo, &null_oid, ce->name);
3024
+ if (!sub || !is_submodule_active(&subrepo, ce->name))
3025
+ /* .gitmodules broken or inactive sub */
3026
+ continue;
3027
+
3028
+ strbuf_reset(&sub_wt);
3029
+ strbuf_reset(&sub_gd);
3030
+ strbuf_addf(&sub_wt, "%s/%s", sub_worktree, sub->path);
3031
+ strbuf_addf(&sub_gd, "%s/modules/%s", sub_gitdir, sub->name);
3032
+
3033
+ connect_work_tree_and_git_dir(sub_wt.buf, sub_gd.buf, 1);
3034
+ }
3035
+ strbuf_release(&sub_wt);
3036
+ strbuf_release(&sub_gd);
3037
+ repo_clear(&subrepo);
3038
+}
3039
+
3040
+void connect_work_tree_and_git_dir(const char *work_tree_,
3041
+ const char *git_dir_,
3042
+ int recurse_into_nested)
3043
{
3044
struct strbuf gitfile_sb = STRBUF_INIT;
3045
struct strbuf cfg_sb = STRBUF_INIT;
3069
strbuf_release(&gitfile_sb);
3070
strbuf_release(&cfg_sb);
3071
strbuf_release(&rel_path);
3072
+
3073
+ if (recurse_into_nested)
3074
+ connect_wt_gitdir_in_nested(work_tree, git_dir);
3075
+
3076
free(work_tree);
3077
free(git_dir);
3078
}
3086
die_errno(_("could not migrate git directory from '%s' to '%s'"),
3087
old_git_dir, new_git_dir);
3088
3035
- connect_work_tree_and_git_dir(path, new_git_dir);
3089
+ connect_work_tree_and_git_dir(path, new_git_dir, 0);
3090
}