Git fork
at reftables-rust 183 lines 5.4 kB view raw
1#!/bin/sh 2 3test_description='Test submodule absorbgitdirs 4 5This test verifies that `git submodue absorbgitdirs` moves a submodules git 6directory into the superproject. 7' 8 9. ./test-lib.sh 10 11test_expect_success 'setup a real submodule' ' 12 cwd="$(pwd)" && 13 git init sub1 && 14 test_commit -C sub1 first && 15 git submodule add ./sub1 && 16 test_tick && 17 git commit -m superproject 18' 19 20test_expect_success 'absorb the git dir' ' 21 >expect && 22 >actual && 23 >expect.1 && 24 >expect.2 && 25 >actual.1 && 26 >actual.2 && 27 git status >expect.1 && 28 git -C sub1 rev-parse HEAD >expect.2 && 29 cat >expect <<-EOF && 30 Migrating git directory of '\''sub1'\'' from 31 '\''$cwd/sub1/.git'\'' to 32 '\''$cwd/.git/modules/sub1'\'' 33 EOF 34 git submodule absorbgitdirs 2>actual && 35 test_cmp expect actual && 36 git fsck && 37 test -f sub1/.git && 38 test -d .git/modules/sub1 && 39 git status >actual.1 && 40 git -C sub1 rev-parse HEAD >actual.2 && 41 test_cmp expect.1 actual.1 && 42 test_cmp expect.2 actual.2 43' 44 45test_expect_success 'absorbing does not fail for deinitialized submodules' ' 46 test_when_finished "git submodule update --init" && 47 git submodule deinit --all && 48 git submodule absorbgitdirs 2>err && 49 test_must_be_empty err && 50 test -d .git/modules/sub1 && 51 test -d sub1 && 52 ! test -e sub1/.git 53' 54 55test_expect_success 'setup nested submodule' ' 56 git init sub1/nested && 57 test_commit -C sub1/nested first_nested && 58 git -C sub1 submodule add ./nested && 59 test_tick && 60 git -C sub1 commit -m "add nested" && 61 git add sub1 && 62 git commit -m "sub1 to include nested submodule" 63' 64 65test_expect_success 'absorb the git dir in a nested submodule' ' 66 git status >expect.1 && 67 git -C sub1/nested rev-parse HEAD >expect.2 && 68 cat >expect <<-EOF && 69 Migrating git directory of '\''sub1/nested'\'' from 70 '\''$cwd/sub1/nested/.git'\'' to 71 '\''$cwd/.git/modules/sub1/modules/nested'\'' 72 EOF 73 git submodule absorbgitdirs 2>actual && 74 test_cmp expect actual && 75 test -f sub1/nested/.git && 76 test -d .git/modules/sub1/modules/nested && 77 git status >actual.1 && 78 git -C sub1/nested rev-parse HEAD >actual.2 && 79 test_cmp expect.1 actual.1 && 80 test_cmp expect.2 actual.2 81' 82 83test_expect_success 're-setup nested submodule' ' 84 # un-absorb the direct submodule, to test if the nested submodule 85 # is still correct (needs a rewrite of the gitfile only) 86 rm -rf sub1/.git && 87 mv .git/modules/sub1 sub1/.git && 88 GIT_WORK_TREE=. git -C sub1 config --unset core.worktree && 89 # fixup the nested submodule 90 echo "gitdir: ../.git/modules/nested" >sub1/nested/.git && 91 GIT_WORK_TREE=../../../nested git -C sub1/.git/modules/nested config \ 92 core.worktree "../../../nested" && 93 # make sure this re-setup is correct 94 git status --ignore-submodules=none && 95 96 # also make sure this old setup does not regress 97 git submodule update --init --recursive >out 2>err && 98 test_must_be_empty out && 99 test_must_be_empty err 100' 101 102test_expect_success 'absorb the git dir in a nested submodule' ' 103 git status >expect.1 && 104 git -C sub1/nested rev-parse HEAD >expect.2 && 105 cat >expect <<-EOF && 106 Migrating git directory of '\''sub1'\'' from 107 '\''$cwd/sub1/.git'\'' to 108 '\''$cwd/.git/modules/sub1'\'' 109 EOF 110 git submodule absorbgitdirs 2>actual && 111 test_cmp expect actual && 112 test -f sub1/.git && 113 test -f sub1/nested/.git && 114 test -d .git/modules/sub1/modules/nested && 115 git status >actual.1 && 116 git -C sub1/nested rev-parse HEAD >actual.2 && 117 test_cmp expect.1 actual.1 && 118 test_cmp expect.2 actual.2 119' 120 121test_expect_success 'absorb the git dir outside of primary worktree' ' 122 test_when_finished "rm -rf repo-bare.git" && 123 git clone --bare . repo-bare.git && 124 test_when_finished "rm -rf repo-wt" && 125 git -C repo-bare.git worktree add ../repo-wt && 126 127 test_when_finished "rm -f .gitconfig" && 128 test_config_global protocol.file.allow always && 129 git -C repo-wt submodule update --init && 130 git init repo-wt/sub2 && 131 test_commit -C repo-wt/sub2 A && 132 git -C repo-wt submodule add ./sub2 sub2 && 133 cat >expect <<-EOF && 134 Migrating git directory of '\''sub2'\'' from 135 '\''$cwd/repo-wt/sub2/.git'\'' to 136 '\''$cwd/repo-bare.git/worktrees/repo-wt/modules/sub2'\'' 137 EOF 138 git -C repo-wt submodule absorbgitdirs 2>actual && 139 test_cmp expect actual 140' 141 142test_expect_success 'setup a gitlink with missing .gitmodules entry' ' 143 git init sub2 && 144 test_commit -C sub2 first && 145 git add sub2 && 146 git commit -m superproject 147' 148 149test_expect_success 'absorbing the git dir fails for incomplete submodules' ' 150 git status >expect.1 && 151 git -C sub2 rev-parse HEAD >expect.2 && 152 cat >expect <<-\EOF && 153 fatal: could not lookup name for submodule '\''sub2'\'' 154 EOF 155 test_must_fail git submodule absorbgitdirs 2>actual && 156 test_cmp expect actual && 157 git -C sub2 fsck && 158 test -d sub2/.git && 159 git status >actual && 160 git -C sub2 rev-parse HEAD >actual.2 && 161 test_cmp expect.1 actual.1 && 162 test_cmp expect.2 actual.2 163' 164 165test_expect_success 'setup a submodule with multiple worktrees' ' 166 # first create another unembedded git dir in a new submodule 167 git init sub3 && 168 test_commit -C sub3 first && 169 git submodule add ./sub3 && 170 test_tick && 171 git commit -m "add another submodule" && 172 git -C sub3 worktree add ../sub3_second_work_tree 173' 174 175test_expect_success 'absorbing fails for a submodule with multiple worktrees' ' 176 cat >expect <<-\EOF && 177 fatal: could not lookup name for submodule '\''sub2'\'' 178 EOF 179 test_must_fail git submodule absorbgitdirs 2>actual && 180 test_cmp expect actual 181' 182 183test_done