mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-09 22:39:38 +00:00
Add unit tests for recent bug fixes
Add unit tests to confirm ignore directory pattern matches and to confirm that ignore and attribute files are loaded properly into the attribute file cache.
This commit is contained in:
parent
62a1f713de
commit
e8c96ed2a7
@ -210,6 +210,13 @@ int git_attr_add_macro(
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int git_attr_cache__is_cached(git_repository *repo, const char *path)
|
||||||
|
{
|
||||||
|
const char *cache_key = path;
|
||||||
|
if (repo && git__prefixcmp(cache_key, git_repository_workdir(repo)) == 0)
|
||||||
|
cache_key += strlen(git_repository_workdir(repo));
|
||||||
|
return (git_hashtable_lookup(repo->attrcache.files, cache_key) == NULL);
|
||||||
|
}
|
||||||
|
|
||||||
/* add git_attr_file to vector of files, loading if needed */
|
/* add git_attr_file to vector of files, loading if needed */
|
||||||
int git_attr_cache__push_file(
|
int git_attr_cache__push_file(
|
||||||
|
@ -27,4 +27,7 @@ extern int git_attr_cache__push_file(
|
|||||||
const char *filename,
|
const char *filename,
|
||||||
int (*loader)(git_repository *, const char *, git_attr_file *));
|
int (*loader)(git_repository *, const char *, git_attr_file *));
|
||||||
|
|
||||||
|
/* returns GIT_SUCCESS if path is in cache */
|
||||||
|
extern int git_attr_cache__is_cached(git_repository *repo, const char *path);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "clar_libgit2.h"
|
#include "clar_libgit2.h"
|
||||||
#include "fileops.h"
|
#include "fileops.h"
|
||||||
#include "git2/attr.h"
|
#include "git2/attr.h"
|
||||||
|
#include "attr.h"
|
||||||
|
|
||||||
static git_repository *g_repo = NULL;
|
static git_repository *g_repo = NULL;
|
||||||
|
|
||||||
@ -89,6 +90,10 @@ void test_attr_repo__get_one(void)
|
|||||||
|
|
||||||
git_buf_free(&b);
|
git_buf_free(&b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cl_git_pass(git_attr_cache__is_cached(g_repo, ".git/info/attributes"));
|
||||||
|
cl_git_pass(git_attr_cache__is_cached(g_repo, ".gitattributes"));
|
||||||
|
cl_git_pass(git_attr_cache__is_cached(g_repo, "sub/.gitattributes"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_attr_repo__get_many(void)
|
void test_attr_repo__get_many(void)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "clar_libgit2.h"
|
#include "clar_libgit2.h"
|
||||||
#include "fileops.h"
|
#include "fileops.h"
|
||||||
#include "git2/attr.h"
|
#include "git2/attr.h"
|
||||||
|
#include "attr.h"
|
||||||
|
|
||||||
static git_repository *g_repo = NULL;
|
static git_repository *g_repo = NULL;
|
||||||
|
|
||||||
@ -29,6 +30,7 @@ void test_status_ignore__0(void)
|
|||||||
const char *path;
|
const char *path;
|
||||||
int expected;
|
int expected;
|
||||||
} test_cases[] = {
|
} test_cases[] = {
|
||||||
|
/* patterns "sub" and "ign" from .gitignore */
|
||||||
{ "file", 0 },
|
{ "file", 0 },
|
||||||
{ "ign", 1 },
|
{ "ign", 1 },
|
||||||
{ "sub", 1 },
|
{ "sub", 1 },
|
||||||
@ -38,6 +40,12 @@ void test_status_ignore__0(void)
|
|||||||
{ "sub/sub/file", 0 },
|
{ "sub/sub/file", 0 },
|
||||||
{ "sub/sub/ign", 1 },
|
{ "sub/sub/ign", 1 },
|
||||||
{ "sub/sub/sub", 1 },
|
{ "sub/sub/sub", 1 },
|
||||||
|
/* pattern "dir/" from .gitignore */
|
||||||
|
{ "dir", 1 },
|
||||||
|
{ "dir/", 1 },
|
||||||
|
{ "sub/dir", 1 },
|
||||||
|
{ "sub/dir/", 1 },
|
||||||
|
{ "sub/sub/dir", 0 }, /* dir is not actually a dir, but a file */
|
||||||
{ NULL, 0 }
|
{ NULL, 0 }
|
||||||
}, *one_test;
|
}, *one_test;
|
||||||
|
|
||||||
@ -46,4 +54,8 @@ void test_status_ignore__0(void)
|
|||||||
cl_git_pass(git_status_should_ignore(g_repo, one_test->path, &ignored));
|
cl_git_pass(git_status_should_ignore(g_repo, one_test->path, &ignored));
|
||||||
cl_assert_(ignored == one_test->expected, one_test->path);
|
cl_assert_(ignored == one_test->expected, one_test->path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* confirm that ignore files were cached */
|
||||||
|
cl_git_pass(git_attr_cache__is_cached(g_repo, ".git/info/exclude"));
|
||||||
|
cl_git_pass(git_attr_cache__is_cached(g_repo, ".gitignore"));
|
||||||
}
|
}
|
||||||
|
0
tests/resources/attr/dir/file
Normal file
0
tests/resources/attr/dir/file
Normal file
Binary file not shown.
0
tests/resources/attr/sub/dir/file
Normal file
0
tests/resources/attr/sub/dir/file
Normal file
0
tests/resources/attr/sub/sub/dir
Normal file
0
tests/resources/attr/sub/sub/dir
Normal file
Loading…
Reference in New Issue
Block a user