Skip to content

Commit 22d3b8d

Browse files
peffgitster
authored andcommitted
clone: detect errors in normalize_path_copy
When we are copying the alternates from the source repository, if we find a relative path that is too deep for the source (e.g., "../../../objects" from "/repo.git/objects"), then normalize_path_copy will report an error and leave trash in the buffer, which we will add to our new alternates file. Instead, let's detect the error, print a warning, and skip copying that alternate. There's no need to die. The relative path is probably just broken cruft in the source repo. If it turns out to have been important for accessing some objects, we rely on other parts of the clone to detect that, just as they would with a missing object in the source repo itself (though note that clones with "-s" are inherently local, which may do fewer object-quality checks in the first place). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 0b65a8d commit 22d3b8d

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

builtin/clone.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,11 @@ static void copy_alternates(struct strbuf *src, struct strbuf *dst,
353353
continue;
354354
}
355355
abs_path = mkpathdup("%s/objects/%s", src_repo, line.buf);
356-
normalize_path_copy(abs_path, abs_path);
357-
add_to_alternates_file(abs_path);
356+
if (!normalize_path_copy(abs_path, abs_path))
357+
add_to_alternates_file(abs_path);
358+
else
359+
warning("skipping invalid relative alternate: %s/%s",
360+
src_repo, line.buf);
358361
free(abs_path);
359362
}
360363
strbuf_release(&line);

0 commit comments

Comments
 (0)