summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 48cc95e)
raw | patch | inline | side by side (parent: 48cc95e)
author | Brad King <brad.king@kitware.com> | |
Sat, 9 Jan 2010 03:36:41 +0000 (22:36 -0500) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Sun, 10 Jan 2010 07:43:22 +0000 (23:43 -0800) |
Commit 842abf0 (Teach resolve_gitlink_ref() about the .git file, 2008-02-20)
taught resolve_gitlink_ref() to call read_gitfile_gently() to resolve .git
files. In this commit teach read_gitfile_gently() to interpret a relative
path in a .git file with respect to the file location.
This change allows update-index to recognize a submodule that uses a relative
path in its .git file. It previously failed because the relative path was
wrongly interpreted with respect to the superproject directory.
Signed-off-by: Brad King <brad.king@kitware.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
taught resolve_gitlink_ref() to call read_gitfile_gently() to resolve .git
files. In this commit teach read_gitfile_gently() to interpret a relative
path in a .git file with respect to the file location.
This change allows update-index to recognize a submodule that uses a relative
path in its .git file. It previously failed because the relative path was
wrongly interpreted with respect to the superproject directory.
Signed-off-by: Brad King <brad.king@kitware.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
setup.c | patch | blob | history | |
t/t2104-update-index-gitfile.sh | patch | blob | history |
index 2cf0f1993718fd737cd87e79d2f4950832c59c9f..7fc42517136955f7748855818999eaaeec9160bf 100644 (file)
--- a/setup.c
+++ b/setup.c
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;
}
index ba719846a6fbe4958ce264165ba3737ce79a3a5b..641607d89ae400f5fbce9dba0f42ee185d3ecd6a 100755 (executable)
test_commit first)
'
-test_expect_failure 'add gitlink to relative .git file' '
+test_expect_success 'add gitlink to relative .git file' '
git update-index --add -- sub2
'