mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-14 01:15:44 +01:00
Fix not found error when reading empty hg repository
This commit is contained in:
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
|
|||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## Unreleased
|
||||||
|
### Fixed
|
||||||
|
- Not found error when using browse command in empty hg repository ([#1355](https://github.com/scm-manager/scm-manager/pull/1355))
|
||||||
|
|
||||||
## [2.6.0] - 2020-09-25
|
## [2.6.0] - 2020-09-25
|
||||||
### Added
|
### Added
|
||||||
- Add support for pr merge with prior rebase ([#1332](https://github.com/scm-manager/scm-manager/pull/1332))
|
- Add support for pr merge with prior rebase ([#1332](https://github.com/scm-manager/scm-manager/pull/1332))
|
||||||
|
|||||||
@@ -87,8 +87,8 @@ class HgFileviewCommandResultReader {
|
|||||||
if (stack.isEmpty()) {
|
if (stack.isEmpty()) {
|
||||||
// if the stack is empty, the requested path is probably a file
|
// if the stack is empty, the requested path is probably a file
|
||||||
return of(last);
|
return of(last);
|
||||||
} else if (stack.size() == 1 && stack.getFirst().isDirectory() && stack.getFirst().getChildren().isEmpty()) {
|
} else if (isEmptySubDirectory(stack)) {
|
||||||
// There are no empty directories in hg. When we get this,
|
// There are no empty directories in hg (except the root). When we get this,
|
||||||
// we just get the requested path as a directory, but it does not exist.
|
// we just get the requested path as a directory, but it does not exist.
|
||||||
return empty();
|
return empty();
|
||||||
} else {
|
} else {
|
||||||
@@ -100,6 +100,16 @@ class HgFileviewCommandResultReader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isEmptySubDirectory(Deque<FileObject> stack) {
|
||||||
|
if (stack.size() != 1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
final FileObject singleEntry = stack.getFirst();
|
||||||
|
return singleEntry.isDirectory()
|
||||||
|
&& singleEntry.getChildren().isEmpty()
|
||||||
|
&& !singleEntry.getName().isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
private FileObject read(HgInputStream stream) throws IOException {
|
private FileObject read(HgInputStream stream) throws IOException {
|
||||||
char type = (char) stream.read();
|
char type = (char) stream.read();
|
||||||
|
|
||||||
|
|||||||
@@ -269,6 +269,17 @@ class HgFileviewCommandResultReaderTest {
|
|||||||
assertThat(fileObject).isEmpty();
|
assertThat(fileObject).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldReturnEmptyRootDir() throws IOException {
|
||||||
|
HgFileviewCommandResultReader reader = new MockInput()
|
||||||
|
.dir("")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Optional<FileObject> fileObject = reader.parseResult();
|
||||||
|
|
||||||
|
assertThat(fileObject).isNotEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
private HgInputStream createInputStream(String input) {
|
private HgInputStream createInputStream(String input) {
|
||||||
return new HgInputStream(new ByteArrayInputStream(input.getBytes(UTF_8)), UTF_8.newDecoder());
|
return new HgInputStream(new ByteArrayInputStream(input.getBytes(UTF_8)), UTF_8.newDecoder());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user