Skip to content

Commit e983175

Browse files
stefanbellergitster
authored andcommitted
submodule: ensure core.worktree is set after update
Signed-off-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4fa4f90 commit e983175

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

builtin/submodule--helper.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1860,6 +1860,29 @@ static int check_name(int argc, const char **argv, const char *prefix)
18601860
return 0;
18611861
}
18621862

1863+
static int connect_gitdir_workingtree(int argc, const char **argv, const char *prefix)
1864+
{
1865+
struct strbuf sb = STRBUF_INIT;
1866+
const char *name, *path;
1867+
char *sm_gitdir;
1868+
1869+
if (argc != 3)
1870+
BUG("submodule--helper connect-gitdir-workingtree <name> <path>");
1871+
1872+
name = argv[1];
1873+
path = argv[2];
1874+
1875+
strbuf_addf(&sb, "%s/modules/%s", get_git_dir(), name);
1876+
sm_gitdir = absolute_pathdup(sb.buf);
1877+
1878+
connect_work_tree_and_git_dir(path, sm_gitdir, 0);
1879+
1880+
strbuf_release(&sb);
1881+
free(sm_gitdir);
1882+
1883+
return 0;
1884+
}
1885+
18631886
#define SUPPORT_SUPER_PREFIX (1<<0)
18641887

18651888
struct cmd_struct {
@@ -1873,6 +1896,7 @@ static struct cmd_struct commands[] = {
18731896
{"name", module_name, 0},
18741897
{"clone", module_clone, 0},
18751898
{"update-clone", update_clone, 0},
1899+
{"connect-gitdir-workingtree", connect_gitdir_workingtree, 0},
18761900
{"relative-path", resolve_relative_path, 0},
18771901
{"resolve-relative-url", resolve_relative_url, 0},
18781902
{"resolve-relative-url-test", resolve_relative_url_test, 0},

git-submodule.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,11 @@ cmd_update()
615615
die "$(eval_gettext "Unable to find current \${remote_name}/\${branch} revision in submodule path '\$sm_path'")"
616616
fi
617617

618+
if ! $(git config -f "$(git rev-parse --git-common-dir)/modules/$name/config" core.worktree) 2>/dev/null
619+
then
620+
git submodule--helper connect-gitdir-workingtree "$name" "$sm_path"
621+
fi
622+
618623
if test "$subsha1" != "$sha1" || test -n "$force"
619624
then
620625
subforce=$force

0 commit comments

Comments
 (0)