diff mbox series

diff-lib: use worktree mode in diffs from i-t-a entries

Message ID 20200810085731.43801-1-ray@ameretat.dev (mailing list archive)
State Superseded
Headers show
Series diff-lib: use worktree mode in diffs from i-t-a entries | expand

Commit Message

Raymond E. Pasco Aug. 10, 2020, 8:57 a.m. UTC
When creating "new file" diffs against i-t-a index entries, diff-lib
erroneously uses the placeholder mode in the cache entry rather than the
mode of the file in the worktree.

Change run_diff_files() to correctly use the mode of the worktree file
in this case, and add a test verifying that diff uses the worktree mode.

Tested-by: Martin Ågren <martin.agren@gmail.com>
Signed-off-by: Raymond E. Pasco <ray@ameretat.dev>
---
Changed wording based on suggestion from Martin Ågren, although if
someone else shows up and says the other style is preferred I will be
cross.

The addition of a test makes this patch based on the patch I sent just
now creating the test file, which is itself based on v2.28.0.

 diff-lib.c                    | 3 ++-
 t/t4069-diff-intent-to-add.sh | 6 ++++++
 2 files changed, 8 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/diff-lib.c b/diff-lib.c
index 25fd2dee19..50521e2093 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -219,7 +219,8 @@  int run_diff_files(struct rev_info *revs, unsigned int option)
 				continue;
 			} else if (revs->diffopt.ita_invisible_in_index &&
 				   ce_intent_to_add(ce)) {
-				diff_addremove(&revs->diffopt, '+', ce->ce_mode,
+				newmode = ce_mode_from_stat(ce, st.st_mode);
+				diff_addremove(&revs->diffopt, '+', newmode,
 					       &null_oid, 0, ce->name, 0);
 				continue;
 			}
diff --git a/t/t4069-diff-intent-to-add.sh b/t/t4069-diff-intent-to-add.sh
index 85c1a35ca7..cdb41ba89d 100644
--- a/t/t4069-diff-intent-to-add.sh
+++ b/t/t4069-diff-intent-to-add.sh
@@ -15,6 +15,12 @@  test_expect_success 'diff between i-t-a and file should be new file' '
 	grep "new file mode 100644" output
 '
 
+test_expect_success 'new file diff should use worktree mode' '
+        chmod 755 test-file &&
+        git diff >output &&
+        grep "new file mode 100755" output
+'
+
 test_expect_success 'diff between i-t-a and no file should be deletion' '
 	rm -f test-file &&
 	git diff >output &&