Skip to content
This repository was archived by the owner on Nov 24, 2024. It is now read-only.

Commit 88ba651

Browse files
committed
Git remote fetch and push operations (IfcOpenShell#3096)
1 parent 894a688 commit 88ba651

6 files changed

Lines changed: 118 additions & 3 deletions

File tree

src/blenderbim/blenderbim/bim/module/ifcgit/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
operator.DiscardUncommitted,
2929
operator.DisplayRevision,
3030
operator.DisplayUncommitted,
31+
operator.Fetch,
3132
operator.Merge,
33+
operator.Push,
3234
operator.RefreshGit,
3335
operator.SwitchRevision,
3436
prop.IfcGitTag,

src/blenderbim/blenderbim/bim/module/ifcgit/data.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ class IfcGitData:
1919
def load(cls):
2020
cls.data = {
2121
"repo": cls.repo(),
22+
"remotes": cls.remotes(),
2223
"branch_names": cls.branch_names(),
24+
"remote_names": cls.remote_names(),
25+
"remote_urls": cls.remote_urls(),
2326
"path_ifc": cls.path_ifc(),
2427
"branches_by_hexsha": cls.branches_by_hexsha(),
2528
"tags_by_hexsha": cls.tags_by_hexsha(),
@@ -42,10 +45,28 @@ def repo(cls):
4245
return tool.IfcGit.repo_from_path(path_ifc)
4346
return None
4447

48+
@classmethod
49+
def remotes(cls):
50+
if cls.repo():
51+
return cls.repo().remotes
52+
return None
53+
4554
@classmethod
4655
def branch_names(cls):
4756
return []
4857

58+
@classmethod
59+
def remote_names(cls):
60+
return []
61+
62+
@classmethod
63+
def remote_urls(cls):
64+
result = {}
65+
if cls.repo():
66+
for remote in cls.repo().remotes:
67+
result[remote.name] = remote.url
68+
return result
69+
4970
@classmethod
5071
def path_ifc(cls):
5172
path_ifc = tool.Ifc.get_path()

src/blenderbim/blenderbim/bim/module/ifcgit/operator.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,3 +246,35 @@ def execute(self, context):
246246
return {"FINISHED"}
247247
else:
248248
return {"CANCELLED"}
249+
250+
251+
class Push(bpy.types.Operator):
252+
"""Pushes the working branch to selected remote"""
253+
254+
bl_label = "Push working branch"
255+
bl_idname = "ifcgit.push"
256+
bl_options = {"REGISTER"}
257+
258+
def execute(self, context):
259+
260+
props = context.scene.IfcGitProperties
261+
repo = IfcGitData.data["repo"]
262+
remote = repo.remotes[props.select_remote]
263+
remote.push()
264+
return {"FINISHED"}
265+
266+
267+
class Fetch(bpy.types.Operator):
268+
"""Fetches from the selected remote"""
269+
270+
bl_label = "Fetch from remote"
271+
bl_idname = "ifcgit.fetch"
272+
bl_options = {"REGISTER"}
273+
274+
def execute(self, context):
275+
276+
props = context.scene.IfcGitProperties
277+
repo = IfcGitData.data["repo"]
278+
remote = repo.remotes[props.select_remote]
279+
remote.fetch()
280+
return {"FINISHED"}

src/blenderbim/blenderbim/bim/module/ifcgit/prop.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,25 @@ def git_branches(self, context):
2121
IfcGitData.data["branch_names"].remove("main")
2222
IfcGitData.data["branch_names"] = ["main"] + IfcGitData.data["branch_names"]
2323

24+
if IfcGitData.data["remotes"]:
25+
props = context.scene.IfcGitProperties
26+
IfcGitData.data["branch_names"] += [r.name for r in IfcGitData.data["remotes"][props.select_remote].refs]
27+
2428
return [(myname, myname, myname) for myname in IfcGitData.data["branch_names"]]
2529

2630

31+
def git_remotes(self, context):
32+
"""remotes enum"""
33+
34+
IfcGitData.data["remote_names"] = sorted([remote.name for remote in IfcGitData.data["remotes"]])
35+
36+
if "origin" in IfcGitData.data["remote_names"]:
37+
IfcGitData.data["remote_names"].remove("origin")
38+
IfcGitData.data["remote_names"] = ["origin"] + IfcGitData.data["remote_names"]
39+
40+
return [(myname, myname, myname) for myname in IfcGitData.data["remote_names"]]
41+
42+
2743
def update_revlist(self, context):
2844
"""wrapper to trigger update of the revision list"""
2945

@@ -109,6 +125,7 @@ class IfcGitProperties(PropertyGroup):
109125
subtype="DIR_PATH",
110126
)
111127
display_branch: EnumProperty(items=git_branches, update=update_revlist)
128+
select_remote: EnumProperty(items=git_remotes)
112129
ifcgit_filter: EnumProperty(
113130
items=[
114131
("all", "All", "All revisions"),

src/blenderbim/blenderbim/bim/module/ifcgit/ui.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,23 @@ def draw(self, context):
154154
# TODO
155155
# item.operator("ifcgit.delete_tag", icon="PANEL_CLOSE")
156156

157-
row = layout.row()
157+
box = layout.box()
158+
row = box.row()
158159
row.prop(props, "new_tag_name")
159-
row = layout.row()
160+
row = box.row()
160161
row.prop(props, "new_tag_message")
161-
row = layout.row()
162+
row = box.row()
162163
row.operator("ifcgit.add_tag", icon="GREASEPENCIL")
163164

165+
if IfcGitData.data["remotes"]:
166+
row = layout.row()
167+
row.prop(props, "select_remote", text="Select remote")
168+
urls = IfcGitData.data["remote_urls"]
169+
row.label(text=urls[props.select_remote])
170+
row = layout.row()
171+
row.operator("ifcgit.push", icon="EXPERIMENTAL")
172+
row.operator("ifcgit.fetch", icon="IMPORT")
173+
164174

165175
class COMMIT_UL_List(bpy.types.UIList):
166176
"""List of Git commits"""

src/blenderbim/docs/users/git_support.rst

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,39 @@ optional message text.
156156
Similar to commit messages, tag messages should be 50 characters or less,
157157
though there is no practical limit.
158158

159+
Remote operations
160+
-----------------
161+
162+
Git is a *distributed revision control system*, your local repository can be a
163+
version of a remote repository and vice-versa. This is conceptually similar to
164+
local branching except this remote repository could belong to someone else or
165+
could be hosted by an online Git-forge service.
166+
167+
Your repository can have multiple remote repositories registered, each
168+
can have potentially multiple branches.
169+
170+
BlenderBIM allows you to make a local *clone* of a remote repository. You will
171+
need to provide a URL *origin* to fetch, and an empty local folder to become
172+
the local repository.
173+
174+
The *Fetch* operator retrieves new data from the remote repository. This isn't
175+
automatically merged, each branch fetched from the remote repository appears as
176+
a branch that can be browsed, switched-to or merged just like a local branch.
177+
These remote branches have prefixed names, eg. `origin/main`.
178+
179+
Once you have committed changes to your local repository, the *Push* operator
180+
tries to update the remote branch using changes from the selected local branch.
181+
182+
.. Warning::
183+
184+
Remote repositories can be accessed in multiple ways; ssh, ftp or https
185+
protocols, for example, can require authentication. This authentication may
186+
expect you to generate and upload ssh keys, store API tokens, save
187+
username/password pairs, or use some other form of credential.
188+
BlenderBIM can't configure these credentials for you, follow the
189+
configuration instructions provided by your online service before trying
190+
actions that require authentication.
191+
159192
Using other Git tools
160193
---------------------
161194

0 commit comments

Comments
 (0)