File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -487,6 +487,20 @@ int cmd_diff(int argc,
487
487
488
488
init_diff_ui_defaults ();
489
489
repo_config (the_repository , git_diff_ui_config , NULL );
490
+
491
+ /*
492
+ * If we are ignoring the fact that our current directory may
493
+ * be part of a working tree controlled by a Git repository to
494
+ * pretend to be a "better GNU diff", we should undo the
495
+ * effect of the setup code that did a chdir() to the top of
496
+ * the working tree. Where we came from is recorded in the
497
+ * prefix.
498
+ */
499
+ if (no_index && prefix ) {
500
+ chdir (prefix );
501
+ prefix = NULL ;
502
+ }
503
+
490
504
prefix = precompose_argv_prefix (argc , argv , prefix );
491
505
492
506
repo_init_revisions (the_repository , & rev , prefix );
Original file line number Diff line number Diff line change @@ -26,6 +26,23 @@ test_expect_success 'git diff --no-index directories' '
26
26
test_line_count = 14 cnt
27
27
'
28
28
29
+ test_expect_success ' git diff --no-index with -' '
30
+ cat >expect <<-\EOF &&
31
+ diff --git a/- b/-
32
+ new file mode 100644
33
+ --- /dev/null
34
+ +++ b/-
35
+ @@ -0,0 +1 @@
36
+ +frotz
37
+ EOF
38
+ (
39
+ cd a &&
40
+ echo frotz |
41
+ test_expect_code 1 git diff --no-index /dev/null - >../actual
42
+ ) &&
43
+ test_cmp expect actual
44
+ '
45
+
29
46
test_expect_success ' git diff --no-index relative path outside repo' '
30
47
(
31
48
cd repo &&
You can’t perform that action at this time.
0 commit comments