Git fork
at reftables-rust 254 lines 6.2 kB view raw
1#!/bin/sh 2 3test_description='basic work tree status reporting' 4 5GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main 6export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 7 8. ./test-lib.sh 9 10test_expect_success setup ' 11 git config --global advice.statusuoption false && 12 test_commit A && 13 test_commit B oneside added && 14 git checkout A^0 && 15 test_commit C oneside created 16' 17 18test_expect_success 'A/A conflict' ' 19 git checkout B^0 && 20 test_must_fail git merge C 21' 22 23test_expect_success 'Report path with conflict' ' 24 git diff --cached --name-status >actual && 25 echo "U oneside" >expect && 26 test_cmp expect actual 27' 28 29test_expect_success 'Report new path with conflict' ' 30 git diff --cached --name-status HEAD^ >actual && 31 echo "U oneside" >expect && 32 test_cmp expect actual 33' 34 35test_expect_success 'M/D conflict does not segfault' ' 36 cat >expect <<EOF && 37On branch side 38You have unmerged paths. 39 (fix conflicts and run "git commit") 40 (use "git merge --abort" to abort the merge) 41 42Unmerged paths: 43 (use "git add/rm <file>..." as appropriate to mark resolution) 44 deleted by us: foo 45 46no changes added to commit (use "git add" and/or "git commit -a") 47EOF 48 mkdir mdconflict && 49 ( 50 cd mdconflict && 51 git init && 52 test_commit initial foo "" && 53 test_commit modify foo foo && 54 git checkout -b side HEAD^ && 55 git rm foo && 56 git commit -m delete && 57 test_must_fail git merge main && 58 test_must_fail git commit --dry-run >../actual && 59 test_cmp ../expect ../actual && 60 git status >../actual && 61 test_cmp ../expect ../actual 62 ) 63' 64 65test_expect_success 'rename & unmerged setup' ' 66 git rm -f -r . && 67 cat "$TEST_DIRECTORY/README" >ONE && 68 git add ONE && 69 test_tick && 70 git commit -m "One commit with ONE" && 71 72 echo Modified >TWO && 73 cat ONE >>TWO && 74 cat ONE >>THREE && 75 git add TWO THREE && 76 sha1=$(git rev-parse :ONE) && 77 git rm --cached ONE && 78 ( 79 echo "100644 $sha1 1 ONE" && 80 echo "100644 $sha1 2 ONE" && 81 echo "100644 $sha1 3 ONE" 82 ) | git update-index --index-info && 83 echo Further >>THREE 84' 85 86test_expect_success 'rename & unmerged status' ' 87 git status -suno >actual && 88 cat >expect <<-EOF && 89 UU ONE 90 AM THREE 91 A TWO 92 EOF 93 test_cmp expect actual 94' 95 96test_expect_success 'git diff-index --cached shows 2 added + 1 unmerged' ' 97 cat >expected <<-EOF && 98 U ONE 99 A THREE 100 A TWO 101 EOF 102 git diff-index --cached --name-status HEAD >actual && 103 test_cmp expected actual 104' 105 106test_expect_success 'git diff-index --cached -M shows 2 added + 1 unmerged' ' 107 cat >expected <<-EOF && 108 U ONE 109 A THREE 110 A TWO 111 EOF 112 git diff-index --cached -M --name-status HEAD >actual && 113 test_cmp expected actual 114' 115 116test_expect_success 'git diff-index --cached -C shows 2 copies + 1 unmerged' ' 117 cat >expected <<-EOF && 118 U ONE 119 C ONE THREE 120 C ONE TWO 121 EOF 122 git diff-index --cached -C --name-status HEAD | 123 sed "s/^C[0-9]*/C/g" >actual && 124 test_cmp expected actual 125' 126 127 128test_expect_success 'status when conflicts with add and rm advice (deleted by them)' ' 129 git reset --hard && 130 git checkout main && 131 test_commit init main.txt init && 132 git checkout -b second_branch && 133 git rm main.txt && 134 git commit -m "main.txt deleted on second_branch" && 135 test_commit second conflict.txt second && 136 git checkout main && 137 test_commit on_second main.txt on_second && 138 test_commit main conflict.txt main && 139 test_must_fail git merge second_branch && 140 cat >expected <<\EOF && 141On branch main 142You have unmerged paths. 143 (fix conflicts and run "git commit") 144 (use "git merge --abort" to abort the merge) 145 146Unmerged paths: 147 (use "git add/rm <file>..." as appropriate to mark resolution) 148 both added: conflict.txt 149 deleted by them: main.txt 150 151no changes added to commit (use "git add" and/or "git commit -a") 152EOF 153 git status --untracked-files=no >actual && 154 test_cmp expected actual 155' 156 157 158test_expect_success 'prepare for conflicts' ' 159 git reset --hard && 160 git checkout -b conflict && 161 test_commit one main.txt one && 162 git branch conflict_second && 163 git mv main.txt sub_main.txt && 164 git commit -m "main.txt renamed in sub_main.txt" && 165 git checkout conflict_second && 166 git mv main.txt sub_second.txt && 167 git commit -m "main.txt renamed in sub_second.txt" 168' 169 170 171test_expect_success 'status when conflicts with add and rm advice (both deleted)' ' 172 test_must_fail git merge conflict && 173 cat >expected <<\EOF && 174On branch conflict_second 175You have unmerged paths. 176 (fix conflicts and run "git commit") 177 (use "git merge --abort" to abort the merge) 178 179Unmerged paths: 180 (use "git add/rm <file>..." as appropriate to mark resolution) 181 both deleted: main.txt 182 added by them: sub_main.txt 183 added by us: sub_second.txt 184 185no changes added to commit (use "git add" and/or "git commit -a") 186EOF 187 git status --untracked-files=no >actual && 188 test_cmp expected actual 189' 190 191 192test_expect_success 'status when conflicts with only rm advice (both deleted)' ' 193 git reset --hard conflict_second && 194 test_must_fail git merge conflict && 195 git add sub_main.txt && 196 git add sub_second.txt && 197 cat >expected <<\EOF && 198On branch conflict_second 199You have unmerged paths. 200 (fix conflicts and run "git commit") 201 (use "git merge --abort" to abort the merge) 202 203Changes to be committed: 204 new file: sub_main.txt 205 206Unmerged paths: 207 (use "git rm <file>..." to mark resolution) 208 both deleted: main.txt 209 210Untracked files not listed (use -u option to show untracked files) 211EOF 212 git status --untracked-files=no >actual && 213 test_cmp expected actual && 214 git reset --hard && 215 git checkout main 216' 217 218test_expect_success 'status --branch with detached HEAD' ' 219 git reset --hard && 220 git checkout main^0 && 221 git status --branch --porcelain >actual && 222 cat >expected <<-EOF && 223 ## HEAD (no branch) 224 ?? .gitconfig 225 ?? actual 226 ?? expect 227 ?? expected 228 ?? mdconflict/ 229 EOF 230 test_cmp expected actual 231' 232 233## Duplicate the above test and verify --porcelain=v1 arg parsing. 234test_expect_success 'status --porcelain=v1 --branch with detached HEAD' ' 235 git reset --hard && 236 git checkout main^0 && 237 git status --branch --porcelain=v1 >actual && 238 cat >expected <<-EOF && 239 ## HEAD (no branch) 240 ?? .gitconfig 241 ?? actual 242 ?? expect 243 ?? expected 244 ?? mdconflict/ 245 EOF 246 test_cmp expected actual 247' 248 249## Verify parser error on invalid --porcelain argument. 250test_expect_success 'status --porcelain=bogus' ' 251 test_must_fail git status --porcelain=bogus 252' 253 254test_done