Skip to content

Commit bef3894

Browse files
dschogitster
authored andcommitted
Fix 'git checkout <submodule>' to update the index
While 'git checkout <submodule>' should not update the submodule's working directory, it should update the index. This is in line with how submodules are handled in the rest of Git. While at it, test 'git reset [<commit>] <submodule>', too. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7634817 commit bef3894

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

builtin-checkout.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ static int update_some(const unsigned char *sha1, const char *base, int baselen,
5353
int len;
5454
struct cache_entry *ce;
5555

56-
if (S_ISGITLINK(mode))
57-
return 0;
58-
5956
if (S_ISDIR(mode))
6057
return READ_TREE_RECURSIVE;
6158

t/t2013-checkout-submodule.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/sh
2+
3+
test_description='checkout can handle submodules'
4+
5+
. ./test-lib.sh
6+
7+
test_expect_success 'setup' '
8+
mkdir submodule &&
9+
(cd submodule &&
10+
git init &&
11+
test_commit first) &&
12+
git add submodule &&
13+
test_tick &&
14+
git commit -m superproject &&
15+
(cd submodule &&
16+
test_commit second) &&
17+
git add submodule &&
18+
test_tick &&
19+
git commit -m updated.superproject
20+
'
21+
22+
test_expect_success '"reset <submodule>" updates the index' '
23+
git update-index --refresh &&
24+
git diff-files --quiet &&
25+
git diff-index --quiet --cached HEAD &&
26+
test_must_fail git reset HEAD^ submodule &&
27+
test_must_fail git diff-files --quiet &&
28+
git reset submodule &&
29+
git diff-files --quiet
30+
'
31+
32+
test_expect_success '"checkout <submodule>" updates the index only' '
33+
git update-index --refresh &&
34+
git diff-files --quiet &&
35+
git diff-index --quiet --cached HEAD &&
36+
git checkout HEAD^ submodule &&
37+
test_must_fail git diff-files --quiet &&
38+
git checkout HEAD submodule &&
39+
git diff-files --quiet
40+
'
41+
42+
test_done

0 commit comments

Comments
 (0)