From 4bc7414df2fa67ad51e1512d3ef1ea5ddbb99c1b Mon Sep 17 00:00:00 2001
From: RahulGautamSingh <rahultesnik@gmail.com>
Date: Tue, 18 Jun 2024 22:01:25 +0530
Subject: [PATCH] fix(util/git): pass no-verify flag to deleteBranch (#29749)

---
 lib/util/git/index.spec.ts | 24 ++++++++++++++++++++++++
 lib/util/git/index.ts      |  8 +++++++-
 2 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/lib/util/git/index.spec.ts b/lib/util/git/index.spec.ts
index b97aba5402..5043eec9f8 100644
--- a/lib/util/git/index.spec.ts
+++ b/lib/util/git/index.spec.ts
@@ -424,6 +424,30 @@ describe('util/git/index', () => {
       const branches = await Git(origin.path).branch({});
       expect(branches.all).not.toContain('renovate/past_branch');
     });
+
+    it('should add no verify flag', async () => {
+      const rawSpy = jest.spyOn(SimpleGit.prototype, 'raw');
+      await git.deleteBranch('renovate/something');
+      expect(rawSpy).toHaveBeenCalledWith([
+        'push',
+        '--delete',
+        'origin',
+        'renovate/something',
+      ]);
+    });
+
+    it('should not add no verify flag', async () => {
+      const rawSpy = jest.spyOn(SimpleGit.prototype, 'raw');
+      setNoVerify(['push']);
+      await git.deleteBranch('renovate/something');
+      expect(rawSpy).toHaveBeenCalledWith([
+        'push',
+        '--delete',
+        'origin',
+        'renovate/something',
+        '--no-verify',
+      ]);
+    });
   });
 
   describe('getBranchLastCommitTime', () => {
diff --git a/lib/util/git/index.ts b/lib/util/git/index.ts
index 5900222c07..49b4882569 100644
--- a/lib/util/git/index.ts
+++ b/lib/util/git/index.ts
@@ -767,7 +767,13 @@ export async function isBranchConflicted(
 export async function deleteBranch(branchName: string): Promise<void> {
   await syncGit();
   try {
-    await gitRetry(() => git.raw(['push', '--delete', 'origin', branchName]));
+    const deleteCommand = ['push', '--delete', 'origin', branchName];
+
+    if (getNoVerify().includes('push')) {
+      deleteCommand.push('--no-verify');
+    }
+
+    await gitRetry(() => git.raw(deleteCommand));
     logger.debug(`Deleted remote branch: ${branchName}`);
   } catch (err) /* istanbul ignore next */ {
     const errChecked = checkForPlatformFailure(err);
-- 
GitLab