@@ -351,3 +351,55 @@ void test_attr_repo__sysdir_with_session(void)
351351 git_buf_dispose (& sysdir );
352352 git_attr_session__free (& session );
353353}
354+
355+ void test_attr_repo__rewrite (void )
356+ {
357+ const char * value ;
358+
359+ cl_git_rewritefile ("attr/.gitattributes" , "file.txt foo=first\n" );
360+ cl_git_pass (git_attr_get (& value , g_repo , 0 , "file.txt" , "foo" ));
361+ cl_assert_equal_s (value , "first" );
362+
363+ cl_git_rewritefile ("attr/.gitattributes" , "file.txt foo=second\n" );
364+ cl_git_pass (git_attr_get (& value , g_repo , 0 , "file.txt" , "foo" ));
365+ cl_assert_equal_s (value , "second" );
366+
367+ cl_git_rewritefile ("attr/.gitattributes" , "file.txt other=value\n" );
368+ cl_git_pass (git_attr_get (& value , g_repo , 0 , "file.txt" , "foo" ));
369+ cl_assert_equal_p (value , NULL );
370+ }
371+
372+ void test_attr_repo__rewrite_sysdir (void )
373+ {
374+ git_buf sysdir = GIT_BUF_INIT ;
375+ const char * value ;
376+
377+ cl_git_pass (p_mkdir ("system" , 0777 ));
378+ cl_git_pass (git_buf_joinpath (& sysdir , clar_sandbox_path (), "system" ));
379+ cl_git_pass (git_sysdir_set (GIT_SYSDIR_SYSTEM , sysdir .ptr ));
380+ g_repo = cl_git_sandbox_reopen ();
381+
382+ cl_git_rewritefile ("system/gitattributes" , "file foo=first" );
383+ cl_git_pass (git_attr_get (& value , g_repo , 0 , "file" , "foo" ));
384+ cl_assert_equal_s (value , "first" );
385+
386+ cl_git_rewritefile ("system/gitattributes" , "file foo=second" );
387+ cl_git_pass (git_attr_get (& value , g_repo , 0 , "file" , "foo" ));
388+ cl_assert_equal_s (value , "second" );
389+
390+ git_buf_dispose (& sysdir );
391+ }
392+
393+ void test_attr_repo__unlink (void )
394+ {
395+ const char * value ;
396+
397+ cl_git_rewritefile ("attr/.gitattributes" , "file.txt foo=value1\n" );
398+ cl_git_pass (git_attr_get (& value , g_repo , 0 , "file.txt" , "foo" ));
399+ cl_assert_equal_s (value , "value1" );
400+
401+ cl_git_pass (p_unlink ("attr/.gitattributes" ));
402+
403+ cl_git_pass (git_attr_get (& value , g_repo , 0 , "file.txt" , "foo" ));
404+ cl_assert_equal_p (value , NULL );
405+ }
0 commit comments