Git fork
1#!/bin/sh
2
3test_description='last-modified tests'
4
5. ./test-lib.sh
6
7test_expect_success 'setup' '
8 test_commit 1 file &&
9 mkdir a &&
10 test_commit 2 a/file &&
11 mkdir a/b &&
12 test_commit 3 a/b/file
13'
14
15test_expect_success 'cannot run last-modified on two trees' '
16 test_must_fail git last-modified HEAD HEAD~1
17'
18
19check_last_modified() {
20 local indir= &&
21 while test $# != 0
22 do
23 case "$1" in
24 -C)
25 indir="$2"
26 shift
27 ;;
28 *)
29 break
30 ;;
31 esac &&
32 shift
33 done &&
34
35 cat >expect &&
36 git ${indir:+-C "$indir"} last-modified "$@" >tmp.1 &&
37 git name-rev --annotate-stdin --name-only --tags \
38 <tmp.1 >tmp.2 &&
39 tr '\t' ' ' <tmp.2 >actual &&
40 test_cmp expect actual
41}
42
43test_expect_success 'last-modified non-recursive' '
44 check_last_modified <<-\EOF
45 3 a
46 1 file
47 EOF
48'
49
50test_expect_success 'last-modified recursive' '
51 check_last_modified -r <<-\EOF
52 3 a/b/file
53 2 a/file
54 1 file
55 EOF
56'
57
58test_expect_success 'last-modified recursive with show-trees' '
59 check_last_modified -r -t <<-\EOF
60 3 a
61 3 a/b
62 3 a/b/file
63 2 a/file
64 1 file
65 EOF
66'
67
68test_expect_success 'last-modified non-recursive with show-trees' '
69 check_last_modified -t <<-\EOF
70 3 a
71 1 file
72 EOF
73'
74
75test_expect_success 'last-modified subdir' '
76 check_last_modified a <<-\EOF
77 3 a
78 EOF
79'
80
81test_expect_success 'last-modified subdir recursive' '
82 check_last_modified -r a <<-\EOF
83 3 a/b/file
84 2 a/file
85 EOF
86'
87
88test_expect_success 'last-modified from non-HEAD commit' '
89 check_last_modified HEAD^ <<-\EOF
90 2 a
91 1 file
92 EOF
93'
94
95test_expect_success 'last-modified from subdir defaults to root' '
96 check_last_modified -C a <<-\EOF
97 3 a
98 1 file
99 EOF
100'
101
102test_expect_success 'last-modified from subdir uses relative pathspecs' '
103 check_last_modified -C a -r b <<-\EOF
104 3 a/b/file
105 EOF
106'
107
108test_expect_success 'limit last-modified traversal by count' '
109 check_last_modified -1 <<-\EOF
110 3 a
111 ^2 file
112 EOF
113'
114
115test_expect_success 'limit last-modified traversal by commit' '
116 check_last_modified HEAD~2..HEAD <<-\EOF
117 3 a
118 ^1 file
119 EOF
120'
121
122test_expect_success 'only last-modified files in the current tree' '
123 git rm -rf a &&
124 git commit -m "remove a" &&
125 check_last_modified <<-\EOF
126 1 file
127 EOF
128'
129
130test_expect_success 'subdirectory modified via merge' '
131 test_when_finished rm -rf repo &&
132 git init repo &&
133 (
134 cd repo &&
135 test_commit base &&
136 git switch --create left &&
137 mkdir subdir &&
138 test_commit left subdir/left &&
139 git switch --create right base &&
140 mkdir subdir &&
141 test_commit right subdir/right &&
142 git switch - &&
143 test_merge merge right &&
144 check_last_modified <<-\EOF
145 merge subdir
146 base base.t
147 EOF
148 )
149'
150
151test_expect_success 'cross merge boundaries in blaming' '
152 git checkout HEAD^0 &&
153 git rm -rf . &&
154 test_commit m1 &&
155 git checkout HEAD^ &&
156 git rm -rf . &&
157 test_commit m2 &&
158 git merge m1 &&
159 check_last_modified <<-\EOF
160 m2 m2.t
161 m1 m1.t
162 EOF
163'
164
165test_expect_success 'last-modified merge for resolved conflicts' '
166 git checkout HEAD^0 &&
167 git rm -rf . &&
168 test_commit c1 conflict &&
169 git checkout HEAD^ &&
170 git rm -rf . &&
171 test_commit c2 conflict &&
172 test_must_fail git merge c1 &&
173 test_commit resolved conflict &&
174 check_last_modified conflict <<-\EOF
175 resolved conflict
176 EOF
177'
178
179
180# Consider `file` with this content through history:
181#
182# A---B---B-------B---B
183# \ /
184# C---D
185test_expect_success 'last-modified merge ignores content from branch' '
186 git checkout HEAD^0 &&
187 git rm -rf . &&
188 test_commit a1 file A &&
189 test_commit a2 file B &&
190 test_commit a3 file C &&
191 test_commit a4 file D &&
192 git checkout a2 &&
193 git merge --no-commit --no-ff a4 &&
194 git checkout a2 -- file &&
195 git merge --continue &&
196 check_last_modified <<-\EOF
197 a2 file
198 EOF
199'
200
201# Consider `file` with this content through history:
202#
203# A---B---B---C---D---B---B
204# \ /
205# B-------B
206test_expect_success 'last-modified merge undoes changes' '
207 git checkout HEAD^0 &&
208 git rm -rf . &&
209 test_commit b1 file A &&
210 test_commit b2 file B &&
211 test_commit b3 file C &&
212 test_commit b4 file D &&
213 git checkout b2 &&
214 test_commit b5 file2 2 &&
215 git checkout b4 &&
216 git merge --no-commit --no-ff b5 &&
217 git checkout b2 -- file &&
218 git merge --continue &&
219 check_last_modified <<-\EOF
220 b5 file2
221 b2 file
222 EOF
223'
224
225test_expect_success 'last-modified complains about unknown arguments' '
226 test_must_fail git last-modified --foo 2>err &&
227 grep "unknown last-modified argument: --foo" err
228'
229
230test_done