Merge branch 'js/abspath-part-inside-repo'
authorJunio C Hamano <gitster@pobox.com>
Tue, 5 Feb 2019 22:26:15 +0000 (14:26 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 5 Feb 2019 22:26:15 +0000 (14:26 -0800)
On a case-insensitive filesystem, we failed to compare the part of
the path that is above the worktree directory in an absolute
pathname, which has been corrected.

* js/abspath-part-inside-repo:
abspath_part_inside_repo: respect core.ignoreCase

1  2 
setup.c
diff --combined setup.c
index 12bf25a0ebad33a8d8db9b8f9a44b0e6e04977d4,291bfb2128c1b51bfe59c3a24cd8753466a42e17..ca9e8a949ed869183f16c57520f19fb361100a02
+++ b/setup.c
@@@ -39,7 -39,7 +39,7 @@@ static int abspath_part_inside_repo(cha
        off = offset_1st_component(path);
  
        /* check if work tree is already the prefix */
-       if (wtlen <= len && !strncmp(path, work_tree, wtlen)) {
+       if (wtlen <= len && !fspathncmp(path, work_tree, wtlen)) {
                if (path[wtlen] == '/') {
                        memmove(path, path + wtlen + 1, len - wtlen);
                        return 0;
@@@ -59,7 -59,7 +59,7 @@@
                path++;
                if (*path == '/') {
                        *path = '\0';
-                       if (strcmp(real_path(path0), work_tree) == 0) {
+                       if (fspathcmp(real_path(path0), work_tree) == 0) {
                                memmove(path0, path + 1, len - (path - path0));
                                return 0;
                        }
@@@ -68,7 -68,7 +68,7 @@@
        }
  
        /* check whole path */
-       if (strcmp(real_path(path0), work_tree) == 0) {
+       if (fspathcmp(real_path(path0), work_tree) == 0) {
                *path0 = '\0';
                return 0;
        }
@@@ -831,6 -831,16 +831,6 @@@ static const char *setup_bare_git_dir(s
        return NULL;
  }
  
 -static const char *setup_nongit(const char *cwd, int *nongit_ok)
 -{
 -      if (!nongit_ok)
 -              die(_("not a git repository (or any of the parent directories): %s"), DEFAULT_GIT_DIR_ENVIRONMENT);
 -      if (chdir(cwd))
 -              die_errno(_("cannot come back to cwd"));
 -      *nongit_ok = 1;
 -      return NULL;
 -}
 -
  static dev_t get_device_or_die(const char *path, const char *prefix, int prefix_len)
  {
        struct stat buf;
@@@ -1044,7 -1054,7 +1044,7 @@@ const char *setup_git_directory_gently(
  {
        static struct strbuf cwd = STRBUF_INIT;
        struct strbuf dir = STRBUF_INIT, gitdir = STRBUF_INIT;
 -      const char *prefix;
 +      const char *prefix = NULL;
        struct repository_format repo_fmt;
  
        /*
        strbuf_addbuf(&dir, &cwd);
  
        switch (setup_git_directory_gently_1(&dir, &gitdir, 1)) {
 -      case GIT_DIR_NONE:
 -              prefix = NULL;
 -              break;
        case GIT_DIR_EXPLICIT:
                prefix = setup_explicit_git_dir(gitdir.buf, &cwd, &repo_fmt, nongit_ok);
                break;
                prefix = setup_bare_git_dir(&cwd, dir.len, &repo_fmt, nongit_ok);
                break;
        case GIT_DIR_HIT_CEILING:
 -              prefix = setup_nongit(cwd.buf, nongit_ok);
 +              if (!nongit_ok)
 +                      die(_("not a git repository (or any of the parent directories): %s"),
 +                          DEFAULT_GIT_DIR_ENVIRONMENT);
 +              *nongit_ok = 1;
                break;
        case GIT_DIR_HIT_MOUNT_POINT:
 -              if (nongit_ok) {
 -                      *nongit_ok = 1;
 -                      strbuf_release(&cwd);
 -                      strbuf_release(&dir);
 -                      return NULL;
 -              }
 -              die(_("not a git repository (or any parent up to mount point %s)\n"
 -                    "Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set)."),
 -                  dir.buf);
 +              if (!nongit_ok)
 +                      die(_("not a git repository (or any parent up to mount point %s)\n"
 +                            "Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set)."),
 +                          dir.buf);
 +              *nongit_ok = 1;
 +              break;
 +      case GIT_DIR_NONE:
 +              /*
 +               * As a safeguard against setup_git_directory_gently_1 returning
 +               * this value, fallthrough to BUG. Otherwise it is possible to
 +               * set startup_info->have_repository to 1 when we did nothing to
 +               * find a repository.
 +               */
        default:
                BUG("unhandled setup_git_directory_1() result");
        }
  
 -      if (prefix)
 -              setenv(GIT_PREFIX_ENVIRONMENT, prefix, 1);
 -      else
 +      /*
 +       * At this point, nongit_ok is stable. If it is non-NULL and points
 +       * to a non-zero value, then this means that we haven't found a
 +       * repository and that the caller expects startup_info to reflect
 +       * this.
 +       *
 +       * Regardless of the state of nongit_ok, startup_info->prefix and
 +       * the GIT_PREFIX environment variable must always match. For details
 +       * see Documentation/config/alias.txt.
 +       */
 +      if (nongit_ok && *nongit_ok) {
 +              startup_info->have_repository = 0;
 +              startup_info->prefix = NULL;
                setenv(GIT_PREFIX_ENVIRONMENT, "", 1);
 -
 -      startup_info->have_repository = !nongit_ok || !*nongit_ok;
 -      startup_info->prefix = prefix;
 +      } else {
 +              startup_info->have_repository = 1;
 +              startup_info->prefix = prefix;
 +              if (prefix)
 +                      setenv(GIT_PREFIX_ENVIRONMENT, prefix, 1);
 +              else
 +                      setenv(GIT_PREFIX_ENVIRONMENT, "", 1);
 +      }
  
        /*
         * Not all paths through the setup code will call 'set_git_dir()' (which
         * the user has set GIT_DIR.  It may be beneficial to disallow bogus
         * GIT_DIR values at some point in the future.
         */
 -      if (startup_info->have_repository || getenv(GIT_DIR_ENVIRONMENT)) {
 +      if (/* GIT_DIR_EXPLICIT, GIT_DIR_DISCOVERED, GIT_DIR_BARE */
 +          startup_info->have_repository ||
 +          /* GIT_DIR_EXPLICIT */
 +          getenv(GIT_DIR_ENVIRONMENT)) {
                if (!the_repository->gitdir) {
                        const char *gitdir = getenv(GIT_DIR_ENVIRONMENT);
                        if (!gitdir)