Merge branch 'dl/complete-stash-updates'
[git] / t / t4255-am-submodule.sh
1 #!/bin/sh
2
3 test_description='git am handling submodules'
4
5 . ./test-lib.sh
6 . "$TEST_DIRECTORY"/lib-submodule-update.sh
7
8 am () {
9         git format-patch --stdout --ignore-submodules=dirty "..$1" >patch &&
10         may_only_be_test_must_fail "$2" &&
11         $2 git am patch
12 }
13
14 test_submodule_switch_func "am"
15
16 am_3way () {
17         git format-patch --stdout --ignore-submodules=dirty "..$1" >patch &&
18         may_only_be_test_must_fail "$2" &&
19         $2 git am --3way patch
20 }
21
22 KNOWN_FAILURE_NOFF_MERGE_ATTEMPTS_TO_MERGE_REMOVED_SUBMODULE_FILES=1
23 test_submodule_switch_func "am_3way"
24
25 test_expect_success 'setup diff.submodule' '
26         test_commit one &&
27         INITIAL=$(git rev-parse HEAD) &&
28
29         git init submodule &&
30         (
31                 cd submodule &&
32                 test_commit two &&
33                 git rev-parse HEAD >../initial-submodule
34         ) &&
35         git submodule add ./submodule &&
36         git commit -m first &&
37
38         (
39                 cd submodule &&
40                 test_commit three &&
41                 git rev-parse HEAD >../first-submodule
42         ) &&
43         git add submodule &&
44         git commit -m second &&
45         SECOND=$(git rev-parse HEAD) &&
46
47         (
48                 cd submodule &&
49                 git mv two.t four.t &&
50                 git commit -m "second submodule" &&
51                 git rev-parse HEAD >../second-submodule
52         ) &&
53         test_commit four &&
54         git add submodule &&
55         git commit --amend --no-edit &&
56         THIRD=$(git rev-parse HEAD) &&
57         git submodule update --init
58 '
59
60 run_test() {
61         START_COMMIT=$1 &&
62         EXPECT=$2 &&
63         # Abort any merges in progress: the previous
64         # test may have failed, and we should clean up.
65         test_might_fail git am --abort &&
66         git reset --hard $START_COMMIT &&
67         rm -f *.patch &&
68         git format-patch -1 &&
69         git reset --hard $START_COMMIT^ &&
70         git submodule update &&
71         git am *.patch &&
72         git submodule update &&
73         git -C submodule rev-parse HEAD >actual &&
74         test_cmp $EXPECT actual
75 }
76
77 test_expect_success 'diff.submodule unset' '
78         test_unconfig diff.submodule &&
79         run_test $SECOND first-submodule
80 '
81
82 test_expect_success 'diff.submodule unset with extra file' '
83         test_unconfig diff.submodule &&
84         run_test $THIRD second-submodule
85 '
86
87 test_expect_success 'diff.submodule=log' '
88         test_config diff.submodule log &&
89         run_test $SECOND first-submodule
90 '
91
92 test_expect_success 'diff.submodule=log with extra file' '
93         test_config diff.submodule log &&
94         run_test $THIRD second-submodule
95 '
96
97 test_done