Commit a1683f28ce2709e615490939e4e244046654d0e5

Russell Belfer 2013-06-14T16:18:04

More tests and bug fixes for status with rename This changes the behavior of the status RENAMED flags so that they will be combined with the MODIFIED flags if appropriate. If a file is modified in the index and also renamed, then the status code will have both the GIT_STATUS_INDEX_MODIFIED and INDEX_RENAMED bits set. If it is renamed but the OID has not changed, then just the GIT_STATUS_INDEX_RENAMED bit will be set. Similarly, the flags GIT_STATUS_WT_MODIFIED and GIT_STATUS_WT_RENAMED can both be set independently of one another. This fixes a serious bug where the check for unmodified files that was done at data load time could end up erasing the RENAMED state of a file that was renamed with no changes. Lastly, this contains a bunch of new tests for status with renames, including tests where the only rename changes are case changes. The expected results of these tests have to vary by whether the platform uses a case sensitive filesystem or not, so the expected data covers those platform differences separately.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
diff --git a/src/diff.h b/src/diff.h
index 1536f79..6ef03ee 100644
--- a/src/diff.h
+++ b/src/diff.h
@@ -95,17 +95,16 @@ extern int git_diff__paired_foreach(
 	int (*cb)(git_diff_delta *i2h, git_diff_delta *w2i, void *payload),
 	void *payload);
 
