Don't crash in GetAccess if refs/meta/config is missing
Change-Id: I6ad1b9802d104d2dac4fc4d20f9478bfde5bccdf
This commit is contained in:
@@ -156,13 +156,16 @@ public class GetAccess implements RestReadView<ProjectResource> {
|
||||
config = ProjectConfig.read(md);
|
||||
info.configWebLinks = new ArrayList<>();
|
||||
|
||||
// WebLinks operates in terms of the data types used in the GWT UI. Once the GWT UI is gone,
|
||||
// WebLinks should be fixed to use the extension data types.
|
||||
// config may have a null revision if the repo doesn't have its own refs/meta/config.
|
||||
if (config.getRevision() != null) {
|
||||
// WebLinks operates in terms of the data types used in the GWT UI. Once the GWT UI is
|
||||
// gone, WebLinks should be fixed to use the extension data types.
|
||||
for (WebLinkInfoCommon wl :
|
||||
webLinks.getFileHistoryLinks(
|
||||
projectName.get(), config.getRevision().getName(), ProjectConfig.PROJECT_CONFIG)) {
|
||||
info.configWebLinks.add(new WebLinkInfo(wl.name, wl.imageUrl, wl.url, wl.target));
|
||||
}
|
||||
}
|
||||
|
||||
if (config.updateGroupNames(groupBackend)) {
|
||||
md.setMessage("Update group names\n");
|
||||
|
||||
@@ -52,6 +52,9 @@ import org.eclipse.jgit.internal.storage.dfs.InMemoryRepository;
|
||||
import org.eclipse.jgit.junit.TestRepository;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.eclipse.jgit.lib.Constants;
|
||||
import org.eclipse.jgit.lib.RefUpdate;
|
||||
import org.eclipse.jgit.lib.RefUpdate.Result;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -83,17 +86,15 @@ public class AccessIT extends AbstractDaemonTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void webLinks() throws Exception {
|
||||
public void webLink() throws Exception {
|
||||
RegistrationHandle handle =
|
||||
fileHistoryWebLinkDynamicSet.add(
|
||||
new FileHistoryWebLink() {
|
||||
@Override
|
||||
public WebLinkInfo getFileHistoryWebLink(
|
||||
String projectName, String revision, String fileName) {
|
||||
WebLinkInfo info =
|
||||
new WebLinkInfo(
|
||||
return new WebLinkInfo(
|
||||
"name", "imageURL", "http://view/" + projectName + "/" + fileName);
|
||||
return info;
|
||||
}
|
||||
});
|
||||
try {
|
||||
@@ -106,6 +107,30 @@ public class AccessIT extends AbstractDaemonTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void webLinkNoRefsMetaConfig() throws Exception {
|
||||
RegistrationHandle handle =
|
||||
fileHistoryWebLinkDynamicSet.add(
|
||||
new FileHistoryWebLink() {
|
||||
@Override
|
||||
public WebLinkInfo getFileHistoryWebLink(
|
||||
String projectName, String revision, String fileName) {
|
||||
return new WebLinkInfo(
|
||||
"name", "imageURL", "http://view/" + projectName + "/" + fileName);
|
||||
}
|
||||
});
|
||||
try (Repository repo = repoManager.openRepository(new Project.NameKey(newProjectName))) {
|
||||
RefUpdate u = repo.updateRef(RefNames.REFS_CONFIG);
|
||||
u.setForceUpdate(true);
|
||||
assertThat(u.delete()).isEqualTo(Result.FORCED);
|
||||
|
||||
// This should not crash.
|
||||
pApi.access();
|
||||
} finally {
|
||||
handle.remove();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addAccessSection() throws Exception {
|
||||
Project.NameKey p = new Project.NameKey(newProjectName);
|
||||
|
||||
Reference in New Issue
Block a user