| #!/bin/bash |
|
|
| |
| |
|
|
| if [ $# -ne 2 ]; then |
| echo "Usage: $0 <start_pr_number> <end_pr_number>" |
| echo "Example: $0 1 5" |
| exit 1 |
| fi |
|
|
| START_PR=$1 |
| END_PR=$2 |
|
|
| |
| if ! [[ "$START_PR" =~ ^[0-9]+$ ]] || ! [[ "$END_PR" =~ ^[0-9]+$ ]]; then |
| echo "Error: PR numbers must be integers" |
| exit 1 |
| fi |
|
|
| if [ $START_PR -gt $END_PR ]; then |
| echo "Error: Start PR number must be less than or equal to end PR number" |
| exit 1 |
| fi |
|
|
| echo "Resolving .gitattributes conflicts for PRs $START_PR through $END_PR..." |
|
|
| |
| resolve_gitattributes() { |
| local pr_num=$1 |
| |
| echo "Processing PR #$pr_num..." |
| |
| |
| if ! git fetch origin refs/pr/$pr_num:pr/$pr_num 2>/dev/null; then |
| echo " β Failed to fetch PR #$pr_num (may not exist)" |
| return 1 |
| fi |
| |
| git checkout pr/$pr_num 2>/dev/null |
| |
| |
| echo " π Attempting merge with main..." |
| merge_output=$(git merge main 2>&1) |
| merge_status=$? |
| |
| if [ $merge_status -eq 0 ]; then |
| echo " βΉοΈ No conflicts found in PR #$pr_num (merge successful)" |
| else |
| echo " π§ Merge conflicts detected, resolving..." |
| |
| |
| if [ -f .gitattributes ] && grep -q "^<<<<<<<" .gitattributes; then |
| echo " π§ Resolving .gitattributes conflict..." |
| |
| grep -v "^<<<<<<<" .gitattributes | \ |
| grep -v "^=======" | \ |
| grep -v "^>>>>>>>" | \ |
| sort -u > .gitattributes.tmp |
| |
| mv .gitattributes.tmp .gitattributes |
| fi |
| fi |
| |
| |
| echo " π¦ Staging all files..." |
| git add . |
| |
| |
| if git commit -m "Merge with main - auto-resolved" 2>/dev/null; then |
| echo " β
Changes committed" |
| else |
| echo " βΉοΈ No changes to commit (already up to date)" |
| fi |
| |
| |
| echo " π Pushing to HuggingFace..." |
| if git push origin pr/$pr_num:refs/pr/$pr_num 2>/dev/null; then |
| echo " β
Successfully pushed to HuggingFace PR #$pr_num" |
| else |
| echo " β Failed to push to HuggingFace PR #$pr_num" |
| return 1 |
| fi |
| |
| return 0 |
| } |
|
|
| |
| success_count=0 |
| total_count=0 |
|
|
| for pr_num in $(seq $START_PR $END_PR); do |
| total_count=$((total_count + 1)) |
| |
| if resolve_gitattributes $pr_num; then |
| success_count=$((success_count + 1)) |
| fi |
| |
| echo "" |
| done |
|
|
| |
| echo "============================================" |
| echo "Summary:" |
| echo " Total PRs processed: $total_count" |
| echo " Successfully resolved: $success_count" |
| echo " Failed: $((total_count - success_count))" |
| echo "============================================" |
|
|
| |
| git checkout main 2>/dev/null || git checkout master 2>/dev/null |
|
|
| echo "Done! Returned to main branch." |
|
|