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