|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Check if commit hash is provided as an argument |
| 4 | +if [ -z "$1" ]; then |
| 5 | + echo "Usage: $0 <commit-hash>" |
| 6 | + exit 1 |
| 7 | +fi |
| 8 | + |
| 9 | +# Commit to cherry-pick (from the command-line argument) |
| 10 | +COMMIT_HASH="$1" |
| 11 | + |
| 12 | +# List of branches |
| 13 | +BRANCHES=( |
| 14 | + "sample-code/end-to-end" |
| 15 | + "sample-code/module-10-assertions" |
| 16 | + "sample-code/module-11-waits" |
| 17 | + "sample-code/module-12-mocking-api-calls" |
| 18 | + "sample-code/module-12-api-interactions " |
| 19 | + "sample-code/module-13-page-objects" |
| 20 | + "sample-code/module-14-allure-reporting" |
| 21 | + "sample-code/module-14-organizing-your-tests" |
| 22 | + "sample-code/module-14-parallel-execution" |
| 23 | + "sample-code/module-15-parallel-execution" |
| 24 | + "sample-code/module-16-allure-reporting" |
| 25 | + "sample-code/module-17-cucumber" |
| 26 | + "sample-code/module-3-my-first-playwright-test" |
| 27 | + "sample-code/module-4-interacting-with-elements" |
| 28 | + "sample-code/module-5-refactoring" |
| 29 | + "sample-code/module-6-browser-options" |
| 30 | + "sample-code/module-7-browser-contexts" |
| 31 | + "sample-code/module-8-locators" |
| 32 | + "sample-code/module-9-forms" |
| 33 | + "sample-code/start-here" |
| 34 | +) |
| 35 | + |
| 36 | +# Iterate over each branch |
| 37 | +for BRANCH in "${BRANCHES[@]}"; do |
| 38 | + echo "Processing branch: $BRANCH" |
| 39 | + |
| 40 | + # Checkout the branch |
| 41 | + git checkout "$BRANCH" |
| 42 | + if [ $? -ne 0 ]; then |
| 43 | + echo "Failed to checkout branch: $BRANCH" |
| 44 | + continue |
| 45 | + fi |
| 46 | + |
| 47 | + # Cherry-pick the commit |
| 48 | + git cherry-pick "$COMMIT_HASH" |
| 49 | + if [ $? -ne 0 ]; then |
| 50 | + echo "Merge conflict detected on branch: $BRANCH" |
| 51 | + echo "Please resolve the conflict, commit the changes, and type 'continue' to proceed, or 'abort' to skip this branch." |
| 52 | + |
| 53 | + while true; do |
| 54 | + read -p "Type 'continue' to proceed or 'abort' to skip this branch: " RESPONSE |
| 55 | + case $RESPONSE in |
| 56 | + continue) |
| 57 | + echo "Continuing after resolving the conflict..." |
| 58 | + break |
| 59 | + ;; |
| 60 | + abort) |
| 61 | + echo "Aborting cherry-pick on branch: $BRANCH" |
| 62 | + git cherry-pick --abort |
| 63 | + continue 2 |
| 64 | + ;; |
| 65 | + *) |
| 66 | + echo "Invalid input. Please type 'continue' or 'abort'." |
| 67 | + ;; |
| 68 | + esac |
| 69 | + done |
| 70 | + fi |
| 71 | + |
| 72 | + # Commit the changes if no conflict or resolved |
| 73 | + git commit --allow-empty -m "Cherry-pick commit $COMMIT_HASH to update branch $BRANCH" |
| 74 | + if [ $? -ne 0 ]; then |
| 75 | + echo "Failed to commit changes on branch: $BRANCH" |
| 76 | + continue |
| 77 | + fi |
| 78 | + |
| 79 | + # Push the changes to origin |
| 80 | + git push origin "$BRANCH" |
| 81 | + if [ $? -ne 0 ]; then |
| 82 | + echo "Failed to push branch: $BRANCH" |
| 83 | + continue |
| 84 | + fi |
| 85 | + |
| 86 | + echo "Successfully processed branch: $BRANCH" |
| 87 | +done |
| 88 | + |
| 89 | +echo "All branches processed." |
0 commit comments