@@ -2278,3 +2278,50 @@ void test_diff_workdir__ignore_blank_lines(void)
22782278 git_patch_free (patch );
22792279 git_diff_free (diff );
22802280}
2281+
2282+ void test_diff_workdir__to_index_reversed_content_loads (void )
2283+ {
2284+ git_diff_options opts = GIT_DIFF_OPTIONS_INIT ;
2285+ git_diff * diff = NULL ;
2286+ diff_expects exp ;
2287+ int use_iterator ;
2288+ char * pathspec = "new_file" ;
2289+
2290+ g_repo = cl_git_sandbox_init ("status" );
2291+
2292+ opts .context_lines = 3 ;
2293+ opts .interhunk_lines = 1 ;
2294+ opts .flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED |
2295+ GIT_DIFF_SHOW_UNTRACKED_CONTENT | GIT_DIFF_REVERSE ;
2296+ opts .pathspec .strings = & pathspec ;
2297+ opts .pathspec .count = 1 ;
2298+
2299+ cl_git_pass (git_diff_index_to_workdir (& diff , g_repo , NULL , & opts ));
2300+
2301+ for (use_iterator = 0 ; use_iterator <= 1 ; use_iterator ++ ) {
2302+ memset (& exp , 0 , sizeof (exp ));
2303+
2304+ if (use_iterator )
2305+ cl_git_pass (diff_foreach_via_iterator (
2306+ diff , diff_file_cb , diff_binary_cb , diff_hunk_cb , diff_line_cb , & exp ));
2307+ else
2308+ cl_git_pass (git_diff_foreach (
2309+ diff , diff_file_cb , diff_binary_cb , diff_hunk_cb , diff_line_cb , & exp ));
2310+
2311+ cl_assert_equal_i (1 , exp .files );
2312+ cl_assert_equal_i (0 , exp .file_status [GIT_DELTA_ADDED ]);
2313+ cl_assert_equal_i (0 , exp .file_status [GIT_DELTA_DELETED ]);
2314+ cl_assert_equal_i (0 , exp .file_status [GIT_DELTA_MODIFIED ]);
2315+ cl_assert_equal_i (0 , exp .file_status [GIT_DELTA_IGNORED ]);
2316+ cl_assert_equal_i (1 , exp .file_status [GIT_DELTA_UNTRACKED ]);
2317+
2318+ cl_assert_equal_i (1 , exp .hunks );
2319+
2320+ cl_assert_equal_i (1 , exp .lines );
2321+ cl_assert_equal_i (0 , exp .line_ctxt );
2322+ cl_assert_equal_i (0 , exp .line_adds );
2323+ cl_assert_equal_i (1 , exp .line_dels );
2324+ }
2325+
2326+ git_diff_free (diff );
2327+ }
0 commit comments