phangs_PAHs / resolve.sh
Christine Ye
Merge with main - auto-resolved
e7898c2
raw
history blame
3.3 kB
#!/bin/bash
# Script to automatically resolve .gitattributes conflicts for multiple HuggingFace PRs
# Usage: ./resolve-gitattributes-conflicts.sh <start_pr> <end_pr>
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
# Validate inputs are numbers
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..."
# Function to resolve gitattributes conflict
resolve_gitattributes() {
local pr_num=$1
echo "Processing PR #$pr_num..."
# Fetch and checkout the PR
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
# Try to merge with main to trigger any conflicts
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..."
# Check if .gitattributes has conflicts and resolve them
if [ -f .gitattributes ] && grep -q "^<<<<<<<" .gitattributes; then
echo " πŸ”§ Resolving .gitattributes conflict..."
# Remove conflict markers and duplicate lines
grep -v "^<<<<<<<" .gitattributes | \
grep -v "^=======" | \
grep -v "^>>>>>>>" | \
sort -u > .gitattributes.tmp
mv .gitattributes.tmp .gitattributes
fi
fi
# Always stage all files and commit/push regardless of merge status
echo " πŸ“¦ Staging all files..."
git add .
# Commit (this will work whether there were conflicts or not)
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
# Always try to push
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
}
# Main loop
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
# Summary
echo "============================================"
echo "Summary:"
echo " Total PRs processed: $total_count"
echo " Successfully resolved: $success_count"
echo " Failed: $((total_count - success_count))"
echo "============================================"
# Return to main branch
git checkout main 2>/dev/null || git checkout master 2>/dev/null
echo "Done! Returned to main branch."