Git development
 help / color / mirror / Atom feed
From: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
To: Git mailing list <git@vger.kernel.org>
Cc: Karthik Nayak <karthik.188@gmail.com>
Subject: [RFC PATCH 0/3] Improve error reporting to mention "why" a directory is not a repository
Date: Thu, 24 Sep 2026 17:32:18 +0530	[thread overview]
Message-ID: <20260924120502.2642141-1-kaartic.sivaraam@gmail.com> (raw)

At the moment, there are a few scenarios where the error message for an
invalid Git repository is a bit blunt. For instance, when we point
GIT_OBJECT_DIRECTORY at a directory that does not exist, we get this:

  $ GIT_OBJECT_DIRECTORY=/does/not/exist git --git-dir repo.git rev-parse --is-bare-repository
  fatal: not a git repository: 'repo.git'

Even though repo.git itself is a valid repository, we get this rather
puzzling error saying that it is not. The actual problem is the invalid
value given to GIT_OBJECT_DIRECTORY, and the user is left on their
to figure that out. This series aims to make such issues easier to
diagnose by saying why the specified repository was not considered
valid.

With this series, the same command outputs:

  $ GIT_OBJECT_DIRECTORY=/does/not/exist git --git-dir repo.git rev-parse --is-bare-repository
  fatal: not a git repository: 'repo.git'
  reason: cannot access object directory '/does/not/exist' set via $GIT_OBJECT_DIRECTORY

The following scenarios are covered when --git-dir is given explicitly:

  - HEAD is missing, or its path is not traversable
  - HEAD is a symlink that cannot be read
  - HEAD is a symlink whose target lives outside refs/
  - HEAD cannot be opened, or cannot be read
  - HEAD contains neither a ref under refs/ nor an object ID
  - $GIT_OBJECT_DIRECTORY is set to something we cannot access
  - the object directory in the common directory is inaccessible
  - the refs directory in the common directory is inaccessible

This series does not yet report a reason in the following cases.

The discovery walk, where we iterate up to the ceiling or the mount
point looking for a repository:

  $ GIT_OBJECT_DIRECTORY=/does/not/exist git rev-parse --is-bare-repository
  fatal: not a git repository (or any parent up to mount point /)
  Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set)

The gitfile case, for instance when run from inside a submodule /
worktree:

  $ GIT_OBJECT_DIRECTORY=/does/not/exist git rev-parse --is-bare-repository
  fatal: gitfile does not point to a valid repository: /path/to/super/sub/.git

GIT_ALTERNATE_OBJECT_DIRECTORIES is also left alone. Its diagnostic
are misleading in their own way, but they are emitted much later, from
the object database rather than from setup, so they need a separate
treatment.

I would be very interested in hearing what others think about this
direction. If it looks reasonable, I'm happy to cover the remaining
cases too, either in this series or separately.

Kaartic Sivaraam (3):
  t0009: add tests to cover more error reporting scenarios
  setup: introduce new helper 'is_git_directory_verbose'
  setup: communicate why a directory is not a valid git directory

 setup.c                       | 165 +++++++++++++++++++++++++---------
 t/t0009-git-dir-validation.sh |  38 ++++++++
 2 files changed, 161 insertions(+), 42 deletions(-)

-- 
2.56.0.rc1.12.g2c9c8d64bb


             reply	other threads:[~2026-09-24 12:05 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-24 12:02 Kaartic Sivaraam [this message]
2026-09-24 12:02 ` [RFC PATCH 1/3] t0009: add tests to cover more error reporting scenarios Kaartic Sivaraam
2026-09-24 22:08   ` Junio C Hamano
2026-09-25 13:46     ` Kaartic Sivaraam
2026-09-24 12:02 ` [RFC PATCH 2/3] setup: introduce new helper 'is_git_directory_verbose' Kaartic Sivaraam
2026-09-24 22:11   ` Junio C Hamano
2026-09-25 17:51     ` Kaartic Sivaraam
2026-09-24 12:02 ` [RFC PATCH 3/3] setup: communicate why a directory is not a valid git directory Kaartic Sivaraam
2026-09-24 22:16   ` Junio C Hamano
2026-09-25 14:33     ` Kaartic Sivaraam
2026-09-29 10:25 ` [RFC PATCH v2 0/4] Improve error reporting to mention "why" a directory is not a repository Kaartic Sivaraam
2026-09-29 10:25   ` [RFC PATCH v2 1/4] setup: normalize an if-else to follow our convention Kaartic Sivaraam
2026-09-29 10:25   ` [RFC PATCH v2 2/4] t0009: add tests to cover more error reporting scenarios Kaartic Sivaraam
2026-09-29 10:25   ` [RFC PATCH v2 3/4] setup: introduce new helper 'is_git_directory_verbose' Kaartic Sivaraam
2026-09-30 16:03     ` Patrick Steinhardt
2026-10-05 12:14       ` Kaartic Sivaraam
2026-09-30 18:32     ` Junio C Hamano
2026-09-29 10:25   ` [RFC PATCH v2 4/4] setup: communicate why a directory is not a valid git directory Kaartic Sivaraam
2026-09-30 16:03     ` Patrick Steinhardt
2026-10-05 12:29       ` Kaartic Sivaraam

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260924120502.2642141-1-kaartic.sivaraam@gmail.com \
    --to=kaartic.sivaraam@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=karthik.188@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox