Skip to content

Commit 0eaf204

Browse files
authored
fix(service): fix working on branches in the core-svc (#3472)
1 parent 5730ce5 commit 0eaf204

19 files changed

+63
-72
lines changed

renku/ui/service/cache/models/job.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class Job(Model):
4343
state = TextField()
4444
extras = JSONField()
4545
client_extras = TextField()
46+
branch = TextField()
4647

4748
ctrl_context = JSONField()
4849
ctrl_result = JSONField()

renku/ui/service/controllers/api/mixins.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ def execute_op(self):
169169
"git_url": self.request_data["git_url"],
170170
}
171171

172-
if "ref" in self.request_data:
173-
clone_context["ref"] = self.request_data["ref"]
172+
if "branch" in self.request_data:
173+
clone_context["branch"] = self.request_data["branch"]
174174

175175
# NOTE: If we want to migrate project, then we need to do full clone.
176176
# This operation can take very long time, and as such is expected
@@ -185,27 +185,27 @@ def execute_op(self):
185185
if not project.initialized:
186186
raise UninitializedProject(project.abs_path)
187187
else:
188-
ref = self.request_data.get("ref", None)
188+
branch = self.request_data.get("branch", None)
189189

190-
if ref:
190+
if branch:
191191
with Repository(project.abs_path) as repository:
192-
if ref != repository.active_branch.name:
192+
if branch != repository.active_branch.name:
193193
# NOTE: Command called for different branch than the one used in cache, change branch
194194
if len(repository.remotes) != 1:
195195
raise RenkuException("Couldn't find remote for project in cache.")
196196
origin = repository.remotes[0]
197-
remote_branch = f"{origin}/{ref}"
197+
remote_branch = f"{origin}/{branch}"
198198

199199
with project.write_lock():
200-
# NOTE: Add new ref to remote branches
201-
repository.run_git_command("remote", "set-branches", "--add", origin, ref)
200+
# NOTE: Add new branch to remote branches
201+
repository.run_git_command("remote", "set-branches", "--add", origin, branch)
202202
if self.migrate_project or self.clone_depth == PROJECT_CLONE_NO_DEPTH:
203-
repository.fetch(origin, ref)
203+
repository.fetch(origin, branch)
204204
else:
205-
repository.fetch(origin, ref, depth=self.clone_depth)
205+
repository.fetch(origin, branch, depth=self.clone_depth)
206206

207207
# NOTE: Switch to new ref
208-
repository.run_git_command("checkout", "--track", "-f", "-b", ref, remote_branch)
208+
repository.run_git_command("checkout", "--track", "-f", "-b", branch, remote_branch)
209209

210210
# NOTE: cleanup remote branches in case a remote was deleted (fetch fails otherwise)
211211
repository.run_git_command("remote", "prune", origin)

renku/ui/service/controllers/cache_migrations_check.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def _fast_op_without_cache(self):
6666
],
6767
tempdir_path,
6868
remote=self.ctx["git_url"],
69-
ref=self.request_data.get("ref", None),
69+
branch=self.request_data.get("branch", None),
7070
token=self.user_data.get("token", None),
7171
)
7272
with renku_project_context(tempdir_path):

renku/ui/service/controllers/templates_create_project.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def default_metadata(self):
6565

