Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/t/t8020-last-modified.sh # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / t / t8020-last-modified.sh` 287 lines ยท 5639 bytes Raw Blame History 1 #!/bin/sh 2 3 test_description='last-modified tests' 4 5 . ./test-lib.sh 6 7 test_expect_success 'setup' ' 8 test_commit 1 file && 9 mkdir a && 10 test_commit 2 a/file && 11 git tag -mA t2 2 && 12 mkdir a/b && 13 test_commit 3 a/b/file 14 ' 15 16 check_last_modified() { 17 local indir= && 18 while test $# != 0 19 do 20 case "$1" in 21 -C) 22 indir="$2" 23 shift 24 ;; 25 *) 26 break 27 ;; 28 esac && 29 shift 30 done && 31 32 cat >expect && 33 git ${indir:+-C "$indir"} last-modified "$@" >tmp.1 && 34 git name-rev --annotate-stdin --name-only --tags --exclude=t2 \ 35 tmp.2 && 36 tr '\t' ' ' actual && 37 test_cmp expect actual 38 } 39 40 test_expect_success 'last-modified non-recursive' ' 41 check_last_modified <<-\EOF 42 3 a 43 1 file 44 EOF 45 ' 46 47 test_expect_success 'last-modified recursive' ' 48 check_last_modified -r <<-\EOF 49 3 a/b/file 50 2 a/file 51 1 file 52 EOF 53 ' 54 55 test_expect_success 'last-modified on annotated tag' ' 56 check_last_modified t2 <<-\EOF 57 2 a 58 1 file 59 EOF 60 ' 61 62 test_expect_success 'last-modified recursive with show-trees' ' 63 check_last_modified -r -t <<-\EOF 64 3 a/b 65 3 a/b/file 66 3 a 67 2 a/file 68 1 file 69 EOF 70 ' 71 72 test_expect_success 'last-modified non-recursive with show-trees' ' 73 check_last_modified -t <<-\EOF 74 3 a 75 1 file 76 EOF 77 ' 78 79 test_expect_success 'last-modified subdir' ' 80 check_last_modified a <<-\EOF 81 3 a 82 EOF 83 ' 84 85 test_expect_success 'last-modified in sparse checkout' ' 86 test_when_finished "git sparse-checkout disable" && 87 git sparse-checkout set b && 88 check_last_modified -- a <<-\EOF 89 3 a 90 EOF 91 ' 92 93 test_expect_success 'last-modified subdir recursive' ' 94 check_last_modified -r a <<-\EOF 95 3 a/b/file 96 2 a/file 97 EOF 98 ' 99 100 test_expect_success 'last-modified subdir non-recursive' ' 101 check_last_modified a <<-\EOF 102 3 a 103 EOF 104 ' 105 106 test_expect_success 'last-modified path in subdir non-recursive' ' 107 check_last_modified a/file <<-\EOF 108 2 a/file 109 EOF 110 ' 111 112 test_expect_success 'last-modified subdir with wildcard non-recursive' ' 113 check_last_modified a/* <<-\EOF 114 3 a/b 115 2 a/file 116 EOF 117 ' 118 119 test_expect_success 'last-modified with negative max-depth' ' 120 check_last_modified --max-depth=-1 <<-\EOF 121 3 a/b/file 122 2 a/file 123 1 file 124 EOF 125 ' 126 127 test_expect_success 'last-modified with max-depth of 1' ' 128 check_last_modified --max-depth=1 <<-\EOF 129 3 a/b 130 2 a/file 131 1 file 132 EOF 133 ' 134 135 test_expect_success 'last-modified from non-HEAD commit' ' 136 check_last_modified HEAD^ <<-\EOF 137 2 a 138 1 file 139 EOF 140 ' 141 142 test_expect_success 'last-modified from subdir defaults to root' ' 143 check_last_modified -C a <<-\EOF 144 3 a 145 1 file 146 EOF 147 ' 148 149 test_expect_success 'last-modified from subdir uses relative pathspecs' ' 150 check_last_modified -C a -r b <<-\EOF 151 3 a/b/file 152 EOF 153 ' 154 155 test_expect_success 'limit last-modified traversal by count' ' 156 check_last_modified -1 <<-\EOF 157 3 a 158 ^2 file 159 EOF 160 ' 161 162 test_expect_success 'limit last-modified traversal by commit' ' 163 check_last_modified HEAD~2..HEAD <<-\EOF 164 3 a 165 ^1 file 166 EOF 167 ' 168 169 test_expect_success 'only last-modified files in the current tree' ' 170 git rm -rf a && 171 git commit -m "remove a" && 172 check_last_modified <<-\EOF 173 1 file 174 EOF 175 ' 176 177 test_expect_success 'subdirectory modified via merge' ' 178 test_when_finished rm -rf repo && 179 git init repo && 180 ( 181 cd repo && 182 test_commit base && 183 git switch --create left && 184 mkdir subdir && 185 test_commit left subdir/left && 186 git switch --create right base && 187 mkdir subdir && 188 test_commit right subdir/right && 189 git switch - && 190 test_merge merge right && 191 check_last_modified <<-\EOF 192 merge subdir 193 base base.t 194 EOF 195 ) 196 ' 197 198 test_expect_success 'cross merge boundaries in blaming' ' 199 git checkout HEAD^0 && 200 git rm -rf . && 201 test_commit m1 && 202 git checkout HEAD^ && 203 git rm -rf . && 204 test_commit m2 && 205 git merge m1 && 206 check_last_modified <<-\EOF 207 m2 m2.t 208 m1 m1.t 209 EOF 210 ' 211 212 test_expect_success 'last-modified merge for resolved conflicts' ' 213 git checkout HEAD^0 && 214 git rm -rf . && 215 test_commit c1 conflict && 216 git checkout HEAD^ && 217 git rm -rf . && 218 test_commit c2 conflict && 219 test_must_fail git merge c1 && 220 test_commit resolved conflict && 221 check_last_modified conflict <<-\EOF 222 resolved conflict 223 EOF 224 ' 225 226 227 # Consider `file` with this content through history: 228 # 229 # A---B---B-------B---B 230 # \ / 231 # C---D 232 test_expect_success 'last-modified merge ignores content from branch' ' 233 git checkout HEAD^0 && 234 git rm -rf . && 235 test_commit a1 file A && 236 test_commit a2 file B && 237 test_commit a3 file C && 238 test_commit a4 file D && 239 git checkout a2 && 240 git merge --no-commit --no-ff a4 && 241 git checkout a2 -- file && 242 git merge --continue && 243 check_last_modified <<-\EOF 244 a2 file 245 EOF 246 ' 247 248 # Consider `file` with this content through history: 249 # 250 # A---B---B---C---D---B---B 251 # \ / 252 # B-------B 253 test_expect_success 'last-modified merge undoes changes' ' 254 git checkout HEAD^0 && 255 git rm -rf . && 256 test_commit b1 file A && 257 test_commit b2 file B && 258 test_commit b3 file C && 259 test_commit b4 file D && 260 git checkout b2 && 261 test_commit b5 file2 2 && 262 git checkout b4 && 263 git merge --no-commit --no-ff b5 && 264 git checkout b2 -- file && 265 git merge --continue && 266 check_last_modified <<-\EOF 267 b5 file2 268 b2 file 269 EOF 270 ' 271 272 test_expect_success 'cannot run last-modified on two commits' ' 273 test_must_fail git last-modified HEAD HEAD~1 2>err && 274 test_grep "last-modified can only operate on one commit at a time" err 275 ' 276 277 test_expect_success 'last-modified complains about unknown arguments' ' 278 test_must_fail git last-modified --foo 2>err && 279 test_grep "unknown last-modified argument: --foo" err 280 ' 281 282 test_expect_success 'last-modified expects commit-ish' ' 283 test_must_fail git last-modified HEAD^{tree} 2>err && 284 test_grep "revision argument ${SQ}HEAD^{tree}${SQ} is a tree, not a commit-ish" err 285 ' 286 287 test_done