| 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 | test_submodule_switch_func "am_3way" |
| 23 | |
| 24 | test_expect_success 'setup diff.submodule' ' |
| 25 | test_commit one && |
| 26 | INITIAL=$(git rev-parse HEAD) && |
| 27 | |
| 28 | git init submodule && |
| 29 | ( |
| 30 | cd submodule && |
| 31 | test_commit two && |
| 32 | git rev-parse HEAD >../initial-submodule |
| 33 | ) && |
| 34 | git submodule add ./submodule && |
| 35 | git commit -m first && |
| 36 | |
| 37 | ( |
| 38 | cd submodule && |
| 39 | test_commit three && |
| 40 | git rev-parse HEAD >../first-submodule |
| 41 | ) && |
| 42 | git add submodule && |
| 43 | git commit -m second && |
| 44 | SECOND=$(git rev-parse HEAD) && |
| 45 | |
| 46 | ( |
| 47 | cd submodule && |
| 48 | git mv two.t four.t && |
| 49 | git commit -m "second submodule" && |
| 50 | git rev-parse HEAD >../second-submodule |
| 51 | ) && |
| 52 | test_commit four && |
| 53 | git add submodule && |
| 54 | git commit --amend --no-edit && |
| 55 | THIRD=$(git rev-parse HEAD) && |
| 56 | git submodule update --init |
| 57 | ' |
| 58 | |
| 59 | run_test() { |
| 60 | START_COMMIT=$1 && |
| 61 | EXPECT=$2 && |
| 62 | # Abort any merges in progress: the previous |
| 63 | # test may have failed, and we should clean up. |
| 64 | test_might_fail git am --abort && |
| 65 | git reset --hard $START_COMMIT && |
| 66 | rm -f *.patch && |
| 67 | git format-patch -1 && |
| 68 | git reset --hard $START_COMMIT^ && |
| 69 | git submodule update && |
| 70 | git am *.patch && |
| 71 | git submodule update && |
| 72 | git -C submodule rev-parse HEAD >actual && |
| 73 | test_cmp $EXPECT actual |
| 74 | } |
| 75 | |
| 76 | test_expect_success 'diff.submodule unset' ' |
| 77 | test_unconfig diff.submodule && |
| 78 | run_test $SECOND first-submodule |
| 79 | ' |
| 80 | |
| 81 | test_expect_success 'diff.submodule unset with extra file' ' |
| 82 | test_unconfig diff.submodule && |
| 83 | run_test $THIRD second-submodule |
| 84 | ' |
| 85 | |
| 86 | test_expect_success 'diff.submodule=log' ' |
| 87 | test_config diff.submodule log && |
| 88 | run_test $SECOND first-submodule |
| 89 | ' |
| 90 | |
| 91 | test_expect_success 'diff.submodule=log with extra file' ' |
| 92 | test_config diff.submodule log && |
| 93 | run_test $THIRD second-submodule |
| 94 | ' |
| 95 | |
| 96 | test_done |