{"thread":{"id":"5205","subject":"[PATCH] git-sh-setup: Fail if the git directory was not found.","startedAt":"2006-08-11T09:23:30Z","lastAt":"2006-08-13T11:52:36Z","messageCount":5,"participants":["Robert Shearman","Alex Riesen","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"25125","messageId":"44DC4C92.5060009@codeweavers.com","threadId":"5205","inReplyTo":null,"subject":"[PATCH] git-sh-setup: Fail if the git directory was not found.","fromName":"Robert Shearman","fromEmail":"rob@codeweavers.com","sentAt":"2006-08-11T09:23:30Z","receivedAt":"2006-08-11T09:23:30Z","isPatch":true,"sender":{"key":"robertshearman@gmail.com","avatar":null},"body":"\nAlways use git-rev-parse to find a valid git directory, as \ngit-repo-config no longer returns an error code if a git directory \nwasn't found.\n\nThis fixes the message received when invoking certain commands \nimplemented as shell scripts from outside of a git tree, so e.g. instead \nof receiving this:\n/home/rob/bin/git-fetch: line 89: /FETCH_HEAD: Permission denied\nWe get this again:\nfatal: Not a git repository: '.git'\n\nAlso, move the setting of GIT_OBJECT_DIRECTORY to outside of the \nnon-subdir-ok case as it isn't specific to that case.\nSigned-off-by: Robert Shearman <rob@codeweavers.com>\n---\n  git-sh-setup.sh |   12 +++---------\n  1 files changed, 3 insertions(+), 9 deletions(-)\n\nHopefully this patch addresses the concerns of Junio and others by \ncontinuing to allow git-ls-remotes to work outside of a git repository.\n\n\ndiff --git a/git-sh-setup.sh b/git-sh-setup.sh\nindex d15747f..49f9e3b 100755\n--- a/git-sh-setup.sh\n+++ b/git-sh-setup.sh\n@@ -37,15 +37,9 @@ esac\n \n if [ -z \"$SUBDIRECTORY_OK\" ]\n then\n-\t: ${GIT_DIR=.git}\n-\t: ${GIT_OBJECT_DIRECTORY=\"$GIT_DIR/objects\"}\n-\n-\t# Make sure we are in a valid repository of a vintage we understand.\n-\tGIT_DIR=\"$GIT_DIR\" git repo-config --get core.nosuch >/dev/null\n-\tif test $? = 128\n-\tthen\n-\t    exit\n-\tfi\n+\tGIT_DIR=$(GIT_DIR=.git git-rev-parse --git-dir) || exit\n else\n \tGIT_DIR=$(git-rev-parse --git-dir) || exit\n fi\n+\n+GIT_OBJECT_DIRECTORY=\"$GIT_DIR/objects\"\n\n"},{"id":"25139","messageId":"20060811194226.GA12276@steel.home","threadId":"5205","inReplyTo":"44DC4C92.5060009@codeweavers.com","subject":"Re: [PATCH] git-sh-setup: Fail if the git directory was not found.","fromName":"Alex Riesen","fromEmail":"fork0@t-online.de","sentAt":"2006-08-11T19:42:26Z","receivedAt":"2006-08-11T19:42:26Z","isPatch":true,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"Robert Shearman, Fri, Aug 11, 2006 11:23:30 +0200:\n> Always use git-rev-parse to find a valid git directory, as \n> git-repo-config no longer returns an error code if a git directory \n> wasn't found.\n\nBTW, did anyone notice that \"--usage\" almost always needs git\ndirectory? That is quite unusual.\n"},{"id":"25144","messageId":"7vfyg2sxrk.fsf@assigned-by-dhcp.cox.net","threadId":"5205","inReplyTo":"44DC4C92.5060009@codeweavers.com","subject":"Re: [PATCH] git-sh-setup: Fail if the git directory was not found.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-08-11T22:39:11Z","receivedAt":"2006-08-11T22:39:11Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Robert Shearman <rob@codeweavers.com> writes:\n\n> Always use git-rev-parse to find a valid git directory, as\n> git-repo-config no longer returns an error code if a git directory\n> wasn't found.\n>\n> This fixes the message received when invoking certain commands\n> implemented as shell scripts from outside of a git tree, so\n> e.g. instead of receiving this:\n> /home/rob/bin/git-fetch: line 89: /FETCH_HEAD: Permission denied\n> We get this again:\n> fatal: Not a git repository: '.git'\n>\n> Also, move the setting of GIT_OBJECT_DIRECTORY to outside of the\n> non-subdir-ok case as it isn't specific to that case.\n>\n> Signed-off-by: Robert Shearman <rob@codeweavers.com>\n\nMoving the assignment of GIT_OBJECT_DIRECTORY is fine, but\nchanging it to an unconditional assignment is wrong.  The user\ncan have a GIT_OBJECT_DIRECTORY set independently from GIT_DIR\n(or ../some/where/.git that is detected).\n\nThe rest looks sane; the new test should still detect the case the\noriginal test tried to catch.\n\n>  git-sh-setup.sh |   12 +++---------\n>  1 files changed, 3 insertions(+), 9 deletions(-)\n>\n> Hopefully this patch addresses the concerns of Junio and others by\n> continuing to allow git-ls-remotes to work outside of a git repository.\n> diff --git a/git-sh-setup.sh b/git-sh-setup.sh\n> index d15747f..49f9e3b 100755\n> --- a/git-sh-setup.sh\n> +++ b/git-sh-setup.sh\n> @@ -37,15 +37,9 @@ esac\n>  \n>  if [ -z \"$SUBDIRECTORY_OK\" ]\n>  then\n> -\t: ${GIT_DIR=.git}\n> -\t: ${GIT_OBJECT_DIRECTORY=\"$GIT_DIR/objects\"}\n> -\n> -\t# Make sure we are in a valid repository of a vintage we understand.\n> -\tGIT_DIR=\"$GIT_DIR\" git repo-config --get core.nosuch >/dev/null\n> -\tif test $? = 128\n> -\tthen\n> -\t    exit\n> -\tfi\n> +\tGIT_DIR=$(GIT_DIR=.git git-rev-parse --git-dir) || exit\n>  else\n>  \tGIT_DIR=$(git-rev-parse --git-dir) || exit\n>  fi\n> +\n> +GIT_OBJECT_DIRECTORY=\"$GIT_DIR/objects\"\n"},{"id":"25151","messageId":"7vlkpuragp.fsf@assigned-by-dhcp.cox.net","threadId":"5205","inReplyTo":"7vfyg2sxrk.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] git-sh-setup: Fail if the git directory was not found.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-08-12T01:47:50Z","receivedAt":"2006-08-12T01:47:50Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <junkio@cox.net> writes:\n\n> Moving the assignment of GIT_OBJECT_DIRECTORY is fine, but\n> changing it to an unconditional assignment is wrong.  The user\n> can have a GIT_OBJECT_DIRECTORY set independently from GIT_DIR\n> (or ../some/where/.git that is detected).\n\nHow about this as a replacement?\n\n-- >8 --\n[PATCH] git-sh-setup: do not use repo-config to test the git directory\n\nSince repo-config does not fail in non-git directory, it is not\na good command to use to test the git-ness nor validate the\nrepository revision of $GIT_DIR.\n\nOriginal patch by Robert Shearman but with minor fixes.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n git-sh-setup.sh |   11 +++--------\n 1 files changed, 3 insertions(+), 8 deletions(-)\n\ndiff --git a/git-sh-setup.sh b/git-sh-setup.sh\nindex d15747f..42f9b1c 100755\n--- a/git-sh-setup.sh\n+++ b/git-sh-setup.sh\n@@ -35,17 +35,12 @@ case \"$1\" in\n \texit\n esac\n \n+# Make sure we are in a valid repository of a vintage we understand.\n if [ -z \"$SUBDIRECTORY_OK\" ]\n then\n \t: ${GIT_DIR=.git}\n-\t: ${GIT_OBJECT_DIRECTORY=\"$GIT_DIR/objects\"}\n-\n-\t# Make sure we are in a valid repository of a vintage we understand.\n-\tGIT_DIR=\"$GIT_DIR\" git repo-config --get core.nosuch >/dev/null\n-\tif test $? = 128\n-\tthen\n-\t    exit\n-\tfi\n+\tGIT_DIR=$(GIT_DIR=\"$GIT_DIR\" git-rev-parse --git-dir) || exit\n else\n \tGIT_DIR=$(git-rev-parse --git-dir) || exit\n fi\n+: ${GIT_OBJECT_DIRECTORY=\"$GIT_DIR/objects\"}\n-- \n1.4.2.rc4.g9d8df\n"},{"id":"25182","messageId":"44DF1284.5080406@codeweavers.com","threadId":"5205","inReplyTo":"7vlkpuragp.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] git-sh-setup: Fail if the git directory was not found.","fromName":"Robert Shearman","fromEmail":"rob@codeweavers.com","sentAt":"2006-08-13T11:52:36Z","receivedAt":"2006-08-13T11:52:36Z","isPatch":true,"sender":{"key":"robertshearman@gmail.com","avatar":null},"body":"Junio C Hamano wrote:\n\n>Junio C Hamano <junkio@cox.net> writes:\n>\n>  \n>\n>>Moving the assignment of GIT_OBJECT_DIRECTORY is fine, but\n>>changing it to an unconditional assignment is wrong.  The user\n>>can have a GIT_OBJECT_DIRECTORY set independently from GIT_DIR\n>>(or ../some/where/.git that is detected).\n>>    \n>>\n\nI'm not an expert in shell scripting so I didn't notice that it was a \nconditional assignment.\n\n>How about this as a replacement?\n>  \n>\n\nLooks good.\n\nThanks,\n\n-- \nRob Shearman\n"}]}