git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* Problem with git diff --relative, diff.external, run from a sub-directory
@ 2023-01-04 22:03 Carl Baldwin
  2023-01-06 11:00 ` [PATCH 0/3] fixing "diff --relative" with external diff Jeff King
  0 siblings, 1 reply; 7+ messages in thread
From: Carl Baldwin @ 2023-01-04 22:03 UTC (permalink / raw)
  To: Git Mailing List

What did you do before the bug happened? (Steps to reproduce your issue)

    I created a simple external diff program called `mydiff` and added it to
    $PATH with exe permissions. It looks like this:

    #!/bin/bash
    # So that I can see how git calls me
    echo $0 ${1+"$@"}
    # || true is just so that git doesn't think that the external diff failed
    diff -u $2 $5 || true

    Next, I created a new repository with one file in a sub-directory. I put
    five paragraphs of generated lorem ipsum in the file. Here are the precise
    commands I ran to do this:

    $ mkdir lorem-ipsum
    $ cd lorem-ipsum
    $ git init
    $ mkdir subdir
    $ : Add some text to this file ... (I added the five paragraphs here)
    $ paste > subdir/text
    $ git add subdir/text
    $ git commit -m "initial commit"
    $ : Make a minor change to the file
    $ vim subdir/text
    $ : With the local modification in place, the following looks correct
    $ git diff --relative
    $ : This also looks correct
    $ GIT_EXTERNAL_DIFF=mydiff git diff --relative
    $ : However, cd to the sub-directory and try it again...
    $ cd subdir
    $ : The following looks as if the file was deleted
    $ GIT_EXTERNAL_DIFF=mydiff git diff --relative
    $ : However, this still looks correct
    $ git diff --relative

What did you expect to happen? (Expected behavior)

    When using a diff.external command with --relative, the diff output should
    show the minor change that I made to the file.

What happened instead? (Actual behavior)

    The diff output shows the entire old contents of the file as deleted. The
    header of the patch looked like this (indent added for this report):

        --- /private/tmp/git-blob-DQP9aO/text   2023-01-04
14:33:00.000000000 -0700
        +++ /dev/null   2023-01-04 14:33:00.000000000 -0700

    Here are the arguments that git passed to mydiff:

        /<path>/<to>/bin/mydiff text /private/tmp/git-blob-KTGAg0/text
0515a69f4ce73e295f4a7824f475bf75793cadb9 100644 /dev/null . .

What's different between what you expected and what actually happened?

    Git failed to pass the new contents of the file as the fifth argument to
    the external diff command which led to showing that the file had apparently
    been deleted when it had not. The sixth and seventh arguments aren't
    correct either but mydiff doesn't use them.

Anything else you want to add:

    The following three things ALL appear to be necessary to reprouduce this
    behavior:

    1. Setting an external diff program (either with env var or
through .gitconfig)
    2. Using --relative (either on the command line or using .gitconfig)
    3. Running `git diff` from a sub-directory under the root of the repository.

Please review the rest of the bug report below.
You can delete any lines you don't wish to share.


[System Info]
git version:
git version 2.39.0
cpu: x86_64
no commit associated with this build
sizeof-long: 8
sizeof-size_t: 8
shell-path: /bin/sh
feature: fsmonitor--daemon
uname: Darwin 21.6.0 Darwin Kernel Version 21.6.0: Thu Sep 29 20:12:57
PDT 2022; root:xnu-8020.240.7~1/RELEASE_X86_64 x86_64
compiler info: clang: 14.0.0 (clang-1400.0.29.202)
libc info: no libc information available
$SHELL (typically, interactive shell): /bin/zsh


[Enabled Hooks]

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-01-06 13:11 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-04 22:03 Problem with git diff --relative, diff.external, run from a sub-directory Carl Baldwin
2023-01-06 11:00 ` [PATCH 0/3] fixing "diff --relative" with external diff Jeff King
2023-01-06 11:03   ` [PATCH 1/3] diff: use filespec path to set up tempfiles for ext-diff Jeff King
2023-01-06 12:48     ` Junio C Hamano
2023-01-06 13:10       ` Jeff King
2023-01-06 11:04   ` [PATCH 2/3] diff: clean up external-diff argv setup Jeff King
2023-01-06 11:05   ` [PATCH 3/3] diff: drop "name" parameter from prepare_temp_file() Jeff King

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).