@@ -125,25 +125,17 @@ void testFileLogRethrowsNonMissingObjectWalkFailures() throws Exception {
125125 }
126126
127127 /**
128- * A Git whose successive log commands return the given iterables ; the underlying
128+ * A Git whose log command returns the given iterable ; the underlying
129129 * repository is real so that HEAD resolution works.
130130 */
131- @ SafeVarargs
132- private final Git gitWithLogs (Iterable <RevCommit >... iterables ) throws IOException , GitAPIException {
131+ private final Git gitWithLogs (Iterable <RevCommit > revCommits ) throws IOException , GitAPIException {
133132 Git mockGit = mock (Git .class );
134133 when (mockGit .getRepository ()).thenReturn (repository );
135- List <LogCommand > logCommands = new ArrayList <>();
136- for (Iterable <RevCommit > revCommits : iterables ) {
137- LogCommand logCommand = mock (LogCommand .class );
138- when (logCommand .add (any (ObjectId .class ))).thenReturn (logCommand );
139- when (logCommand .addPath (anyString ())).thenReturn (logCommand );
140- when (logCommand .call ()).thenReturn (revCommits );
141- logCommands .add (logCommand );
142- }
143- when (mockGit .log ())
144- .thenReturn (
145- logCommands .get (0 ),
146- logCommands .subList (1 , logCommands .size ()).toArray (new LogCommand [0 ]));
134+ LogCommand logCommand = mock (LogCommand .class );
135+ when (logCommand .add (any (ObjectId .class ))).thenReturn (logCommand );
136+ when (logCommand .addPath (anyString ())).thenReturn (logCommand );
137+ when (logCommand .call ()).thenReturn (revCommits );
138+ when (mockGit .log ()).thenReturn (logCommand );
147139 return mockGit ;
148140 }
149141
@@ -173,7 +165,8 @@ private ObjectId headId() throws IOException {
173165 }
174166
175167 @ Test
176- void testFileLogFallsBackToTotalCommitCountWhenFilteredWalkYieldsNothingDueToMissingObjects () throws Exception {
168+ void testFileLogReturnsOnlyVerifiedPartialPathHistoryWhenFilteredWalkYieldsNothingDueToMissingObjects ()
169+ throws Exception {
177170 String attributeHandler = "AttributeHandler.java" ;
178171 InputStream resourceAsStream = getClass ().getClassLoader ().getResourceAsStream (attributeHandler );
179172 writeFile (attributeHandler , convertInputStreamToString (resourceAsStream ));
@@ -183,21 +176,20 @@ void testFileLogFallsBackToTotalCommitCountWhenFilteredWalkYieldsNothingDueToMis
183176 Iterable <RevCommit > failingFilteredWalk = walkYieldingThenThrowing (
184177 Collections .emptyList (),
185178 new RevWalkException (new MissingObjectException (headId (), Constants .OBJ_TREE )));
186- Iterable <RevCommit > pathlessWalk = Collections .singletonList (onlyCommit );
187179
188- GitLogReader gitLogReader = new GitLogReader (gitWithLogs (failingFilteredWalk , pathlessWalk ));
180+ GitLogReader gitLogReader = new GitLogReader (gitWithLogs (failingFilteredWalk ));
189181
190182 ScmLogInfo scmLogInfo = Assertions .assertDoesNotThrow (() -> gitLogReader .fileLog (attributeHandler ));
191183
192- Assertions . assertEquals ( 1 , scmLogInfo . getCommitCount ());
193- Assertions . assertEquals ( onlyCommit . getCommitTime (), scmLogInfo . getEarliestCommit ());
194- Assertions .assertEquals (onlyCommit . getCommitTime () , scmLogInfo .getMostRecentCommit ());
184+ // When the filtered walk yields nothing due to missing objects, return only the verified partial results
185+ // (which in this case is zero commits) rather than falling back to total repository history
186+ Assertions .assertEquals (0 , scmLogInfo .getCommitCount ());
195187 }
196188
197189 @ Test
198- void testFileLogWithMissingTreeFallsBackToTotalCommitCount () throws Exception {
190+ void testFileLogReturnsOnlyVerifiedPartialPathHistoryWithMissingTree () throws Exception {
199191 // Simulates a shallow clone whose tree objects are missing: the filtered walk
200- // yields nothing, so fileLog falls back to the total (tree-independent) history.
192+ // may yield zero results due to missing objects, but should not fall back to total history.
201193 GitLogReader gitLogReader = new GitLogReader (git );
202194
203195 String attributeHandler = "AttributeHandler.java" ;
@@ -218,9 +210,9 @@ void testFileLogWithMissingTreeFallsBackToTotalCommitCount() throws Exception {
218210
219211 ScmLogInfo scmLogInfo = Assertions .assertDoesNotThrow (() -> gitLogReader .fileLog (attributeHandler ));
220212
221- Assertions . assertEquals ( 2 , scmLogInfo . getCommitCount ());
222- Assertions . assertEquals ( firstCommit . getCommitTime (), scmLogInfo . getEarliestCommit ());
223- Assertions .assertEquals (secondCommit . getCommitTime () , scmLogInfo .getMostRecentCommit ());
213+ // With missing tree objects, the filtered walk may yield zero verified partial results
214+ // rather than falling back to total repository history
215+ Assertions .assertEquals (0 , scmLogInfo .getCommitCount ());
224216 }
225217
226218 @ Test
0 commit comments