@@ -43,84 +43,61 @@ struct compare_data
4343
4444static int add_and_check_file (void * payload , git_buf * actual_path )
4545{
46- git_buf expected_path_oid = GIT_BUF_INIT ;
46+ git_buf expected_path = GIT_BUF_INIT ;
4747 git_buf expected_path_fail = GIT_BUF_INIT ;
4848 git_buf expected_contents = GIT_BUF_INIT ;
4949 struct compare_data * cd = payload ;
50- bool failed = true;
51- int cmp_git , cmp_gitattributes ;
5250 char * basename ;
53- int add_bypath_ret ;
5451 const git_index_entry * entry ;
55- git_oid oid ;
56- git_error_state error = { 0 };
52+ git_blob * blob ;
5753
5854 basename = git_path_basename (actual_path -> ptr );
59- cmp_git = strcmp (basename , ".git" );
60- cmp_gitattributes = strcmp (basename , ".gitattributes" );
61-
62- if (cmp_git == 0 || cmp_gitattributes == 0 ) {
63- failed = false;
64- goto done ;
65- }
6655
67- giterr_clear ();
68- add_bypath_ret = git_index_add_bypath (g_index , basename );
69- giterr_state_capture (& error , add_bypath_ret );
56+ if (!strcmp (basename , ".git" ) || !strcmp (basename , ".gitattributes" ))
57+ return 0 ;
7058
71- entry = git_index_get_bypath (g_index , basename , 0 );
72- if (!add_bypath_ret && !entry )
73- goto done ;
59+ cl_git_pass (git_buf_joinpath (& expected_path , cd -> dirname , basename ));
7460
75- cl_git_pass (git_buf_joinpath (& expected_path_oid , cd -> dirname , basename ));
76- cl_git_pass (git_buf_joinpath (& expected_path_fail , cd -> dirname , basename ));
77- git_buf_puts (& expected_path_oid , ".obj" );
78- git_buf_puts (& expected_path_fail , ".fail" );
61+ cl_git_pass (git_buf_puts (& expected_path_fail , expected_path .ptr ));
62+ cl_git_pass (git_buf_puts (& expected_path_fail , ".fail" ));
7963
80- if (git_path_isfile (expected_path_oid .ptr )) {
81- if (add_bypath_ret )
82- goto done ;
64+ if (git_path_isfile (expected_path .ptr )) {
65+ cl_git_pass (git_index_add_bypath (g_index , basename ));
8366
84- if ( git_futils_readbuffer ( & expected_contents , expected_path_oid . ptr ) < 0 )
85- goto done ;
67+ cl_assert ( entry = git_index_get_bypath ( g_index , basename , 0 ));
68+ cl_git_pass ( git_blob_lookup ( & blob , g_repo , & entry -> id )) ;
8669
87- if (git_oid_fromstr (& oid , expected_contents .ptr ))
88- goto done ;
89- if (!git_oid_equal (& oid , & entry -> id ))
90- goto done ;
91- }
92-
93- if (git_path_isfile (expected_path_fail .ptr )) {
94- if (!add_bypath_ret )
95- goto done ;
96-
97- if (git_futils_readbuffer (& expected_contents , expected_path_fail .ptr ) < 0 )
98- goto done ;
70+ cl_git_pass (git_futils_readbuffer (& expected_contents , expected_path .ptr ));
71+ cl_assert_equal_s (expected_contents , git_blob_rawcontent (blob ));
9972
73+ git_blob_free (blob );
74+ } else if (git_path_isfile (expected_path_fail .ptr )) {
75+ cl_git_pass (git_futils_readbuffer (& expected_contents , expected_path_fail .ptr ));
10076 git_buf_rtrim (& expected_contents );
10177
102- if (error .error_msg .klass != GITERR_FILTER || strstr (error .error_msg .message , expected_contents .ptr ) == NULL )
103- goto done ;
78+ cl_git_fail (git_index_add_bypath (g_index , basename ));
79+ cl_assert_equal_i (GITERR_FILTER , giterr_last ()-> klass );
80+ cl_assert_equal_s (expected_contents .ptr , giterr_last ()-> message );
81+ } else {
82+ cl_fail ("unexpected index failure" );
10483 }
10584
10685 failed = false;
10786
10887done :
10988 if (failed ) {
11089 git_buf details = GIT_BUF_INIT ;
111- git_buf_printf (& details , "filename=%s, safecrlf =%s, autocrlf=%s, attrs={%s}" ,
112- git_path_basename ( actual_path -> ptr ) , cd -> safecrlf , cd -> autocrlf , cd -> attrs );
90+ git_buf_printf (& details , "filename=%s, system =%s, autocrlf=%s, safecrlf =%s, attrs={%s}" ,
91+ basename , cd -> systype , cd -> autocrlf , cd -> safecrlf , cd -> attrs );
11392 clar__fail (__FILE__ , __LINE__ ,
114- "adding file did not work as expected" , details .ptr , 0 );
115- git_buf_free (& details );
93+ "index contents did not match expected" , details .ptr , 0 );
94+ git_buf_dispose (& details );
11695 }
11796
11897 git__free (basename );
119- git_buf_free (& expected_contents );
120- git_buf_free (& expected_path_oid );
121- git_buf_free (& expected_path_fail );
122- giterr_state_free (& error );
123-
98+ git_buf_dispose (& expected_contents );
99+ git_buf_dispose (& expected_path );
100+ git_buf_dispose (& expected_path_fail );
124101 return 0 ;
125102}
126103
@@ -135,12 +112,12 @@ static void test_add_index(const char *safecrlf, const char *autocrlf, const cha
135112
136113 git_buf_puts (& reponame , "crlf" );
137114
138- git_buf_puts (& sandboxname , "safecrlf_" );
139- git_buf_puts (& sandboxname , safecrlf );
140-
141- git_buf_puts (& sandboxname , ",autocrlf_" );
115+ git_buf_puts (& sandboxname , "autocrlf_" );
142116 git_buf_puts (& sandboxname , autocrlf );
143117
118+ git_buf_puts (& sandboxname , ",safecrlf_" );
119+ git_buf_puts (& sandboxname , safecrlf );
120+
144121 if (* attrs ) {
145122 git_buf_puts (& sandboxname , "," );
146123
@@ -162,7 +139,7 @@ static void test_add_index(const char *safecrlf, const char *autocrlf, const cha
162139
163140 cl_git_pass (git_index_clear (g_index ));
164141
165- git_buf_joinpath (& expected_dirname , "crlf_data" , "checkin_results " );
142+ git_buf_joinpath (& expected_dirname , "crlf_data" , "posix_to_odb " );
166143 git_buf_joinpath (& expected_fixture , expected_dirname .ptr , sandboxname .ptr );
167144 cl_fixture_sandbox (expected_fixture .ptr );
168145
@@ -199,13 +176,18 @@ static void set_up_workingdir(const char *name)
199176 git_vector_free_deep (& contents );
200177
201178 /* copy input files */
202- git_path_dirload (& contents , cl_fixture ("crlf_data/checkin_input_files " ), 0 , 0 );
179+ git_path_dirload (& contents , cl_fixture ("crlf " ), 0 , 0 );
203180 git_vector_foreach (& contents , i , fn ) {
204181 char * basename = git_path_basename (fn );
205182 git_buf dest_filename = GIT_BUF_INIT ;
206- git_buf_joinpath (& dest_filename , name , basename );
183+
184+ if (strcmp (basename , ".gitted" ) &&
185+ strcmp (basename , ".gitattributes" )) {
186+ git_buf_joinpath (& dest_filename , name , basename );
187+ cl_git_pass (git_futils_cp (fn , dest_filename .ptr , 0644 ));
188+ }
189+
207190 git__free (basename );
208- cl_git_pass (git_futils_cp (fn , dest_filename .ptr , 0644 ));
209191 git_buf_free (& dest_filename );
210192 }
211193 git_vector_free_deep (& contents );
@@ -217,7 +199,7 @@ void test_index_crlf__matches_core_git(void)
217199 const char * autocrlf [] = { "true" , "false" , "input" , NULL };
218200 const char * attrs [] = { "" , "-crlf" , "-text" , "eol=crlf" , "eol=lf" ,
219201 "text" , "text eol=crlf" , "text eol=lf" ,
220- "text=auto" , "text=auto eol=crlf" , "text=auto eol=lf" ,
202+ "text=auto" , "text=auto eol=crlf" , "text=auto eol=lf" ,
221203 NULL };
222204 const char * * a , * * b , * * c ;
223205
0 commit comments