diff options
| author | Junio C Hamano <gitster@pobox.com> | 2025-10-15 10:29:28 -0700 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2025-10-15 10:29:29 -0700 |
| commit | 2dad35f32f4ac69d53a426759209d44f4a09df55 (patch) | |
| tree | ce6d3c014e8f076c0f7de5af6e03f6d48dd2873d | |
| parent | 0949f24eb4f0d1286496fd4cf3bf60f419d22b50 (diff) | |
| parent | e1d3d61a45bfdc5031d2066c0e4505ebd8145777 (diff) | |
| download | git-2dad35f32f4ac69d53a426759209d44f4a09df55.tar.gz | |
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
| -rw-r--r-- | builtin/diff.c | 15 | ||||
| -rwxr-xr-x | t/t4053-diff-no-index.sh | 17 |
2 files changed, 32 insertions, 0 deletions
diff --git a/builtin/diff.c b/builtin/diff.c index 9a89e25a98..0b23c41456 100644 --- a/builtin/diff.c +++ b/builtin/diff.c @@ -487,6 +487,21 @@ int cmd_diff(int argc, init_diff_ui_defaults(); repo_config(the_repository, git_diff_ui_config, NULL); + + /* + * If we are ignoring the fact that our current directory may + * be part of a working tree controlled by a Git repository to + * pretend to be a "better GNU diff", we should undo the + * effect of the setup code that did a chdir() to the top of + * the working tree. Where we came from is recorded in the + * prefix. + */ + if (no_index && prefix) { + if (chdir(prefix)) + die(_("cannot come back to cwd")); + prefix = NULL; + } + prefix = precompose_argv_prefix(argc, argv, prefix); repo_init_revisions(the_repository, &rev, prefix); diff --git a/t/t4053-diff-no-index.sh b/t/t4053-diff-no-index.sh index 01db9243ab..44b4b13f5d 100755 --- a/t/t4053-diff-no-index.sh +++ b/t/t4053-diff-no-index.sh @@ -26,6 +26,23 @@ test_expect_success 'git diff --no-index directories' ' test_line_count = 14 cnt ' +test_expect_success 'git diff --no-index with -' ' + cat >expect <<-\EOF && + diff --git a/- b/- + new file mode 100644 + --- /dev/null + +++ b/- + @@ -0,0 +1 @@ + +frotz + EOF + ( + cd a && + echo frotz | + test_expect_code 1 git diff --no-index /dev/null - >../actual + ) && + test_cmp expect actual +' + test_expect_success 'git diff --no-index relative path outside repo' ' ( cd repo && |
