Code

Merge branch 'bk/fix-relative-gitdir-file'
authorJunio C Hamano <gitster@pobox.com>
Wed, 20 Jan 2010 22:38:34 +0000 (14:38 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 20 Jan 2010 22:38:34 +0000 (14:38 -0800)
* bk/fix-relative-gitdir-file:
  Handle relative paths in submodule .git files
  Test update-index for a gitlink to a .git file

1  2 
setup.c

diff --combined setup.c
index 3a07aa4df710f5d9584d4ddf412e3debc0e64db4,7fc42517136955f7748855818999eaaeec9160bf..710e2f3008c79c08cdc507288881c9a58311283a
+++ b/setup.c
@@@ -77,18 -77,6 +77,18 @@@ int check_filename(const char *prefix, 
        die_errno("failed to stat '%s'", arg);
  }
  
 +static void NORETURN die_verify_filename(const char *prefix, const char *arg)
 +{
 +      unsigned char sha1[20];
 +      unsigned mode;
 +      /* try a detailed diagnostic ... */
 +      get_sha1_with_mode_1(arg, sha1, &mode, 0, prefix);
 +      /* ... or fall back the most general message. */
 +      die("ambiguous argument '%s': unknown revision or path not in the working tree.\n"
 +          "Use '--' to separate paths from revisions", arg);
 +
 +}
 +
  /*
   * Verify a filename that we got as an argument for a pathspec
   * entry. Note that a filename that begins with "-" never verifies
@@@ -102,7 -90,8 +102,7 @@@ void verify_filename(const char *prefix
                die("bad flag '%s' used after filename", arg);
        if (check_filename(prefix, arg))
                return;
 -      die("ambiguous argument '%s': unknown revision or path not in the working tree.\n"
 -          "Use '--' to separate paths from revisions", arg);
 +      die_verify_filename(prefix, arg);
  }
  
  /*
@@@ -263,6 -252,8 +263,8 @@@ static int check_repository_format_gent
  const char *read_gitfile_gently(const char *path)
  {
        char *buf;
+       char *dir;
+       const char *slash;
        struct stat st;
        int fd;
        size_t len;
        if (len < 9)
                die("No path in gitfile: %s", path);
        buf[len] = '\0';
-       if (!is_git_directory(buf + 8))
-               die("Not a git repository: %s", buf + 8);
-       path = make_absolute_path(buf + 8);
+       dir = buf + 8;
+       if (!is_absolute_path(dir) && (slash = strrchr(path, '/'))) {
+               size_t pathlen = slash+1 - path;
+               size_t dirlen = pathlen + len - 8;
+               dir = xmalloc(dirlen + 1);
+               strncpy(dir, path, pathlen);
+               strncpy(dir + pathlen, buf + 8, len - 8);
+               dir[dirlen] = '\0';
+               free(buf);
+               buf = dir;
+       }
+       if (!is_git_directory(dir))
+               die("Not a git repository: %s", dir);
+       path = make_absolute_path(dir);
        free(buf);
        return path;
  }