From e68c178c8601f5d53c05064d65cda780fc4eb33a Mon Sep 17 00:00:00 2001 From: Eduard Heimbuch Date: Wed, 28 Jul 2021 11:22:37 +0200 Subject: [PATCH] Fix hg fileview resolves for same path on file and directory (#1746) If a file and a directory with the same name existed somewhere at the same level in a Mercurial repository, our logic in the fileview command failed to collect them. The parent of the file was mistaken for the entire file path, resulting in confusing errors that the file could not be found in the manifest. With this fix, file detection should now be more secure than before. Co-authored-by: Sebastian Sdorra --- gradle/changelog/hg_fileview_command.yaml | 2 ++ .../main/resources/sonia/scm/python/fileview.py | 2 +- .../resources/sonia/scm/python/fileview_test.py | 15 +++++++++++++++ .../src/repos/sources/containers/Sources.tsx | 6 +++++- 4 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 gradle/changelog/hg_fileview_command.yaml diff --git a/gradle/changelog/hg_fileview_command.yaml b/gradle/changelog/hg_fileview_command.yaml new file mode 100644 index 0000000000..3d69ff6dd2 --- /dev/null +++ b/gradle/changelog/hg_fileview_command.yaml @@ -0,0 +1,2 @@ +- type: Fixed + description: Fix file detection on hg fileview command ([#1746](https://github.com/scm-manager/scm-manager/pull/1746)) diff --git a/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/python/fileview.py b/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/python/fileview.py index 0ee335561e..8eca8bdb68 100644 --- a/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/python/fileview.py +++ b/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/python/fileview.py @@ -58,7 +58,7 @@ class File_Collector: def collect(self, paths, path = "", dir_only = False): for p in paths: - if p.startswith(path): + if p.startswith(path + b"/") or path == b"": self.attach(self.extract_name_without_parent(path, p), self.structure, dir_only) def attach(self, branch, trunk, dir_only = False): diff --git a/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/python/fileview_test.py b/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/python/fileview_test.py index 946e6130bb..c32023acc6 100644 --- a/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/python/fileview_test.py +++ b/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/python/fileview_test.py @@ -186,6 +186,21 @@ class Test_File_Viewer(unittest.TestCase): d = collector[0][1] self.assertDirectory(d, "d") + # https://github.com/scm-manager/scm-manager/issues/1719 + def test_with_folder_and_file_same_name(self): + files = ["folder/ThisIsIt/ThisIsIt.sln", "folder/ThisIsIt/ThisIsIt/ThisIsIt.csproj"] + root = self.collect(files) + self.assertChildren(root, ["folder"]) + + root = self.collect(files, "folder") + self.assertChildren(root, ["folder/ThisIsIt"]) + + root = self.collect(files, "folder/ThisIsIt") + self.assertChildren(root, ["folder/ThisIsIt/ThisIsIt", "folder/ThisIsIt/ThisIsIt.sln"]) + + root = self.collect(files, "folder/ThisIsIt/ThisIsIt") + self.assertChildren(root, ["folder/ThisIsIt/ThisIsIt/ThisIsIt.csproj"]) + def collect(self, paths, path = "", recursive = False): revCtx = DummyRevContext(paths) diff --git a/scm-ui/ui-webapp/src/repos/sources/containers/Sources.tsx b/scm-ui/ui-webapp/src/repos/sources/containers/Sources.tsx index 4a8fdfc0f3..da8c42ef98 100644 --- a/scm-ui/ui-webapp/src/repos/sources/containers/Sources.tsx +++ b/scm-ui/ui-webapp/src/repos/sources/containers/Sources.tsx @@ -26,7 +26,7 @@ import { useTranslation } from "react-i18next"; import { useHistory, useLocation, useParams } from "react-router-dom"; import { useSources } from "@scm-manager/ui-api"; import { Branch, Repository } from "@scm-manager/ui-types"; -import { Breadcrumb, Loading, Notification } from "@scm-manager/ui-components"; +import { Breadcrumb, ErrorNotification, Loading, Notification } from "@scm-manager/ui-components"; import FileTree from "../components/FileTree"; import Content from "./Content"; import CodeActionBar from "../../codeSection/components/CodeActionBar"; @@ -80,6 +80,10 @@ const Sources: FC = ({ repository, branches, selectedBranch, baseUrl }) = enabled: !branches || !!selectedBranch, }); + if (error) { + return ; + } + if (isLoading || (!error && !file)) { return ; }