]> asedeno.scripts.mit.edu Git - git.git/blob - t/t7407-submodule-foreach.sh
Add selftest for 'git submodule foreach'
[git.git] / t / t7407-submodule-foreach.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2009 Johan Herland
4 #
5
6 test_description='Test "git submodule foreach"
7
8 This test verifies that "git submodule foreach" correctly visits all submodules
9 that are currently checked out.
10 '
11
12 . ./test-lib.sh
13
14
15 test_expect_success 'setup a submodule tree' '
16         echo file > file &&
17         git add file &&
18         test_tick &&
19         git commit -m upstream
20         git clone . super &&
21         git clone super submodule &&
22         (
23                 cd super &&
24                 git submodule add ../submodule sub1 &&
25                 git submodule add ../submodule sub2 &&
26                 git submodule add ../submodule sub3 &&
27                 git config -f .gitmodules --rename-section \
28                         submodule.sub1 submodule.foo1 &&
29                 git config -f .gitmodules --rename-section \
30                         submodule.sub2 submodule.foo2 &&
31                 git config -f .gitmodules --rename-section \
32                         submodule.sub3 submodule.foo3 &&
33                 git add .gitmodules
34                 test_tick &&
35                 git commit -m "submodules" &&
36                 git submodule init sub1 &&
37                 git submodule init sub2 &&
38                 git submodule init sub3
39         ) &&
40         (
41                 cd submodule &&
42                 echo different > file &&
43                 git add file &&
44                 test_tick &&
45                 git commit -m "different"
46         ) &&
47         (
48                 cd super &&
49                 (
50                         cd sub3 &&
51                         git pull
52                 ) &&
53                 git add sub3 &&
54                 test_tick &&
55                 git commit -m "update sub3"
56         )
57 '
58
59 sub1sha1=$(cd super/sub1 && git rev-parse HEAD)
60 sub3sha1=$(cd super/sub3 && git rev-parse HEAD)
61
62 cat > expect <<EOF
63 Entering 'sub1'
64 sub1-$sub1sha1
65 Entering 'sub3'
66 sub3-$sub3sha1
67 EOF
68
69 test_expect_success 'test basic "submodule foreach" usage' '
70         git clone super clone &&
71         (
72                 cd clone &&
73                 git submodule update --init -- sub1 sub3 &&
74                 git submodule foreach "echo \$path-\$sha1" > ../actual
75         ) &&
76         test_cmp expect actual
77 '
78
79 test_done