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

Re: [PATCH] More readable 'Not a git repository' messages

From
Nguyen Thai Ngoc Duy <pclouds@gmail.com>
Date
Aug 9, 2010, 22:14 UTC
Message-ID
<AANLkTinttmKi4+EbE54r-GeRbN3_2wxUHu_qJMn5Nysn@mail.gmail.com>
In-Reply-To
<i3pdkj$hut$1@dough.gmane.org>
On Tue, Aug 10, 2010 at 3:24 AM, Ralf Ebert <info@ralfebert.de> wrote:
Show 47 quoted lines
> Stating the folder concerned with the operation and wording the
> messages differently make them slightly more readable.
>
> old: Not a git repository (or any of the parent directories): .git
> new: Not in a git repository: /home/bob/somefolder
>
> old: Not a git repository (or any parent up to mount parent /home/bob)
> old: Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not
> set).
> new: Not in a git repository: /home/bob/somefolder
> new: (stopped searching at /home because GIT_DISCOVERY_ACROSS_FILESYSTEM is
> not set)
>
> Signed-off-by: Ralf Ebert <info@ralfebert.de>
> ---
>  setup.c |   11 +++++++----
>  1 files changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/setup.c b/setup.c
> index 2769160..e27fbf1 100644
> --- a/setup.c
> +++ b/setup.c
> @@ -321,6 +321,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
>  {
>        const char *work_tree_env = getenv(GIT_WORK_TREE_ENVIRONMENT);
>        const char *env_ceiling_dirs =
> getenv(CEILING_DIRECTORIES_ENVIRONMENT);
> +       char cwd_orig[PATH_MAX];
>        static char cwd[PATH_MAX+1];
>        const char *gitdirenv;
>        const char *gitfile_dir;
> @@ -376,8 +377,9 @@ const char *setup_git_directory_gently(int *nongit_ok)
>                die("Not a git repository: '%s'", gitdirenv);
>        }
>  -      if (!getcwd(cwd, sizeof(cwd)-1))
> +       if (!getcwd(cwd_orig, sizeof(cwd_orig)))
>                die_errno("Unable to read current working directory");
> +       strcpy(cwd, cwd_orig);
>        ceil_offset = longest_ancestor_length(cwd, env_ceiling_dirs);
>        if (ceil_offset < 0 && has_dos_drive_prefix(cwd))
> @@ -431,7 +433,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
>                                *nongit_ok = 1;
>                                return NULL;
>                        }
> -                       die("Not a git repository (or any of the parent
> directories): %s", DEFAULT_GIT_DIR_ENVIRONMENT);
> +                       die("Not in a git repository: %s", cwd_orig);
cwd can be used in this case.
Show 15 quoted lines
>                }
>                if (one_filesystem) {
>                        if (stat("..", &buf)) {
> @@ -446,8 +448,9 @@ const char *setup_git_directory_gently(int *nongit_ok)
>                                        return NULL;
>                                }
>                                cwd[offset] = '\0';
> -                               die("Not a git repository (or any parent up
> to mount parent %s)\n"
> -                               "Stopping at filesystem boundary
> (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).", cwd);
> +                               die("Not in a git repository: %s\n"
> +                               "(stopped searching at %s because "
> +                               "GIT_DISCOVERY_ACROSS_FILESYSTEM is not
> set)", cwd_orig, cwd);
How about this and avoid adding cwd_orig?
-                               cwd[offset] = '\0';
-                               die("Not a git repository (or any
parent up to mount parent %s)\n"
-                               "Stopping at filesystem boundary
(GIT_DISCOVERY_ACROSS_FILESYSTEM not set).", cwd);
+                               die("Not in a git repository: %s\n"
+                               "(stopped searching at %.*s because "
+                               "GIT_DISCOVERY_ACROSS_FILESYSTEM is
not set)", cwd, offset, cwd);
-- 
Duy
Previous: Ralf EbertNext: Ralf Ebert
Message 2 of 13 in “More readable 'Not a git repository' messages”
  1. More readable 'Not a git repository' messagesRalf Ebert, Aug 9, 2010
  2. Nguyen Thai Ngoc DuyAug 9, 2010
  3. Ralf EbertAug 9, 2010
  4. Jonathan NiederAug 9, 2010
  5. Ralf EbertAug 9, 2010
  6. Nguyen Thai Ngoc DuyAug 10, 2010
  7. Sverre RabbelierAug 10, 2010
  8. Jared HanceAug 10, 2010
  9. Joshua JuranAug 10, 2010
  10. More readable 'Not a git repository' messagesRalf Ebert, Aug 13, 2010
  11. Joshua JuranAug 13, 2010
  12. setup.c: Improve 'Not a git repository' messagesRalf Ebert, Aug 15, 2010
  13. Jonathan NiederAug 15, 2010

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.