@@ -99,11 +99,11 @@ void test_index_tests__default_test_index(void)
99
99
entries = (git_index_entry * * )index -> entries .contents ;
100
100
101
101
for (i = 0 ; i < ARRAY_SIZE (test_entries ); ++ i ) {
102
- git_index_entry * e = entries [test_entries [i ].index ];
102
+ git_index_entry * e = entries [test_entries [i ].index ];
103
103
104
- cl_assert_equal_s (e -> path , test_entries [i ].path );
105
- cl_assert (e -> mtime .seconds == test_entries [i ].mtime );
106
- cl_assert (e -> file_size == test_entries [i ].file_size );
104
+ cl_assert_equal_s (e -> path , test_entries [i ].path );
105
+ cl_assert (e -> mtime .seconds == test_entries [i ].mtime );
106
+ cl_assert (e -> file_size == test_entries [i ].file_size );
107
107
}
108
108
109
109
git_index_free (index );
@@ -131,10 +131,10 @@ void test_index_tests__find_in_existing(void)
131
131
cl_git_pass (git_index_open (& index , TEST_INDEX_PATH ));
132
132
133
133
for (i = 0 ; i < ARRAY_SIZE (test_entries ); ++ i ) {
134
- size_t idx ;
134
+ size_t idx ;
135
135
136
- cl_assert (!git_index_find (& idx , index , test_entries [i ].path ));
137
- cl_assert (idx == test_entries [i ].index );
136
+ cl_assert (!git_index_find (& idx , index , test_entries [i ].path ));
137
+ cl_assert (idx == test_entries [i ].index );
138
138
}
139
139
140
140
git_index_free (index );
@@ -148,7 +148,7 @@ void test_index_tests__find_in_empty(void)
148
148
cl_git_pass (git_index_open (& index , "fake-index" ));
149
149
150
150
for (i = 0 ; i < ARRAY_SIZE (test_entries ); ++ i ) {
151
- cl_assert (GIT_ENOTFOUND == git_index_find (NULL , index , test_entries [i ].path ));
151
+ cl_assert (GIT_ENOTFOUND == git_index_find (NULL , index , test_entries [i ].path ));
152
152
}
153
153
154
154
git_index_free (index );
@@ -484,3 +484,53 @@ void test_index_tests__elocked(void)
484
484
git_index_free (index );
485
485
git_repository_free (repo );
486
486
}
487
+
488
+ void test_index_tests__reload_from_disk (void )
489
+ {
490
+ git_repository * repo ;
491
+ git_index * read_index ;
492
+ git_index * write_index ;
493
+
494
+ cl_set_cleanup (& cleanup_myrepo , NULL );
495
+
496
+ cl_git_pass (git_futils_mkdir ("./myrepo" , NULL , 0777 , GIT_MKDIR_PATH ));
497
+ cl_git_mkfile ("./myrepo/a.txt" , "a\n" );
498
+ cl_git_mkfile ("./myrepo/b.txt" , "b\n" );
499
+
500
+ cl_git_pass (git_repository_init (& repo , "./myrepo" , 0 ));
501
+ cl_git_pass (git_repository_index (& write_index , repo ));
502
+ cl_assert_equal_i (false, write_index -> on_disk );
503
+
504
+ cl_git_pass (git_index_open (& read_index , write_index -> index_file_path ));
505
+ cl_assert_equal_i (false, read_index -> on_disk );
506
+
507
+ /* Stage two new files agaisnt the write_index */
508
+ cl_git_pass (git_index_add_bypath (write_index , "a.txt" ));
509
+ cl_git_pass (git_index_add_bypath (write_index , "b.txt" ));
510
+
511
+ cl_assert_equal_sz (2 , git_index_entrycount (write_index ));
512
+
513
+ /* Persist the index changes to disk */
514
+ cl_git_pass (git_index_write (write_index ));
515
+ cl_assert_equal_i (true, write_index -> on_disk );
516
+
517
+ /* Sync the changes back into the read_index */
518
+ cl_assert_equal_sz (0 , git_index_entrycount (read_index ));
519
+
520
+ cl_git_pass (git_index_read (read_index ));
521
+ cl_assert_equal_i (true, read_index -> on_disk );
522
+
523
+ cl_assert_equal_sz (2 , git_index_entrycount (read_index ));
524
+
525
+ /* Remove the index file from the filesystem */
526
+ cl_git_pass (p_unlink (write_index -> index_file_path ));
527
+
528
+ /* Sync the changes back into the read_index */
529
+ cl_git_pass (git_index_read (read_index ));
530
+ cl_assert_equal_i (false, read_index -> on_disk );
531
+ cl_assert_equal_sz (0 , git_index_entrycount (read_index ));
532
+
533
+ git_index_free (read_index );
534
+ git_index_free (write_index );
535
+ git_repository_free (repo );
536
+ }
0 commit comments