diff --git a/src/tree.c b/src/tree.c index 7b47af347..150f90c44 100644 --- a/src/tree.c +++ b/src/tree.c @@ -26,7 +26,9 @@ static bool valid_filemode(const int filemode) static int valid_entry_name(const char *filename) { - return *filename != '\0' && strchr(filename, '/') == NULL; + return *filename != '\0' && strchr(filename, '/') == NULL && + strcmp(filename, "..") != 0 && strcmp(filename, ".") != 0 && + strcmp(filename, ".git") != 0; } static int entry_sort_cmp(const void *a, const void *b) diff --git a/tests-clar/object/tree/write.c b/tests-clar/object/tree/write.c index 657bed289..cc5438b05 100644 --- a/tests-clar/object/tree/write.c +++ b/tests-clar/object/tree/write.c @@ -39,6 +39,12 @@ void test_object_tree_write__from_memory(void) &bid, GIT_FILEMODE_BLOB)); cl_git_fail(git_treebuilder_insert(NULL, builder, "/", &bid, GIT_FILEMODE_BLOB)); + cl_git_fail(git_treebuilder_insert(NULL, builder, ".git", + &bid, GIT_FILEMODE_BLOB)); + cl_git_fail(git_treebuilder_insert(NULL, builder, "..", + &bid, GIT_FILEMODE_BLOB)); + cl_git_fail(git_treebuilder_insert(NULL, builder, ".", + &bid, GIT_FILEMODE_BLOB)); cl_git_fail(git_treebuilder_insert(NULL, builder, "folder/new.txt", &bid, GIT_FILEMODE_BLOB));