-int git_diff_find_similar__hashsig_for_file(
+extern int git_diff_find_similar__hashsig_for_file(
 	void **out, const git_diff_file *f, const char *path, void *p);
 
-int git_diff_find_similar__hashsig_for_buf(
+extern int git_diff_find_similar__hashsig_for_buf(
 	void **out, const git_diff_file *f, const char *buf, size_t len, void *p);
 
-void git_diff_find_similar__hashsig_free(void *sig, void *payload);
+extern void git_diff_find_similar__hashsig_free(void *sig, void *payload);
 
-int git_diff_find_similar__calc_similarity(
+extern int git_diff_find_similar__calc_similarity(
 	int *score, void *siga, void *sigb, void *payload);
 
-
 #endif
 
diff --git a/src/diff_patch.c b/src/diff_patch.c
index a1e1fe8..40cb337 100644
--- a/src/diff_patch.c
+++ b/src/diff_patch.c
@@ -175,10 +175,11 @@ static int diff_patch_load(git_diff_patch *patch, git_diff_output *output)
 			goto cleanup;
 	}
 
-	/* if we were previously missing an oid, reassess UNMODIFIED state */
+	/* if we were previously missing an oid, update MODIFIED->UNMODIFIED */
 	if (incomplete_data &&
 		patch->ofile.file.mode == patch->nfile.file.mode &&
-		git_oid_equal(&patch->ofile.file.oid, &patch->nfile.file.oid))
+		git_oid_equal(&patch->ofile.file.oid, &patch->nfile.file.oid) &&
+		patch->delta->status == GIT_DELTA_MODIFIED) /* not RENAMED/COPIED! */
 		patch->delta->status = GIT_DELTA_UNMODIFIED;
 
 cleanup:
@@ -284,6 +285,7 @@ int git_diff_foreach(
 	git_xdiff_init(&xo, &diff->opts);
 
 	git_vector_foreach(&diff->deltas, idx, patch.delta) {
+
 		/* check flags against patch status */
 		if (git_diff_delta__should_skip(&diff->opts, patch.delta))
 			continue;
diff --git a/src/diff_print.c b/src/diff_print.c
index 244aa6e..6fc7425 100644
--- a/src/diff_print.c
+++ b/src/diff_print.c
@@ -41,7 +41,7 @@ static int diff_print_info_init(
 	return 0;
 }
 
-static char pick_suffix(int mode)
+static char diff_pick_suffix(int mode)
 {
 	if (S_ISDIR(mode))
 		return '/';
@@ -76,10 +76,11 @@ static int callback_error(void)
 	return GIT_EUSER;
 }
 
-static int print_compact(
+static int diff_print_one_compact(
 	const git_diff_delta *delta, float progress, void *data)
 {
 	diff_print_info *pi = data;
+	git_buf *out = pi->buf;
 	char old_suffix, new_suffix, code = git_diff_status_char(delta->status);
 
 	GIT_UNUSED(progress);
@@ -87,34 +88,35 @@ static int print_compact(
 	if (code == ' ')
 		return 0;
 
-	old_suffix = pick_suffix(delta->old_file.mode);
-	new_suffix = pick_suffix(delta->new_file.mode);
+	old_suffix = diff_pick_suffix(delta->old_file.mode);
+	new_suffix = diff_pick_suffix(delta->new_file.mode);
 
-	git_buf_clear(pi->buf);
+	git_buf_clear(out);
 
 	if (delta->old_file.path != delta->new_file.path &&
 		pi->diff->strcomp(delta->old_file.path,delta->new_file.path) != 0)
-		git_buf_printf(pi->buf, "%c\t%s%c -> %s%c\n", code,
+		git_buf_printf(out, "%c\t%s%c -> %s%c\n", code,
 			delta->old_file.path, old_suffix, delta->new_file.path, new_suffix);
 	else if (delta->old_file.mode != delta->new_file.mode &&
 		delta->old_file.mode != 0 && delta->new_file.mode != 0)
-		git_buf_printf(pi->buf, "%c\t%s%c (%o -> %o)\n", code,
+		git_buf_printf(out, "%c\t%s%c (%o -> %o)\n", code,
 			delta->old_file.path, new_suffix, delta->old_file.mode, delta->new_file.mode);
 	else if (old_suffix != ' ')
-		git_buf_printf(pi->buf, "%c\t%s%c\n", code, delta->old_file.path, old_suffix);
+		git_buf_printf(out, "%c\t%s%c\n", code, delta->old_file.path, old_suffix);
 	else
-		git_buf_printf(pi->buf, "%c\t%s\n", code, delta->old_file.path);
+		git_buf_printf(out, "%c\t%s\n", code, delta->old_file.path);
 
-	if (git_buf_oom(pi->buf))
+	if (git_buf_oom(out))
 		return -1;
 
 	if (pi->print_cb(delta, NULL, GIT_DIFF_LINE_FILE_HDR,
-			git_buf_cstr(pi->buf), git_buf_len(pi->buf), pi->payload))
+			git_buf_cstr(out), git_buf_len(out), pi->payload))
 		return callback_error();
 
 	return 0;
 }
 
+/* print a git_diff_list to a print callback in compact format */
 int git_diff_print_compact(
 	git_diff_list *diff,
 	git_diff_data_cb print_cb,
@@ -125,17 +127,18 @@ int git_diff_print_compact(
 	diff_print_info pi;
 
 	if (!(error = diff_print_info_init(&pi, &buf, diff, print_cb, payload)))
-		error = git_diff_foreach(diff, print_compact, NULL, NULL, &pi);
+		error = git_diff_foreach(diff, diff_print_one_compact, NULL, NULL, &pi);
 
 	git_buf_free(&buf);
 
 	return error;
 }
 
-static int print_raw(
+static int diff_print_one_raw(
 	const git_diff_delta *delta, float progress, void *data)
 {
 	diff_print_info *pi = data;
+	git_buf *out = pi->buf;
 	char code = git_diff_status_char(delta->status);
 	char start_oid[GIT_OID_HEXSZ+1], end_oid[GIT_OID_HEXSZ+1];
 
@@ -144,36 +147,37 @@ static int print_raw(
 	if (code == ' ')
 		return 0;
 
-	git_buf_clear(pi->buf);
+	git_buf_clear(out);
 
 	git_oid_tostr(start_oid, pi->oid_strlen, &delta->old_file.oid);
 	git_oid_tostr(end_oid, pi->oid_strlen, &delta->new_file.oid);
 
 	git_buf_printf(
-		pi->buf, ":%06o %06o %s... %s... %c",
+		out, ":%06o %06o %s... %s... %c",
 		delta->old_file.mode, delta->new_file.mode, start_oid, end_oid, code);
 
 	if (delta->similarity > 0)
-		git_buf_printf(pi->buf, "%03u", delta->similarity);
+		git_buf_printf(out, "%03u", delta->similarity);
 
 	if (delta->status == GIT_DELTA_RENAMED || delta->status == GIT_DELTA_COPIED)
 		git_buf_printf(
-			pi->buf, "\t%s %s\n", delta->old_file.path, delta->new_file.path);
+			out, "\t%s %s\n", delta->old_file.path, delta->new_file.path);
 	else
 		git_buf_printf(
-			pi->buf, "\t%s\n", delta->old_file.path ?
+			out, "\t%s\n", delta->old_file.path ?
 			delta->old_file.path : delta->new_file.path);
 
-	if (git_buf_oom(pi->buf))
+	if (git_buf_oom(out))
 		return -1;
 
 	if (pi->print_cb(delta, NULL, GIT_DIFF_LINE_FILE_HDR,
-			git_buf_cstr(pi->buf), git_buf_len(pi->buf), pi->payload))
+			git_buf_cstr(out), git_buf_len(out), pi->payload))
 		return callback_error();
 
 	return 0;
 }
 
+/* print a git_diff_list to a print callback in raw output format */
 int git_diff_print_raw(
 	git_diff_list *diff,
 	git_diff_data_cb print_cb,
@@ -184,15 +188,16 @@ int git_diff_print_raw(
 	diff_print_info pi;
 
 	if (!(error = diff_print_info_init(&pi, &buf, diff, print_cb, payload)))
-		error = git_diff_foreach(diff, print_raw, NULL, NULL, &pi);
+		error = git_diff_foreach(diff, diff_print_one_raw, NULL, NULL, &pi);
 
 	git_buf_free(&buf);
 
 	return error;
 }
 
-static int print_oid_range(diff_print_info *pi, const git_diff_delta *delta)
+static int diff_print_oid_range(diff_print_info *pi, const git_diff_delta *delta)
 {
+	git_buf *out = pi->buf;
 	char start_oid[GIT_OID_HEXSZ+1], end_oid[GIT_OID_HEXSZ+1];
 
 	git_oid_tostr(start_oid, pi->oid_strlen, &delta->old_file.oid);
@@ -200,27 +205,27 @@ static int print_oid_range(diff_print_info *pi, const git_diff_delta *delta)
 
 	/* TODO: Match git diff more closely */
 	if (delta->old_file.mode == delta->new_file.mode) {
-		git_buf_printf(pi->buf, "index %s..%s %o\n",
+		git_buf_printf(out, "index %s..%s %o\n",
 			start_oid, end_oid, delta->old_file.mode);
 	} else {
 		if (delta->old_file.mode == 0) {
-			git_buf_printf(pi->buf, "new file mode %o\n", delta->new_file.mode);
+			git_buf_printf(out, "new file mode %o\n", delta->new_file.mode);
 		} else if (delta->new_file.mode == 0) {
-			git_buf_printf(pi->buf, "deleted file mode %o\n", delta->old_file.mode);
+			git_buf_printf(out, "deleted file mode %o\n", delta->old_file.mode);
 		} else {
-			git_buf_printf(pi->buf, "old mode %o\n", delta->old_file.mode);
-			git_buf_printf(pi->buf, "new mode %o\n", delta->new_file.mode);
+			git_buf_printf(out, "old mode %o\n", delta->old_file.mode);
+			git_buf_printf(out, "new mode %o\n", delta->new_file.mode);
 		}
-		git_buf_printf(pi->buf, "index %s..%s\n", start_oid, end_oid);
+		git_buf_printf(out, "index %s..%s\n", start_oid, end_oid);
 	}
 
-	if (git_buf_oom(pi->buf))
+	if (git_buf_oom(out))
 		return -1;
 
 	return 0;
 }
 
-static int print_patch_file(
+static int diff_print_patch_file(
 	const git_diff_delta *delta, float progress, void *data)
 {
 	diff_print_info *pi = data;
@@ -247,7 +252,7 @@ static int print_patch_file(
 	git_buf_clear(pi->buf);
 	git_buf_printf(pi->buf, "diff --git %s%s %s%s\n", oldpfx, delta->old_file.path, newpfx, delta->new_file.path);
 
-	if (print_oid_range(pi, delta) < 0)
+	if (diff_print_oid_range(pi, delta) < 0)
 		return -1;
 
 	if (git_oid_iszero(&delta->old_file.oid)) {
@@ -288,7 +293,7 @@ static int print_patch_file(
 	return 0;
 }
 
-static int print_patch_hunk(
+static int diff_print_patch_hunk(
 	const git_diff_delta *d,
 	const git_diff_range *r,
 	const char *header,
@@ -311,7 +316,7 @@ static int print_patch_hunk(
 	return 0;
 }
 
-static int print_patch_line(
+static int diff_print_patch_line(
 	const git_diff_delta *delta,
 	const git_diff_range *range,
 	char line_origin, /* GIT_DIFF_LINE value from above */
@@ -343,6 +348,7 @@ static int print_patch_line(
 	return 0;
 }
 
+/* print a git_diff_list to an output callback in patch format */
 int git_diff_print_patch(
 	git_diff_list *diff,
 	git_diff_data_cb print_cb,
@@ -354,27 +360,15 @@ int git_diff_print_patch(
 
 	if (!(error = diff_print_info_init(&pi, &buf, diff, print_cb, payload)))
 		error = git_diff_foreach(
-			diff, print_patch_file, print_patch_hunk, print_patch_line, &pi);
+			diff, diff_print_patch_file, diff_print_patch_hunk,
+			diff_print_patch_line, &pi);
 
 	git_buf_free(&buf);
 
 	return error;
 }
 
-
-static int print_to_buffer_cb(
-	const git_diff_delta *delta,
-	const git_diff_range *range,
-	char line_origin,
-	const char *content,
-	size_t content_len,
-	void *payload)
-{
-	git_buf *output = payload;
-	GIT_UNUSED(delta); GIT_UNUSED(range); GIT_UNUSED(line_origin);
-	return git_buf_put(output, content, content_len);
-}
-
+/* print a git_diff_patch to an output callback */
 int git_diff_patch_print(
 	git_diff_patch *patch,
 	git_diff_data_cb print_cb,
@@ -389,13 +383,28 @@ int git_diff_patch_print(
 	if (!(error = diff_print_info_init(
 			&pi, &temp, git_diff_patch__diff(patch), print_cb, payload)))
 		error = git_diff_patch__invoke_callbacks(
-			patch, print_patch_file, print_patch_hunk, print_patch_line, &pi);
+			patch, diff_print_patch_file, diff_print_patch_hunk,
+			diff_print_patch_line, &pi);
 
 	git_buf_free(&temp);
 
 	return error;
 }
 
+static int diff_print_to_buffer_cb(
+	const git_diff_delta *delta,
+	const git_diff_range *range,
+	char line_origin,
+	const char *content,
+	size_t content_len,
+	void *payload)
+{
+	git_buf *output = payload;
+	GIT_UNUSED(delta); GIT_UNUSED(range); GIT_UNUSED(line_origin);
+	return git_buf_put(output, content, content_len);
+}
+
+/* print a git_diff_patch to a string buffer */
 int git_diff_patch_to_str(
 	char **string,
 	git_diff_patch *patch)
@@ -403,7 +412,7 @@ int git_diff_patch_to_str(
 	int error;
 	git_buf output = GIT_BUF_INIT;
 
-	error = git_diff_patch_print(patch, print_to_buffer_cb, &output);
+	error = git_diff_patch_print(patch, diff_print_to_buffer_cb, &output);
 
 	/* GIT_EUSER means git_buf_put in print_to_buffer_cb returned -1,
 	 * meaning a memory allocation failure, so just map to -1...
diff --git a/src/diff_tform.c b/src/diff_tform.c
index 94fa035..64746e7 100644
--- a/src/diff_tform.c
+++ b/src/diff_tform.c
@@ -483,7 +483,7 @@ static int similarity_measure(
 	if (GIT_MODE_TYPE(a_file->mode) != GIT_MODE_TYPE(b_file->mode))
 		return 0;
 
-	/* if exact match is requested, force calculation of missing OIDs */
+	/* if exact match is requested, force calculation of missing OIDs now */
 	if (exact_match) {
 		if (git_oid_iszero(&a_file->oid) &&
 			diff->old_src == GIT_ITERATOR_TYPE_WORKDIR &&
diff --git a/src/status.c b/src/status.c
index 9c4aead..375100a 100644
--- a/src/status.c
+++ b/src/status.c
@@ -20,11 +20,11 @@
 #include "git2/diff.h"
 #include "diff.h"
 
-static unsigned int index_delta2status(git_delta_t index_status)
+static unsigned int index_delta2status(const git_diff_delta *head2idx)
 {
-	unsigned int st = GIT_STATUS_CURRENT;
+	git_status_t st = GIT_STATUS_CURRENT;
 
-	switch (index_status) {
+	switch (head2idx->status) {
 	case GIT_DELTA_ADDED:
 	case GIT_DELTA_COPIED:
 		st = GIT_STATUS_INDEX_NEW;
@@ -37,6 +37,9 @@ static unsigned int index_delta2status(git_delta_t index_status)
 		break;
 	case GIT_DELTA_RENAMED:
 		st = GIT_STATUS_INDEX_RENAMED;
+
+		if (!git_oid_equal(&head2idx->old_file.oid, &head2idx->new_file.oid))
+			st |= GIT_STATUS_INDEX_MODIFIED;
 		break;
 	case GIT_DELTA_TYPECHANGE:
 		st = GIT_STATUS_INDEX_TYPECHANGE;
@@ -48,11 +51,12 @@ static unsigned int index_delta2status(git_delta_t index_status)
 	return st;
 }
 
-static unsigned int workdir_delta2status(git_delta_t workdir_status)
+static unsigned int workdir_delta2status(
+	git_diff_list *diff, git_diff_delta *idx2wd)
 {
-	unsigned int st = GIT_STATUS_CURRENT;
+	git_status_t st = GIT_STATUS_CURRENT;
 
-	switch (workdir_status) {
+	switch (idx2wd->status) {
 	case GIT_DELTA_ADDED:
 	case GIT_DELTA_COPIED:
 	case GIT_DELTA_UNTRACKED:
@@ -69,6 +73,28 @@ static unsigned int workdir_delta2status(git_delta_t workdir_status)
 		break;
 	case GIT_DELTA_RENAMED:
 		st = GIT_STATUS_WT_RENAMED;
+
+		if (!git_oid_equal(&idx2wd->old_file.oid, &idx2wd->new_file.oid)) {
+			/* if OIDs don't match, we might need to calculate them now to
+			 * discern between RENAMED vs RENAMED+MODIFED
+			 */
+			if (git_oid_iszero(&idx2wd->old_file.oid) &&
+				diff->old_src == GIT_ITERATOR_TYPE_WORKDIR &&
+				!git_diff__oid_for_file(
+					diff->repo, idx2wd->old_file.path, idx2wd->old_file.mode,
+					idx2wd->old_file.size, &idx2wd->old_file.oid))
+			idx2wd->old_file.flags |= GIT_DIFF_FLAG_VALID_OID;
+
+			if (git_oid_iszero(&idx2wd->new_file.oid) &&
+				diff->new_src == GIT_ITERATOR_TYPE_WORKDIR &&
+				!git_diff__oid_for_file(
+					diff->repo, idx2wd->new_file.path, idx2wd->new_file.mode,
+					idx2wd->new_file.size, &idx2wd->new_file.oid))
+				idx2wd->new_file.flags |= GIT_DIFF_FLAG_VALID_OID;
+
+			if (!git_oid_equal(&idx2wd->old_file.oid, &idx2wd->new_file.oid))
+				st |= GIT_STATUS_WT_MODIFIED;
+		}
 		break;
 	case GIT_DELTA_TYPECHANGE:
 		st = GIT_STATUS_WT_TYPECHANGE;
@@ -111,18 +137,19 @@ static bool status_is_included(
 }
 
 static git_status_t status_compute(
+	git_status_list *status,
 	git_diff_delta *head2idx,
 	git_diff_delta *idx2wd)
 {
-	git_status_t status = 0;
+	git_status_t st = GIT_STATUS_CURRENT;
 
 	if (head2idx)
-		status |= index_delta2status(head2idx->status);
+		st |= index_delta2status(head2idx);
 
 	if (idx2wd)
-		status |= workdir_delta2status(idx2wd->status);
+		st |= workdir_delta2status(status->idx2wd, idx2wd);
 
-	return status;
+	return st;
 }
 
 static int status_collect(
@@ -139,7 +166,7 @@ static int status_collect(
 	status_entry = git__malloc(sizeof(git_status_entry));
 	GITERR_CHECK_ALLOC(status_entry);
 
-	status_entry->status = status_compute(head2idx, idx2wd);
+	status_entry->status = status_compute(status, head2idx, idx2wd);
 	status_entry->head_to_index = head2idx;
 	status_entry->index_to_workdir = idx2wd;
 
diff --git a/tests-clar/status/renames.c b/tests-clar/status/renames.c
index d29c7bf..80ff260 100644
--- a/tests-clar/status/renames.c
+++ b/tests-clar/status/renames.c
@@ -61,13 +61,13 @@ static void test_status(
 	const char *oldname, *newname;
 	size_t i;
 
-	cl_assert(expected_len == git_status_list_entrycount(status_list));
+	cl_assert_equal_sz(expected_len, git_status_list_entrycount(status_list));
 
 	for (i = 0; i < expected_len; i++) {
 		actual = git_status_byindex(status_list, i);
 		expected = &expected_list[i];
 
-		cl_assert(actual->status == expected->status);
+		cl_assert_equal_i((int)expected->status, (int)actual->status);
 
 		oldname = actual->head_to_index ? actual->head_to_index->old_file.path :
 			actual->index_to_workdir ? actual->index_to_workdir->old_file.path : NULL;
@@ -119,8 +119,10 @@ void test_status_renames__head2index_two(void)
 	git_status_list *statuslist;
 	git_status_options opts = GIT_STATUS_OPTIONS_INIT;
 	struct status_entry expected[] = {
-		{ GIT_STATUS_INDEX_RENAMED, "sixserving.txt", "aaa.txt" },
-		{ GIT_STATUS_INDEX_RENAMED, "untimely.txt", "bbb.txt" },
+		{ GIT_STATUS_INDEX_RENAMED | GIT_STATUS_INDEX_MODIFIED,
+		  "sixserving.txt", "aaa.txt" },
+		{ GIT_STATUS_INDEX_RENAMED | GIT_STATUS_INDEX_MODIFIED,
+		  "untimely.txt", "bbb.txt" },
 		{ GIT_STATUS_INDEX_RENAMED, "songof7cities.txt", "ccc.txt" },
 		{ GIT_STATUS_INDEX_RENAMED, "ikeepsix.txt", "ddd.txt" },
 	};
@@ -174,8 +176,10 @@ void test_status_renames__index2workdir_two(void)
 	git_status_list *statuslist;
 	git_status_options opts = GIT_STATUS_OPTIONS_INIT;
 	struct status_entry expected[] = {
-		{ GIT_STATUS_WT_RENAMED, "sixserving.txt", "aaa.txt" },
-		{ GIT_STATUS_WT_RENAMED, "untimely.txt", "bbb.txt" },
+		{ GIT_STATUS_WT_RENAMED | GIT_STATUS_WT_MODIFIED,
+		  "sixserving.txt", "aaa.txt" },
+		{ GIT_STATUS_WT_RENAMED | GIT_STATUS_WT_MODIFIED,
+		  "untimely.txt", "bbb.txt" },
 		{ GIT_STATUS_WT_RENAMED, "songof7cities.txt", "ccc.txt" },
 		{ GIT_STATUS_WT_RENAMED, "ikeepsix.txt", "ddd.txt" },
 	};
@@ -199,7 +203,8 @@ void test_status_renames__both_one(void)
 	git_status_list *statuslist;
 	git_status_options opts = GIT_STATUS_OPTIONS_INIT;
 	struct status_entry expected[] = {
-		{ GIT_STATUS_INDEX_RENAMED | GIT_STATUS_WT_RENAMED, "ikeepsix.txt", "newname-workdir.txt" },
+		{ GIT_STATUS_INDEX_RENAMED | GIT_STATUS_WT_RENAMED,
+		  "ikeepsix.txt", "newname-workdir.txt" },
 	};
 
 	opts.flags |= GIT_STATUS_OPT_INCLUDE_UNTRACKED;
@@ -229,10 +234,15 @@ void test_status_renames__both_two(void)
 	git_status_list *statuslist;
 	git_status_options opts = GIT_STATUS_OPTIONS_INIT;
 	struct status_entry expected[] = {
-		{ GIT_STATUS_INDEX_RENAMED | GIT_STATUS_WT_RENAMED, "ikeepsix.txt", "ikeepsix-both.txt" },
-		{ GIT_STATUS_INDEX_RENAMED, "sixserving.txt", "sixserving-index.txt" },
-		{ GIT_STATUS_WT_RENAMED, "songof7cities.txt", "songof7cities-workdir.txt" },
-		{ GIT_STATUS_INDEX_RENAMED | GIT_STATUS_WT_RENAMED, "untimely.txt", "untimely-both.txt" },
+		{ GIT_STATUS_INDEX_RENAMED | GIT_STATUS_INDEX_MODIFIED |
+		  GIT_STATUS_WT_RENAMED | GIT_STATUS_WT_MODIFIED,
+		  "ikeepsix.txt", "ikeepsix-both.txt" },
+		{ GIT_STATUS_INDEX_RENAMED | GIT_STATUS_INDEX_MODIFIED,
+		  "sixserving.txt", "sixserving-index.txt" },
+		{ GIT_STATUS_WT_RENAMED | GIT_STATUS_WT_MODIFIED,
+		  "songof7cities.txt", "songof7cities-workdir.txt" },
+		{ GIT_STATUS_INDEX_RENAMED | GIT_STATUS_WT_RENAMED,
+		  "untimely.txt", "untimely-both.txt" },
 	};
 
 	opts.flags |= GIT_STATUS_OPT_INCLUDE_UNTRACKED;
@@ -263,3 +273,113 @@ void test_status_renames__both_two(void)
 
 	git_index_free(index);
 }
+
+void test_status_renames__both_casechange_one(void)
+{
+	git_index *index;
+	git_status_list *statuslist;
+	git_status_options opts = GIT_STATUS_OPTIONS_INIT;
+	int index_caps;
+	struct status_entry expected_icase[] = {
+		{ GIT_STATUS_INDEX_RENAMED,
+		  "ikeepsix.txt", "IKeepSix.txt" },
+	};
+	struct status_entry expected_case[] = {
+		{ GIT_STATUS_INDEX_RENAMED | GIT_STATUS_WT_RENAMED,
+		  "ikeepsix.txt", "IKEEPSIX.txt" },
+	};
+
+	opts.flags |= GIT_STATUS_OPT_INCLUDE_UNTRACKED;
+	opts.flags |= GIT_STATUS_OPT_RENAMES_HEAD_TO_INDEX;
+	opts.flags |= GIT_STATUS_OPT_RENAMES_INDEX_TO_WORKDIR;
+
+	cl_git_pass(git_repository_index(&index, g_repo));
+	index_caps = git_index_caps(index);
+
+	rename_file(g_repo, "ikeepsix.txt", "IKeepSix.txt");
+
+	cl_git_pass(git_index_remove_bypath(index, "ikeepsix.txt"));
+	cl_git_pass(git_index_add_bypath(index, "IKeepSix.txt"));
+	cl_git_pass(git_index_write(index));
+
+	/* on a case-insensitive file system, this change won't matter.
+	 * on a case-sensitive one, it will.
+	 */
+	rename_file(g_repo, "IKeepSix.txt", "IKEEPSIX.txt");
+
+	cl_git_pass(git_status_list_new(&statuslist, g_repo, &opts));
+
+	test_status(statuslist, (index_caps & GIT_INDEXCAP_IGNORE_CASE) ?
+		expected_icase : expected_case, 1);
+
+	git_status_list_free(statuslist);
+
+	git_index_free(index);
+}
+
+void test_status_renames__both_casechange_two(void)
+{
+	git_index *index;
+	git_status_list *statuslist;
+	git_status_options opts = GIT_STATUS_OPTIONS_INIT;
+	int index_caps;
+	struct status_entry expected_icase[] = {
+		{ GIT_STATUS_INDEX_RENAMED | GIT_STATUS_INDEX_MODIFIED |
+		  GIT_STATUS_WT_MODIFIED,
+		  "ikeepsix.txt", "IKeepSix.txt" },
+		{ GIT_STATUS_INDEX_MODIFIED,
+		  "sixserving.txt", "sixserving.txt" },
+		{ GIT_STATUS_INDEX_RENAMED | GIT_STATUS_WT_MODIFIED,
+		  "songof7cities.txt", "songof7.txt" },
+		{ GIT_STATUS_INDEX_RENAMED | GIT_STATUS_WT_RENAMED,
+		  "untimely.txt", "untimeliest.txt" }
+	};
+	struct status_entry expected_case[] = {
+		{ GIT_STATUS_INDEX_RENAMED | GIT_STATUS_INDEX_MODIFIED |
+		  GIT_STATUS_WT_RENAMED | GIT_STATUS_WT_MODIFIED,
+		  "ikeepsix.txt", "ikeepsix.txt" },
+		{ GIT_STATUS_INDEX_MODIFIED | GIT_STATUS_WT_RENAMED,
+		  "sixserving.txt", "SixServing.txt" },
+		{ GIT_STATUS_INDEX_RENAMED |
+		  GIT_STATUS_WT_MODIFIED | GIT_STATUS_WT_RENAMED,
+		  "songof7cities.txt", "SONGOF7.txt" },
+		{ GIT_STATUS_INDEX_RENAMED | GIT_STATUS_WT_RENAMED,
+		  "untimely.txt", "untimeliest.txt" }
+	};
+
+	opts.flags |= GIT_STATUS_OPT_INCLUDE_UNTRACKED;
+	opts.flags |= GIT_STATUS_OPT_RENAMES_HEAD_TO_INDEX;
+	opts.flags |= GIT_STATUS_OPT_RENAMES_INDEX_TO_WORKDIR;
+
+	cl_git_pass(git_repository_index(&index, g_repo));
+	index_caps = git_index_caps(index);
+
+	rename_and_edit_file(g_repo, "ikeepsix.txt", "IKeepSix.txt");
+	rename_and_edit_file(g_repo, "sixserving.txt", "sixserving.txt");
+	rename_file(g_repo, "songof7cities.txt", "songof7.txt");
+	rename_file(g_repo, "untimely.txt", "untimelier.txt");
+
+	cl_git_pass(git_index_remove_bypath(index, "ikeepsix.txt"));
+	cl_git_pass(git_index_remove_bypath(index, "sixserving.txt"));
+	cl_git_pass(git_index_remove_bypath(index, "songof7cities.txt"));
+	cl_git_pass(git_index_remove_bypath(index, "untimely.txt"));
+	cl_git_pass(git_index_add_bypath(index, "IKeepSix.txt"));
+	cl_git_pass(git_index_add_bypath(index, "sixserving.txt"));
+	cl_git_pass(git_index_add_bypath(index, "songof7.txt"));
+	cl_git_pass(git_index_add_bypath(index, "untimelier.txt"));
+	cl_git_pass(git_index_write(index));
+
+	rename_and_edit_file(g_repo, "IKeepSix.txt", "ikeepsix.txt");
+	rename_file(g_repo, "sixserving.txt", "SixServing.txt");
+	rename_and_edit_file(g_repo, "songof7.txt", "SONGOF7.txt");
+	rename_file(g_repo, "untimelier.txt", "untimeliest.txt");
+
+	cl_git_pass(git_status_list_new(&statuslist, g_repo, &opts));
+
+	test_status(statuslist, (index_caps & GIT_INDEXCAP_IGNORE_CASE) ?
+		expected_icase : expected_case, 4);
+
+	git_status_list_free(statuslist);
+
+	git_index_free(index);
+}