diff options
| author | Junio C Hamano <gitster@pobox.com> | 2025-08-22 13:13:20 -0700 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2025-08-22 13:13:21 -0700 |
| commit | 72e4eb56f0a89ed4345ee9f806321cc49b0e7a0d (patch) | |
| tree | 9c61ce5b082c7312eefae4f9efde3f883b332256 /builtin/diff.c | |
| parent | d08436df5f686c0d9419717eaeba16bb4ebb3719 (diff) | |
| parent | e1d3d61a45bfdc5031d2066c0e4505ebd8145777 (diff) | |
Merge branch 'jc/diff-no-index-in-subdir'
"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
Diffstat (limited to 'builtin/diff.c')
| -rw-r--r-- | builtin/diff.c | 15 |
1 files changed, 15 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); |
