diff --git a/renku/core/commands/providers/renku.py b/renku/core/commands/providers/renku.py index fd9ba4fe90..69ad0397dc 100644 --- a/renku/core/commands/providers/renku.py +++ b/renku/core/commands/providers/renku.py @@ -62,7 +62,7 @@ def find_record(self, uri, client=None): self._prepare_authentication(client, uri) - initial_identifier, kg_urls = self._get_dataset_info(uri) + same_as, initial_identifier, kg_urls = self._get_dataset_info(uri) project_url = None failed_urls = [] @@ -77,7 +77,14 @@ def find_record(self, uri, client=None): datasets = self._query_knowledge_graph(project_datasets_kg_url) - dataset_name = next(ds["name"] for ds in datasets if ds["versions"].get("initial") == initial_identifier) + dataset_name = next( + (ds["name"] for ds in datasets if ds["versions"].get("initial") == initial_identifier), None + ) + if not dataset_name and same_as: + dataset_name = next((ds["name"] for ds in datasets if ds.get("sameAs") == same_as), None) + + if not dataset_name: + continue # Check if we can clone the project for url in (ssh_url, https_url): @@ -144,6 +151,7 @@ def _get_dataset_info(self, uri): response = self._query_knowledge_graph(kg_url) initial_identifier = response.get("versions", {}).get("initial") + same_as = response.get("sameAs") if project_id: kg_path = f"/knowledge-graph/{project_id.strip('/')}" @@ -160,7 +168,7 @@ def get_project_link(project): kg_urls = [get_project_link(p) for p in projects] kg_urls = [u for u in kg_urls if u] - return initial_identifier, kg_urls + return same_as, initial_identifier, kg_urls @staticmethod def _extract_project_and_dataset_ids(parsed_url): diff --git a/renku/core/management/datasets.py b/renku/core/management/datasets.py index 67df7afca1..894041662a 100644 --- a/renku/core/management/datasets.py +++ b/renku/core/management/datasets.py @@ -784,7 +784,7 @@ def _add_from_git(self, url, sources, destination, ref): if remote_client._is_external_file(src): operation = (src.resolve(), dst, "symlink") else: - operation = (src, dst, "copy") + operation = (src, dst, "move") results.append( { @@ -1237,6 +1237,7 @@ def checkout(repo, ref): except GitCommandError: raise errors.ParameterError('Cannot find reference "{}" in Git repository: {}'.format(ref, url)) + depth = 1 if not ref else None ref = ref or renku_branch u = GitURL.parse(url) path = u.pathname @@ -1251,6 +1252,7 @@ def checkout(repo, ref): repo = Repo(str(repo_path)) if repo.remotes.origin.url == url: try: + repo.git.checkout(".") repo.git.fetch(all=True) repo.git.checkout(ref) try: @@ -1269,7 +1271,7 @@ def checkout(repo, ref): except PermissionError: raise errors.InvalidFileOperation("Cannot delete files in {}: Permission denied".format(repo_path)) - repo, _ = clone(url, path=str(repo_path), install_githooks=False) + repo, _ = clone(url, path=str(repo_path), install_githooks=False, depth=depth) # Because the name of the default branch is not always 'master', we # create an alias of the default branch when cloning the repo. It