Skip to content

Commit 2132403

Browse files
authored
Update _git.py (#320)
* Update _git.py Fix LRO bug - no result is returned from a commit to git operation therefore added True boolean param to use status code instead. Added check to see whether any changes exist before calling commit operation and added message if no modified items found. Fixed small typo. * Update _git.py changed git status response empty check when making commit. changed green icon dot to info if nothing to commit
1 parent 747dedd commit 2132403

File tree

1 file changed

+33
-27
lines changed

1 file changed

+33
-27
lines changed

src/sempy_labs/_git.py

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -277,46 +277,52 @@ def commit_to_git(
277277
workspace, workspace_id = resolve_workspace_name_and_id(workspace)
278278

279279
gs = get_git_status(workspace=workspace)
280-
workspace_head = gs["Workspace Head"].iloc[0]
280+
if not gs.empty:
281+
workspace_head = gs["Workspace Head"].iloc[0]
281282

282-
if item_ids is None:
283-
commit_mode = "All"
284-
else:
285-
commit_mode = "Selective"
283+
if item_ids is None:
284+
commit_mode = "All"
285+
else:
286+
commit_mode = "Selective"
286287

287-
if isinstance(item_ids, str):
288-
item_ids = [item_ids]
288+
if isinstance(item_ids, str):
289+
item_ids = [item_ids]
289290

290-
request_body = {
291-
"mode": commit_mode,
292-
"workspaceHead": workspace_head,
293-
"comment": comment,
294-
}
291+
request_body = {
292+
"mode": commit_mode,
293+
"workspaceHead": workspace_head,
294+
"comment": comment,
295+
}
295296

296-
if item_ids is not None:
297-
request_body["items"] = [{"objectId": item_id} for item_id in item_ids]
297+
if item_ids is not None:
298+
request_body["items"] = [{"objectId": item_id} for item_id in item_ids]
298299

299-
client = fabric.FabricRestClient()
300-
response = client.post(
301-
f"/v1/workspaces/{workspace_id}/git/commitToGit",
302-
json=request_body,
303-
)
300+
client = fabric.FabricRestClient()
301+
response = client.post(
302+
f"/v1/workspaces/{workspace_id}/git/commitToGit",
303+
json=request_body,
304+
)
304305

305-
if response.status_code not in [200, 202]:
306-
raise FabricHTTPException(response)
306+
if response.status_code not in [200, 202]:
307+
raise FabricHTTPException(response)
307308

308-
lro(client, response)
309+
lro(client=client, response=response, return_status_code=True)
309310

310-
if commit_mode == "All":
311-
print(
312-
f"{icons.green_dot} All items within the '{workspace}' workspace have been committed to Git."
313-
)
311+
if commit_mode == "All":
312+
print(
313+
f"{icons.green_dot} All items within the '{workspace}' workspace have been committed to Git."
314+
)
315+
else:
316+
print(
317+
f"{icons.green_dot} The {item_ids} items within the '{workspace}' workspace have been committed to Git."
318+
)
314319
else:
315320
print(
316-
f"{icons.green_dot} The {item_ids} items ithin the '{workspace}' workspace have been committed to Git."
321+
f"{icons.info} Git already up to date: no modified items found within the '{workspace}' workspace."
317322
)
318323

319324

325+
320326
def update_from_git(
321327
remote_commit_hash: str,
322328
conflict_resolution_policy: str,

0 commit comments

Comments
 (0)