6666
metadata = {
6767
"__template_source__": self.ctx["git_url"],
68-
"__template_ref__": self.ctx["ref"],
68+
"__template_ref__": self.ctx["branch"],
6969
"__template_id__": self.ctx["identifier"],
7070
"__namespace__": self.ctx["project_namespace"],
7171
"__repository__": self.ctx["project_repository"],
@@ -115,7 +115,7 @@ def setup_new_project(self):
115115

116116
def setup_template(self):
117117
"""Reads template manifest."""
118-
templates_source = fetch_templates_source(source=self.ctx["git_url"], reference=self.ctx["ref"])
118+
templates_source = fetch_templates_source(source=self.ctx["git_url"], reference=self.ctx["branch"])
119119
identifier = self.ctx["identifier"]
120120
try:
121121
self.template = templates_source.get_template(id=identifier, reference=None)

renku/ui/service/controllers/templates_read_manifest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def template_manifest(self):
5050
"""Reads template manifest."""
5151
from PIL import Image
5252

53-
templates_source = fetch_templates_source(source=self.ctx["git_url"], reference=self.ctx["ref"])
53+
templates_source = fetch_templates_source(source=self.ctx["git_url"], reference=self.ctx["branch"])
5454
manifest = templates_source.manifest.get_raw_content()
5555

5656
# NOTE: convert icons to base64

renku/ui/service/controllers/utils/project_clone.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def user_project_clone(cache, user_data, project_data):
7373
"user.email": project_data["email"],
7474
"pull.rebase": False,
7575
},
76-
checkout_revision=project_data["ref"],
76+
checkout_revision=project_data["branch"],
7777
)
7878
).output
7979
project.save()

renku/ui/service/controllers/utils/remote_project.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def __init__(self, user_data, request_data):
4545
self.ctx = ProjectCloneContext().load({**user_data, **request_data}, unknown=EXCLUDE)
4646

4747
self.git_url = self.ctx["url_with_auth"]
48-
self.branch = self.ctx["ref"]
48+
self.branch = self.ctx["branch"]
4949

5050
@property
5151
def remote_url(self):

renku/ui/service/gateways/gitlab_api_provider.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ def download_files_from_api(
4747
target_folder: Union[Path, str],
4848
remote: str,
4949
token: str,
50-
ref: Optional[str] = None,
50+
branch: Optional[str] = None,
5151
):
5252
"""Download files through a remote Git API."""
53-
if not ref:
54-
ref = "HEAD"
53+
if not branch:
54+
branch = "HEAD"
5555

5656
target_folder = Path(target_folder)
5757

@@ -82,7 +82,7 @@ def download_files_from_api(
8282

8383
try:
8484
with open(full_path, "wb") as f:
85-
project.files.raw(file_path=str(path), ref=ref, streamed=True, action=f.write)
85+
project.files.raw(file_path=str(path), ref=branch, streamed=True, action=f.write)
8686

8787
result_paths.append(full_path)
8888
except gitlab.GitlabGetError:

renku/ui/service/interfaces/git_api_provider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def download_files_from_api(
3030
target_folder: Union[Path, str],
3131
remote: str,
3232
token: str,
33-
ref: Optional[str] = None,
33+
branch: Optional[str] = None,
3434
):
3535
"""Download files through a remote Git API."""
3636
raise NotImplementedError()

renku/ui/service/serializers/cache.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ class RepositoryCloneRequest(RemoteRepositorySchema):
131131
"""Request schema for repository clone."""
132132

133133
depth = fields.Integer(metadata={"description": "Git fetch depth"}, load_default=PROJECT_CLONE_DEPTH_DEFAULT)
134-
ref = fields.String(metadata={"description": "Repository reference (branch, commit or tag)"}, load_default=None)
135134

136135

137136
class ProjectCloneContext(RepositoryCloneRequest):
@@ -240,18 +239,6 @@ class ProjectMigrateRequest(AsyncSchema, LocalRepositorySchema, RemoteRepository
240239
skip_docker_update = fields.Boolean(dump_default=False)
241240
skip_migrations = fields.Boolean(dump_default=False)
242241

243-
@pre_load()
244-
def handle_ref(self, data, **kwargs):
245-
"""Handle ref and branch."""
246-
247-
# Backward compatibility: branch and ref were both used. Let's keep branch as the exposed field
248-
# even if interally it gets converted to "ref" later.
249-
if data.get("ref"):
250-
data["branch"] = data["ref"]
251-
del data["ref"]
252-
253-
return data
254-
255242

256243
class ProjectMigrateResponse(RenkuSyncSchema):
257244
"""Response schema for project migrate."""

0 commit comments

Comments
 (0)