mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-16 18:26:16 +01:00
Store repository id in native config file
Hooks can read this repository type dependant config file and handle the changes for the correct repository id
This commit is contained in:
@@ -183,26 +183,6 @@ public class XmlRepositoryDAO
|
||||
.orElseThrow(() -> new InternalRepositoryException(repository, "could not find base directory for repository")));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Repository getRepositoryForDirectory(File path) {
|
||||
for (RepositoryPath p : db.values()) {
|
||||
if (toRealPath(path.toPath()).startsWith(toRealPath(context.getBaseDirectory().toPath().resolve(p.getPath())))) {
|
||||
return p.getRepository();
|
||||
}
|
||||
}
|
||||
throw new NotFoundException("directory", path.getPath());
|
||||
}
|
||||
|
||||
private Path toRealPath(Path path) {
|
||||
try {
|
||||
// resolve links and other indirections
|
||||
// (see issue #82, https://bitbucket.org/sdorra/scm-manager/issues/82/symbolic-link-in-hg-repository-path)
|
||||
return path.toRealPath();
|
||||
} catch (IOException e) {
|
||||
throw new InternalRepositoryException(entity("directory", path.toString()), "could not get Path$toRealPath for path: " + path);
|
||||
}
|
||||
}
|
||||
|
||||
private Optional<RepositoryPath> findExistingRepositoryPath(Repository repository) {
|
||||
return db.values().stream()
|
||||
.filter(repoPath -> repoPath.getId().equals(repository.getId()))
|
||||
|
||||
@@ -106,48 +106,4 @@ public class XmlRepositoryDAOTest {
|
||||
|
||||
assertThat(path.toString()).isEqualTo("/tmp/path");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFindRepositoryForRelativePath() {
|
||||
new File(context.getBaseDirectory(), "relative/path/data").mkdirs();
|
||||
Repository existingRepository = new Repository("id", "old", null, null);
|
||||
RepositoryPath repositoryPath = new RepositoryPath("relative/path", "id", existingRepository);
|
||||
when(db.values()).thenReturn(asList(repositoryPath));
|
||||
|
||||
XmlRepositoryDAO dao = new XmlRepositoryDAO(storeFactory, new InitialRepositoryLocationResolver(context), fileSystem, context);
|
||||
|
||||
Repository repository = dao.getRepositoryForDirectory(new File(context.getBaseDirectory(), "relative/path/data"));
|
||||
|
||||
assertThat(repository).isSameAs(existingRepository);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFindRepositoryForAbsolutePath() throws IOException {
|
||||
Repository existingRepository = new Repository("id", "old", null, null);
|
||||
File folder = temporaryFolder.newFolder("somewhere", "data");
|
||||
RepositoryPath repositoryPath = new RepositoryPath(folder.getParent(), "id", existingRepository);
|
||||
when(db.values()).thenReturn(asList(repositoryPath));
|
||||
|
||||
XmlRepositoryDAO dao = new XmlRepositoryDAO(storeFactory, new InitialRepositoryLocationResolver(context), fileSystem, context);
|
||||
|
||||
Repository repository = dao.getRepositoryForDirectory(folder);
|
||||
|
||||
assertThat(repository).isSameAs(existingRepository);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFindRepositoryForLinks() throws IOException {
|
||||
Repository existingRepository = new Repository("id", "old", null, null);
|
||||
File folder = temporaryFolder.newFolder("somewhere", "else", "data");
|
||||
File link = new File(folder.getParentFile().getParentFile(), "link");
|
||||
Files.createSymbolicLink(link.toPath(), folder.getParentFile().toPath());
|
||||
RepositoryPath repositoryPath = new RepositoryPath(new File(link, "data").getPath(), "id", existingRepository);
|
||||
when(db.values()).thenReturn(asList(repositoryPath));
|
||||
|
||||
XmlRepositoryDAO dao = new XmlRepositoryDAO(storeFactory, new InitialRepositoryLocationResolver(context), fileSystem, context);
|
||||
|
||||
Repository repository = dao.getRepositoryForDirectory(folder);
|
||||
|
||||
assertThat(repository).isSameAs(existingRepository);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user