Fix browse of empty repository

In an empty hg repository the Changeset c is null. This leads to an
NullPointerException in the original code. So we check whether we have
a Changeset and otherwise use the old functionality.
This commit is contained in:
Rene Pfeuffer
2019-11-15 09:50:28 +01:00
parent 2f5095e76a
commit cc4c4f0822

View File

@@ -77,7 +77,9 @@ public class HgBrowseCommand extends AbstractCommand implements BrowseCommand
String revision = MoreObjects.firstNonNull(request.getRevision(), "tip");
Changeset c = LogCommand.on(getContext().open()).rev(revision).limit(1).single();
cmd.rev(c.getNode());
if (c != null) {
cmd.rev(c.getNode());
}
if (!Strings.isNullOrEmpty(request.getPath()))
{
@@ -100,6 +102,6 @@ public class HgBrowseCommand extends AbstractCommand implements BrowseCommand
}
FileObject file = cmd.execute();
return new BrowserResult(c.getNode(), revision, file);
return new BrowserResult(c == null? "tip": c.getNode(), revision, file);
}
}