Git fork

Merge branch 'jc/diff-no-index-in-subdir' into maint-2.51

"git diff --no-index" run inside a subdirectory under control of a
Git repository operated at the top of the working tree and stripped
the prefix from the output, and oddballs like "-" (stdin) did not
work correctly because of it. Correct the set-up by undoing what
the set-up sequence did to cwd and prefix.

* jc/diff-no-index-in-subdir:
diff: --no-index should ignore the worktree

+32
+15
builtin/diff.c
··· 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 + if (chdir(prefix)) 501 + die(_("cannot come back to cwd")); 502 + prefix = NULL; 503 + } 504 + 490 505 prefix = precompose_argv_prefix(argc, argv, prefix); 491 506 492 507 repo_init_revisions(the_repository, &rev, prefix);
+17
t/t4053-diff-no-index.sh
··· 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 &&