Skip to content

Commit

Permalink
feat: add 'no_verify' parameter to methods that push (#580)
Browse files Browse the repository at this point in the history
Sometimes we don't want to run pre-push hook validations when calling out
to git push from our programs. To avoid running any git hooks, we can use
--no-verify.
  • Loading branch information
n-dusan authored Jan 17, 2025
1 parent f66ae16 commit 9b1fdc7
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions taf/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -998,11 +998,20 @@ def delete_remote_tracking_branch(
self._git(f"branch {flag} -r {remote_branch_name}", log_error=True)

def delete_remote_branch(
self, branch_name: str, remote: Optional[str] = None
self,
branch_name: str,
remote: Optional[str] = None,
no_verify: Optional[bool] = False,
) -> None:
"""
Delete remote branch.
"""
if remote is None:
remote = self.remotes[0]
self._git(f"push {remote} --delete {branch_name}", log_error=True)
no_verify_flag = "--no-verify" if no_verify else ""
self._git(
f"push {remote} --delete {branch_name} {no_verify_flag}", log_error=True
)

def get_commit_date(self, commit_sha: str) -> str:
"""Returns commit date of the given commit"""
Expand Down Expand Up @@ -1437,6 +1446,7 @@ def push(
branch: Optional[str] = None,
set_upstream: Optional[bool] = False,
force: Optional[bool] = False,
no_verify: Optional[bool] = False,
) -> bool:

if not self.has_remote():
Expand All @@ -1454,11 +1464,13 @@ def push(

upstream_flag = "-u" if set_upstream else ""
force_flag = "-f" if force else ""
no_verify_flag = "--no-verify" if no_verify else ""
self._git(
"push {} {} origin {}",
"push {} {} origin {} {}",
upstream_flag,
force_flag,
branch,
no_verify_flag,
reraise_error=True,
)
self._log_notice("Successfully pushed to remote")
Expand Down

0 comments on commit 9b1fdc7

Please sign in to comment.