Merge pull request #1356 from arrbee/fix-directory-as-ignore-file

Do not fail if .gitignore is directory
This commit is contained in:
Vicent Martí 2013-02-22 12:26:01 -08:00
commit 68fec637a2
2 changed files with 35 additions and 13 deletions

View File

@ -278,8 +278,14 @@ static int load_attr_file(
return GIT_ENOTFOUND; return GIT_ENOTFOUND;
error = git_futils_readbuffer(&content, filename); error = git_futils_readbuffer(&content, filename);
if (error < 0) if (error < 0) {
return error; /* convert error into ENOTFOUND so failed permissions / invalid
* file type don't actually stop the operation in progress.
*/
return GIT_ENOTFOUND;
/* TODO: once warnings are available, issue a warning callback */
}
*data = git_buf_detach(&content); *data = git_buf_detach(&content);

View File

@ -1,4 +1,6 @@
#include "clar_libgit2.h" #include "clar_libgit2.h"
#include "posix.h"
#include "path.h"
static git_repository *g_repo = NULL; static git_repository *g_repo = NULL;
@ -30,3 +32,17 @@ void test_attr_ignore__honor_temporary_rules(void)
assert_is_ignored(true, "NewFolder/NewFolder"); assert_is_ignored(true, "NewFolder/NewFolder");
assert_is_ignored(true, "NewFolder/NewFolder/File.txt"); assert_is_ignored(true, "NewFolder/NewFolder/File.txt");
} }
void test_attr_ignore__skip_gitignore_directory(void)
{
cl_git_rewritefile("attr/.git/info/exclude", "/NewFolder\n/NewFolder/NewFolder");
p_unlink("attr/.gitignore");
cl_assert(!git_path_exists("attr/.gitignore"));
p_mkdir("attr/.gitignore", 0777);
cl_git_mkfile("attr/.gitignore/garbage.txt", "new_file\n");
assert_is_ignored(false, "File.txt");
assert_is_ignored(true, "NewFolder");
assert_is_ignored(true, "NewFolder/NewFolder");
assert_is_ignored(true, "NewFolder/NewFolder/File.txt");
}