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

Re: [PATCH] more meaningful error message in gitk when git binary is not available

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 1, 2012, 17:11 UTC
Message-ID
<7va9w6dsnq.fsf@alter.siamese.dyndns.org>
In-Reply-To
<50694380.4090108@josefassad.com>
Josef Assad <josef@josefassad.com> writes:
> Signed-off-by: Josef Assad <josef@josefassad.com>
> ---
>  gitk-git/gitk |    6 ++++++
>  1 files changed, 6 insertions(+), 0 deletions(-)
Thanks.
Show 17 quoted lines
> diff --git a/gitk-git/gitk b/gitk-git/gitk
> index d93bd99..7e2e0a7 100755
> --- a/gitk-git/gitk
> +++ b/gitk-git/gitk
> @@ -11680,6 +11680,12 @@ setui $uicolor
>
>  setoptions
>
> +# check that the git executables are available for use
> +if [catch {set gitexists [exec which git]}] {
> +    show_error {} . [mc "Cannot find a suitable git executable."]
> +    exit 1
> +}
> +
>  # check that we can find a .git directory somewhere...
>  if {[catch {set gitdir [exec git rev-parse --git-dir]}]} {
>      show_error {} . [mc "Cannot find a git repository here."]

It is somewhat a stupid solution to add an extra fork that will only waste cycles in the normal non-error case, especially when we already have an error codepath that acts on lack of the "git" command anyway, isn't it?

The "rev-parse" you see in the post-context will fail when we are not in a git repository, but it will also fail when we do not have git.

You can add the new check to if {[catch {... git rev-parse }]} block; before unconditionally saying "cannot find a git repo", you check if "git" even exists, and give an appropriate error message. That way, you do not punish normal use case with an extra useless fork.

Something like this, I presume.
 gitk | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/gitk b/gitk
index d93bd99..60794a7 100755
--- a/gitk
+++ b/gitk
@@ -11682,7 +11682,12 @@ setoptions
 
 # check that we can find a .git directory somewhere...
 if {[catch {set gitdir [exec git rev-parse --git-dir]}]} {
-    show_error {} . [mc "Cannot find a git repository here."]
+    # we could have failed because there is no git to begin with
+    if {[catch {exec git version}]} {
+        show_error {} . [mc "You do not seem to have 'git' command."]
+    } else {
+        show_error {} . [mc "Cannot find a git repository here."]
+    }
     exit 1
 }
 
Previous: Joachim SchmitzNext: Josef Assad
Message 3 of 4 in “more meaningful error message in gitk when git binary is not available”
  1. more meaningful error message in gitk when git binary is not availableJosef Assad, Oct 1, 2012
  2. Joachim SchmitzOct 1, 2012
  3. Junio C HamanoOct 1, 2012
  4. Josef AssadOct 1, 2012

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.