Files REST endpoint: Don't parse non-existing files
Rather fail with ResourceNotFoundException. This is e.g. important for the GetDiff REST endpoint as it returns an empty diff for non-existing files. As result the diff screen shows an empty diff for any non-existing file, but users expect to see an error. This change may break existing users of the extension API since the RevisionApi#file(String) is now throwing RestApiException. Change-Id: If0c172818b553129145f5ccd2f99e19b94472cce Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -52,6 +52,7 @@ import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.BinaryResult;
|
||||
import com.google.gerrit.extensions.restapi.ETagView;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
import com.google.gerrit.extensions.restapi.UnprocessableEntityException;
|
||||
import com.google.gerrit.reviewdb.client.Patch;
|
||||
import com.google.gerrit.server.change.GetRevisionActions;
|
||||
@@ -565,6 +566,19 @@ public class RevisionIT extends AbstractDaemonTest {
|
||||
assertThat(diff.metaB.lines).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void diffNonExistingFile() throws Exception {
|
||||
PushOneCommit.Result r = createChange();
|
||||
|
||||
exception.expect(ResourceNotFoundException.class);
|
||||
exception.expectMessage("non-existing");
|
||||
gApi.changes()
|
||||
.id(r.getChangeId())
|
||||
.revision(r.getCommit().name())
|
||||
.file("non-existing")
|
||||
.diff();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void diffOnMergeCommitChange() throws Exception {
|
||||
PushOneCommit.Result r = createMergeCommitChange("refs/for/master");
|
||||
|
||||
Reference in New Issue
Block a user