Browse Source

ZOOKEEPER-4806: Commits have to be refreshed after merging

Reviewers: anmolnar
Author: szucsvillo
Closes #2137 from szucsvillo/ZOOKEEPER-4806
szucsvillo 1 year ago
parent
commit
7074448f2d
1 changed files with 13 additions and 1 deletions
  1. 13 1
      zk-merge-pr.py

+ 13 - 1
zk-merge-pr.py

@@ -209,9 +209,21 @@ def cherry_pick(pr_num, merge_hash, default_branch):
 
     pick_branch_name = "%s_PICK_PR_%s_%s" % (TEMP_BRANCH_PREFIX, pr_num, pick_ref.upper())
 
-    run_cmd("git fetch %s" % PUSH_REMOTE_NAME)
+    run_cmd("git fetch %s" % PR_REMOTE_NAME)
     run_cmd("git checkout -b %s %s/%s" % (pick_branch_name, PUSH_REMOTE_NAME, pick_ref))
 
+    current_attempt = 0
+    max_attempts = 6
+    # Check if the merge hash exists
+    while not run_cmd("git rev-parse --verify %s" % merge_hash):
+        if current_attempt >= max_attempts:
+            print("Error: The commit hash does not exist in the local repository.")
+            exit()
+        current_attempt += 1
+        print("Waiting for the merge hash to become available...(10 sec)")
+        time.sleep(10)
+        run_cmd("git fetch %s" % PR_REMOTE_NAME)
+
     try:
         run_cmd("git cherry-pick -sx %s" % merge_hash)
     except Exception as e: