{"thread":{"id":"57901","subject":"bug: `git diff` implies folder isn’t a git repo","startedAt":"2022-05-20T04:37:40Z","lastAt":"2022-05-21T18:40:10Z","messageCount":2,"participants":["allejo","brian m. carlson"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"455547","messageId":"180dfb3d8d3.12352a818142651.7062268074453572353@allejo.io","threadId":"57901","inReplyTo":null,"subject":"bug: `git diff` implies folder isn’t a git repo","fromName":"allejo","fromEmail":"me@allejo.io","sentAt":"2022-05-20T04:22:27Z","receivedAt":"2022-05-20T04:37:40Z","isPatch":false,"sender":{"key":"me@allejo.io","avatar":null},"body":"Please answer the following questions to help us understand your issue.\n\nWhat did you do before the bug happened? (Steps to reproduce your issue)\n\nChange ownership of a Git repo to require `safe.directory` behavior.\n\nWhat did you expect to happen? (Expected behavior)\n\nIf you run `git diff --exit-code` on a non-`safe.directory`, you should get the standard error.\n\n    Error: fatal: unsafe repository ('/path/to/repo' is owned by someone else)\n\nWhat happened instead? (Actual behavior)\n\nI get an error message saying it's not actually a git repository even though it is, it's just not safe to work in.\n\n    warning: Not a git repository. Use --no-index to compare two paths outside a working tree\n    usage: git diff --no-index [<options>] <path> <path>\n\n    Diff output format options\n        -p, --patch           generate patch\n        -s, --no-patch        suppress diff output\n        -u                    generate patch\n        -U, --unified[=<n>]   generate diffs with <n> lines context\n        -W, --function-context\n                              generate diffs with <n> lines context\n        --raw                 generate the diff in raw format\n        --patch-with-raw      synonym for '-p --raw'\n        --patch-with-stat     synonym for '-p --stat'\n        --numstat             machine friendly --stat\n        --shortstat           output only the last line of --stat\n        -X, --dirstat[=<param1,param2>...]\n                              output the distribution of relative amount of changes for each sub-directory\n    ...\n\nWhat's different between what you expected and what actually happened?\n\nOne 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.\n\nAnything else you want to add:\n\nI am installing git on Ubuntu 20.04.4 from its default repositories inside of a GitHub Actions runner.\n\n[System Info]\ngit version:\ngit version 2.25.1\ncpu: x86_64\nno commit associated with this build\nsizeof-long: 8\nsizeof-size_t: 8\nshell-path: /bin/sh\nlibc info: no libc information available\n$SHELL (typically, interactive shell): /bin/bash\n\n\n[Enabled Hooks]\nnot run from a git repository - no hooks to show\n\n"},{"id":"455708","messageId":"Yokx/MyZHjGHRkoK@camp.crustytoothpaste.net","threadId":"57901","inReplyTo":"180dfb3d8d3.12352a818142651.7062268074453572353@allejo.io","subject":"Re: bug: `git diff` implies folder isn’t a git repo","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2022-05-21T18:39:56Z","receivedAt":"2022-05-21T18:40:10Z","isPatch":false,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2022-05-20 at 04:22:27, allejo wrote:\n> Please answer the following questions to help us understand your issue.\n> \n> What did you do before the bug happened? (Steps to reproduce your issue)\n> \n> Change ownership of a Git repo to require `safe.directory` behavior.\n> \n> What did you expect to happen? (Expected behavior)\n> \n> If you run `git diff --exit-code` on a non-`safe.directory`, you should get the standard error.\n> \n>     Error: fatal: unsafe repository ('/path/to/repo' is owned by someone else)\n> \n> What happened instead? (Actual behavior)\n> \n> 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.\n> \n>     warning: Not a git repository. Use --no-index to compare two paths outside a working tree\n>     usage: git diff --no-index [<options>] <path> <path>\n> \n>     Diff output format options\n>         -p, --patch           generate patch\n>         -s, --no-patch        suppress diff output\n>         -u                    generate patch\n>         -U, --unified[=<n>]   generate diffs with <n> lines context\n>         -W, --function-context\n>                               generate diffs with <n> lines context\n>         --raw                 generate the diff in raw format\n>         --patch-with-raw      synonym for '-p --raw'\n>         --patch-with-stat     synonym for '-p --stat'\n>         --numstat             machine friendly --stat\n>         --shortstat           output only the last line of --stat\n>         -X, --dirstat[=<param1,param2>...]\n>                               output the distribution of relative amount of changes for each sub-directory\n>     ...\n> \n> What's different between what you expected and what actually happened?\n> \n> 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.\n\nWhile I agree this is not a good experience, let me explain why this is.\nSome programs, like git status, must always have a Git repository.\nOthers, like git diff, may have a Git repository or not.  If they do\nnot, some functionality is not available.\n\nThe check for a Git repository happens during setup before anything\nhaving to do with git diff is actually invoked.  By the time git diff\nactually gets invoked, all it knows is that either (a) there is a valid\nGit repository which can be used and is properly set up or (b) there is\nnot.  In this case, the answer is (b): you don't have a valid Git\nrepository because the permissions are wrong.\n\nThis could of course be changed, but it requires a bunch of retrofitting\nthroughout the code to save _why_ it's not a valid Git repository and\nthen print that later on, which hasn't happened yet.\n-- \nbrian m. carlson (he/him or they/them)\nToronto, Ontario, CA\n"}]}