Merge branch 'bk/fix-relative-gitdir-file'
* bk/fix-relative-gitdir-file: Handle relative paths in submodule .git files Test update-index for a gitlink to a .git filemaint
						commit
						bd0d1916de
					
				
							
								
								
									
										22
									
								
								setup.c
								
								
								
								
							
							
						
						
									
										22
									
								
								setup.c
								
								
								
								
							|  | @ -263,6 +263,8 @@ static int check_repository_format_gently(int *nongit_ok) | ||||||
| const char *read_gitfile_gently(const char *path) | const char *read_gitfile_gently(const char *path) | ||||||
| { | { | ||||||
| 	char *buf; | 	char *buf; | ||||||
|  | 	char *dir; | ||||||
|  | 	const char *slash; | ||||||
| 	struct stat st; | 	struct stat st; | ||||||
| 	int fd; | 	int fd; | ||||||
| 	size_t len; | 	size_t len; | ||||||
|  | @ -287,9 +289,23 @@ const char *read_gitfile_gently(const char *path) | ||||||
| 	if (len < 9) | 	if (len < 9) | ||||||
| 		die("No path in gitfile: %s", path); | 		die("No path in gitfile: %s", path); | ||||||
| 	buf[len] = '\0'; | 	buf[len] = '\0'; | ||||||
| 	if (!is_git_directory(buf + 8)) | 	dir = buf + 8; | ||||||
| 		die("Not a git repository: %s", buf + 8); |  | ||||||
| 	path = make_absolute_path(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); | 	free(buf); | ||||||
| 	return path; | 	return path; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -0,0 +1,38 @@ | ||||||
|  | #!/bin/sh | ||||||
|  | # | ||||||
|  | # Copyright (c) 2010 Brad King | ||||||
|  | # | ||||||
|  |  | ||||||
|  | test_description='git update-index for gitlink to .git file. | ||||||
|  | ' | ||||||
|  |  | ||||||
|  | . ./test-lib.sh | ||||||
|  |  | ||||||
|  | test_expect_success 'submodule with absolute .git file' ' | ||||||
|  | 	mkdir sub1 && | ||||||
|  | 	(cd sub1 && | ||||||
|  | 	 git init && | ||||||
|  | 	 REAL="$(pwd)/.real" && | ||||||
|  | 	 mv .git "$REAL" | ||||||
|  | 	 echo "gitdir: $REAL" >.git && | ||||||
|  | 	 test_commit first) | ||||||
|  | ' | ||||||
|  |  | ||||||
|  | test_expect_success 'add gitlink to absolute .git file' ' | ||||||
|  | 	git update-index --add -- sub1 | ||||||
|  | ' | ||||||
|  |  | ||||||
|  | test_expect_success 'submodule with relative .git file' ' | ||||||
|  | 	mkdir sub2 && | ||||||
|  | 	(cd sub2 && | ||||||
|  | 	 git init && | ||||||
|  | 	 mv .git .real && | ||||||
|  | 	 echo "gitdir: .real" >.git && | ||||||
|  | 	 test_commit first) | ||||||
|  | ' | ||||||
|  |  | ||||||
|  | test_expect_success 'add gitlink to relative .git file' ' | ||||||
|  | 	git update-index --add -- sub2 | ||||||
|  | ' | ||||||
|  |  | ||||||
|  | test_done | ||||||
		Loading…
	
		Reference in New Issue
	
	 Junio C Hamano
						Junio C Hamano