git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] git-sh-setup: Fail if the git directory was not found.

From
RSRobert Shearman <rob@codeweavers.com>
Date
Aug 11, 2006, 09:23 UTC
Message-ID
<44DC4C92.5060009@codeweavers.com>

Always use git-rev-parse to find a valid git directory, as git-repo-config no longer returns an error code if a git directory wasn't found.

This fixes the message received when invoking certain commands implemented as shell scripts from outside of a git tree, so e.g. instead of receiving this: /home/rob/bin/git-fetch: line 89: /FETCH_HEAD: Permission denied We get this again: fatal: Not a git repository: '.git'

Also, move the setting of GIT_OBJECT_DIRECTORY to outside of the 
non-subdir-ok case as it isn't specific to that case.
Signed-off-by: Robert Shearman <rob@codeweavers.com>
---
  git-sh-setup.sh |   12 +++---------
  1 files changed, 3 insertions(+), 9 deletions(-)

Hopefully this patch addresses the concerns of Junio and others by continuing to allow git-ls-remotes to work outside of a git repository.

diff --git a/git-sh-setup.sh b/git-sh-setup.sh
index d15747f..49f9e3b 100755
--- a/git-sh-setup.sh
+++ b/git-sh-setup.sh
@@ -37,15 +37,9 @@ esac
 
 if [ -z "$SUBDIRECTORY_OK" ]
 then
-	: ${GIT_DIR=.git}
-	: ${GIT_OBJECT_DIRECTORY="$GIT_DIR/objects"}
-
-	# Make sure we are in a valid repository of a vintage we understand.
-	GIT_DIR="$GIT_DIR" git repo-config --get core.nosuch >/dev/null
-	if test $? = 128
-	then
-	    exit
-	fi
+	GIT_DIR=$(GIT_DIR=.git git-rev-parse --git-dir) || exit
 else
 	GIT_DIR=$(git-rev-parse --git-dir) || exit
 fi
+
+GIT_OBJECT_DIRECTORY="$GIT_DIR/objects"
Next: Alex Riesen
Message 1 of 5 in “git-sh-setup: Fail if the git directory was not found.”
  1. git-sh-setup: Fail if the git directory was not found.Robert Shearman, Aug 11, 2006
  2. Alex RiesenAug 11, 2006
  3. Junio C HamanoAug 11, 2006
  4. Junio C HamanoAug 12, 2006
  5. Robert ShearmanAug 13, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.