Skip to content

Commit df56607

Browse files
max630gitster
authored andcommitted
git-common-dir: make "modules/" per-working-directory directory
Each working directory of main repository has its own working directory of submodule, and in most cases they should be checked out to different revisions. So they should be separated. It looks logical to make submodule instances in different working directories to reuse the submodule directory in the common dir of the main repository, and probably this is how "checkout --to" should initialize them called on the main repository, but they also should work fine being completely separated clones. Testfile t7410-submodule-checkout-to.sh demostrates the behavior. Signed-off-by: Max Kirillov <[email protected]> Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ee4fb84 commit df56607

File tree

3 files changed

+52
-4
lines changed

3 files changed

+52
-4
lines changed

Documentation/gitrepository-layout.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,7 @@ commondir::
248248
incomplete without the repository pointed by "commondir".
249249

250250
modules::
251-
Contains the git-repositories of the submodules. This
252-
directory is ignored if $GIT_COMMON_DIR is set and
253-
"$GIT_COMMON_DIR/modules" will be used instead.
251+
Contains the git-repositories of the submodules.
254252

255253
worktrees::
256254
Contains worktree specific information of linked

path.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ static void replace_dir(struct strbuf *buf, int len, const char *newdir)
9292
}
9393

9494
static const char *common_list[] = {
95-
"/branches", "/hooks", "/info", "!/logs", "/lost-found", "/modules",
95+
"/branches", "/hooks", "/info", "!/logs", "/lost-found",
9696
"/objects", "/refs", "/remotes", "/worktrees", "/rr-cache", "/svn",
9797
"config", "!gc.pid", "packed-refs", "shallow",
9898
NULL

t/t7410-submodule-checkout-to.sh

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/bin/sh
2+
3+
test_description='Combination of submodules and multiple workdirs'
4+
5+
. ./test-lib.sh
6+
7+
base_path=$(pwd -P)
8+
9+
test_expect_success 'setup: make origin' \
10+
'mkdir -p origin/sub && ( cd origin/sub && git init &&
11+
echo file1 >file1 &&
12+
git add file1 &&
13+
git commit -m file1 ) &&
14+
mkdir -p origin/main && ( cd origin/main && git init &&
15+
git submodule add ../sub &&
16+
git commit -m "add sub" ) &&
17+
( cd origin/sub &&
18+
echo file1updated >file1 &&
19+
git add file1 &&
20+
git commit -m "file1 updated" ) &&
21+
( cd origin/main/sub && git pull ) &&
22+
( cd origin/main &&
23+
git add sub &&
24+
git commit -m "sub updated" )'
25+
26+
test_expect_success 'setup: clone' \
27+
'mkdir clone && ( cd clone &&
28+
git clone --recursive "$base_path/origin/main")'
29+
30+
rev1_hash_main=$(git --git-dir=origin/main/.git show --pretty=format:%h -q "HEAD~1")
31+
rev1_hash_sub=$(git --git-dir=origin/sub/.git show --pretty=format:%h -q "HEAD~1")
32+
33+
test_expect_success 'checkout main' \
34+
'mkdir default_checkout &&
35+
(cd clone/main &&
36+
git checkout --to "$base_path/default_checkout/main" "$rev1_hash_main")'
37+
38+
test_expect_failure 'can see submodule diffs just after checkout' \
39+
'(cd default_checkout/main && git diff --submodule master"^!" | grep "file1 updated")'
40+
41+
test_expect_success 'checkout main and initialize independed clones' \
42+
'mkdir fully_cloned_submodule &&
43+
(cd clone/main &&
44+
git checkout --to "$base_path/fully_cloned_submodule/main" "$rev1_hash_main") &&
45+
(cd fully_cloned_submodule/main && git submodule update)'
46+
47+
test_expect_success 'can see submodule diffs after independed cloning' \
48+
'(cd fully_cloned_submodule/main && git diff --submodule master"^!" | grep "file1 updated")'
49+
50+
test_done

0 commit comments

Comments
 (0)