BlenderBIM operator to add remote repo (#3096)

Procedure to merge a pull request would be: Add Remote, select the added
remote in the pull-down, Fetch from remote, select the added remote
branch in the pull-down, Merge, delete remote
This commit is contained in:
Bruno Postle
2023-06-10 22:04:01 +01:00
parent 4806b9a260
commit a71b5e1f11
6 changed files with 56 additions and 1 deletions
@@ -21,6 +21,7 @@ from . import ui, prop, operator
classes = ( classes = (
operator.AddFileToRepo, operator.AddFileToRepo,
operator.AddRemote,
operator.AddTag, operator.AddTag,
operator.CloneRepo, operator.CloneRepo,
operator.CommitChanges, operator.CommitChanges,
@@ -82,6 +82,7 @@ class CloneRepo(bpy.types.Operator):
props = context.scene.IfcGitProperties props = context.scene.IfcGitProperties
core.clone_repo(tool.IfcGit, props.remote_url, props.local_folder, self) core.clone_repo(tool.IfcGit, props.remote_url, props.local_folder, self)
props.remote_url = ""
refresh() refresh()
return {"FINISHED"} return {"FINISHED"}
@@ -303,6 +304,36 @@ class Fetch(bpy.types.Operator):
return {"FINISHED"} return {"FINISHED"}
class AddRemote(bpy.types.Operator):
"""Add a remote repository"""
bl_label = "Add Remote"
bl_idname = "ifcgit.add_remote"
bl_options = {"REGISTER"}
@classmethod
def poll(cls, context):
IfcGitData.make_sure_is_loaded()
props = context.scene.IfcGitProperties
repo = IfcGitData.data["repo"]
if (
not repo
or not tool.IfcGit.is_valid_ref_format(props.remote_name)
or props.remote_name in [remote.name for remote in repo.remotes]
or not props.remote_url
):
return False
return True
def execute(self, context):
repo = IfcGitData.data["repo"]
core.add_remote(tool.IfcGit, repo)
bpy.ops.ifcgit.refresh()
refresh()
return {"FINISHED"}
class DeleteRemote(bpy.types.Operator): class DeleteRemote(bpy.types.Operator):
"""Delete the selected remote""" """Delete the selected remote"""
@@ -312,7 +343,6 @@ class DeleteRemote(bpy.types.Operator):
def execute(self, context): def execute(self, context):
props = context.scene.IfcGitProperties
repo = IfcGitData.data["repo"] repo = IfcGitData.data["repo"]
core.delete_remote(tool.IfcGit, repo) core.delete_remote(tool.IfcGit, repo)
bpy.ops.ifcgit.refresh() bpy.ops.ifcgit.refresh()
@@ -113,6 +113,11 @@ class IfcGitProperties(PropertyGroup):
description="An optional human readable description of this tag", description="An optional human readable description of this tag",
default="", default="",
) )
remote_name: StringProperty(
name="New remote name",
description="A local name for a remote Git repository",
default="",
)
remote_url: StringProperty( remote_url: StringProperty(
name="Git URL", name="Git URL",
description="A URL pointing to a Git repository", description="A URL pointing to a Git repository",
@@ -171,6 +171,14 @@ class IFCGIT_PT_panel(bpy.types.Panel):
row.operator("ifcgit.push", icon="EXPERIMENTAL") row.operator("ifcgit.push", icon="EXPERIMENTAL")
row.operator("ifcgit.fetch", icon="IMPORT") row.operator("ifcgit.fetch", icon="IMPORT")
box = layout.box()
row = box.row()
row.prop(props, "remote_name")
row = box.row()
row.prop(props, "remote_url")
row = box.row()
row.operator("ifcgit.add_remote", icon="IMPORT")
class COMMIT_UL_List(bpy.types.UIList): class COMMIT_UL_List(bpy.types.UIList):
"""List of Git commits""" """List of Git commits"""
+4
View File
@@ -42,6 +42,10 @@ def delete_tag(ifcgit, repo, tag_name):
ifcgit.delete_tag(repo, tag_name) ifcgit.delete_tag(repo, tag_name)
def add_remote(ifcgit, repo):
ifcgit.add_remote(repo)
def delete_remote(ifcgit, repo): def delete_remote(ifcgit, repo):
ifcgit.delete_remote(repo) ifcgit.delete_remote(repo)
+7
View File
@@ -102,6 +102,13 @@ class IfcGit:
if tag_name in repo.tags: if tag_name in repo.tags:
repo.delete_tag(tag_name) repo.delete_tag(tag_name)
@classmethod
def add_remote(cls, repo):
props = bpy.context.scene.IfcGitProperties
repo.create_remote(name=props.remote_name, url=props.remote_url)
props.remote_name = ""
props.remote_url = ""
@classmethod @classmethod
def delete_remote(cls, repo): def delete_remote(cls, repo):
props = bpy.context.scene.IfcGitProperties props = bpy.context.scene.IfcGitProperties