22#include "fileops.h"
33#include "git2/attr.h"
44#include "attr.h"
5+ #include "sysdir.h"
56
67#include "attr_expect.h"
78#include "git2/sys/repository.h"
@@ -17,6 +18,7 @@ void test_attr_repo__cleanup(void)
1718{
1819 cl_git_sandbox_cleanup ();
1920 g_repo = NULL ;
21+ cl_sandbox_set_search_path_defaults ();
2022}
2123
2224static struct attr_expected get_one_test_cases [] = {
@@ -376,3 +378,46 @@ void test_attr_repo__bare_repo_with_index(void)
376378 cl_assert (GIT_ATTR_IS_FALSE (values [2 ]));
377379 cl_assert (GIT_ATTR_IS_UNSPECIFIED (values [3 ]));
378380}
381+
382+ void test_attr_repo__sysdir (void )
383+ {
384+ git_buf sysdir = GIT_BUF_INIT ;
385+ const char * value ;
386+
387+ cl_git_pass (p_mkdir ("system" , 0777 ));
388+ cl_git_rewritefile ("system/gitattributes" , "file merge=foo" );
389+ cl_git_pass (git_buf_joinpath (& sysdir , clar_sandbox_path (), "system" ));
390+ cl_git_pass (git_sysdir_set (GIT_SYSDIR_SYSTEM , sysdir .ptr ));
391+ g_repo = cl_git_sandbox_reopen ();
392+
393+ cl_git_pass (git_attr_get (& value , g_repo , 0 , "file" , "merge" ));
394+ cl_assert_equal_s (value , "foo" );
395+
396+ cl_git_pass (p_unlink ("system/gitattributes" ));
397+ cl_git_pass (p_rmdir ("system" ));
398+ git_buf_dispose (& sysdir );
399+ }
400+
401+ void test_attr_repo__sysdir_with_session (void )
402+ {
403+ const char * values [2 ], * attrs [2 ] = { "foo" , "bar" };
404+ git_buf sysdir = GIT_BUF_INIT ;
405+ git_attr_session session ;
406+
407+ cl_git_pass (p_mkdir ("system" , 0777 ));
408+ cl_git_rewritefile ("system/gitattributes" , "file foo=1 bar=2" );
409+ cl_git_pass (git_buf_joinpath (& sysdir , clar_sandbox_path (), "system" ));
410+ cl_git_pass (git_sysdir_set (GIT_SYSDIR_SYSTEM , sysdir .ptr ));
411+ g_repo = cl_git_sandbox_reopen ();
412+
413+ cl_git_pass (git_attr_session__init (& session , g_repo ));
414+ cl_git_pass (git_attr_get_many_with_session (values , g_repo , & session , 0 , "file" , ARRAY_SIZE (attrs ), attrs ));
415+
416+ cl_assert_equal_s (values [0 ], "1" );
417+ cl_assert_equal_s (values [1 ], "2" );
418+
419+ cl_git_pass (p_unlink ("system/gitattributes" ));
420+ cl_git_pass (p_rmdir ("system" ));
421+ git_buf_dispose (& sysdir );
422+ git_attr_session__free (& session );
423+ }
0 commit comments