git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* bug: `git diff` implies folder isn’t a git repo
@ 2022-05-20  4:22 allejo
  2022-05-21 18:39 ` brian m. carlson
  0 siblings, 1 reply; 2+ messages in thread
From: allejo @ 2022-05-20  4:22 UTC (permalink / raw)
  To: git

Please answer the following questions to help us understand your issue.

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

Change ownership of a Git repo to require `safe.directory` behavior.

What did you expect to happen? (Expected behavior)

If you run `git diff --exit-code` on a non-`safe.directory`, you should get the standard error.

    Error: fatal: unsafe repository ('/path/to/repo' is owned by someone else)

What happened instead? (Actual behavior)

I get an error message saying it's not actually a git repository even though it is, it's just not safe to work in.

    warning: Not a git repository. Use --no-index to compare two paths outside a working tree
    usage: git diff --no-index [<options>] <path> <path>

    Diff output format options
        -p, --patch           generate patch
        -s, --no-patch        suppress diff output
        -u                    generate patch
        -U, --unified[=<n>]   generate diffs with <n> lines context
        -W, --function-context
                              generate diffs with <n> lines context
        --raw                 generate the diff in raw format
        --patch-with-raw      synonym for '-p --raw'
        --patch-with-stat     synonym for '-p --stat'
        --numstat             machine friendly --stat
        --shortstat           output only the last line of --stat
        -X, --dirstat[=<param1,param2>...]
                              output the distribution of relative amount of changes for each sub-directory
    ...

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

One error message implies the folder isn't a Git repo while the other explicitly says it's not safe to work in and how to fix it.

Anything else you want to add:

I am installing git on Ubuntu 20.04.4 from its default repositories inside of a GitHub Actions runner.

[System Info]
git version:
git version 2.25.1
cpu: x86_64
no commit associated with this build
sizeof-long: 8
sizeof-size_t: 8
shell-path: /bin/sh
libc info: no libc information available
$SHELL (typically, interactive shell): /bin/bash


[Enabled Hooks]
not run from a git repository - no hooks to show


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

* Re: bug: `git diff` implies folder isn’t a git repo
  2022-05-20  4:22 bug: `git diff` implies folder isn’t a git repo allejo
@ 2022-05-21 18:39 ` brian m. carlson
  0 siblings, 0 replies; 2+ messages in thread
From: brian m. carlson @ 2022-05-21 18:39 UTC (permalink / raw)
  To: allejo; +Cc: git

[-- Attachment #1: Type: text/plain, Size: 2828 bytes --]

On 2022-05-20 at 04:22:27, allejo wrote:
> Please answer the following questions to help us understand your issue.
> 
> What did you do before the bug happened? (Steps to reproduce your issue)
> 
> Change ownership of a Git repo to require `safe.directory` behavior.
> 
> What did you expect to happen? (Expected behavior)
> 
> If you run `git diff --exit-code` on a non-`safe.directory`, you should get the standard error.
> 
>     Error: fatal: unsafe repository ('/path/to/repo' is owned by someone else)
> 
> What happened instead? (Actual behavior)
> 
> I get an error message saying it's not actually a git repository even though it is, it's just not safe to work in.
> 
>     warning: Not a git repository. Use --no-index to compare two paths outside a working tree
>     usage: git diff --no-index [<options>] <path> <path>
> 
>     Diff output format options
>         -p, --patch           generate patch
>         -s, --no-patch        suppress diff output
>         -u                    generate patch
>         -U, --unified[=<n>]   generate diffs with <n> lines context
>         -W, --function-context
>                               generate diffs with <n> lines context
>         --raw                 generate the diff in raw format
>         --patch-with-raw      synonym for '-p --raw'
>         --patch-with-stat     synonym for '-p --stat'
>         --numstat             machine friendly --stat
>         --shortstat           output only the last line of --stat
>         -X, --dirstat[=<param1,param2>...]
>                               output the distribution of relative amount of changes for each sub-directory
>     ...
> 
> What's different between what you expected and what actually happened?
> 
> One error message implies the folder isn't a Git repo while the other explicitly says it's not safe to work in and how to fix it.

While I agree this is not a good experience, let me explain why this is.
Some programs, like git status, must always have a Git repository.
Others, like git diff, may have a Git repository or not.  If they do
not, some functionality is not available.

The check for a Git repository happens during setup before anything
having to do with git diff is actually invoked.  By the time git diff
actually gets invoked, all it knows is that either (a) there is a valid
Git repository which can be used and is properly set up or (b) there is
not.  In this case, the answer is (b): you don't have a valid Git
repository because the permissions are wrong.

This could of course be changed, but it requires a bunch of retrofitting
throughout the code to save _why_ it's not a valid Git repository and
then print that later on, which hasn't happened yet.
-- 
brian m. carlson (he/him or they/them)
Toronto, Ontario, CA

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 262 bytes --]

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

end of thread, other threads:[~2022-05-21 18:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-20  4:22 bug: `git diff` implies folder isn’t a git repo allejo
2022-05-21 18:39 ` brian m. carlson

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).