|
21 | 21 |
|
22 | 22 | # Configuration |
23 | 23 | SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
24 | | -TEMP_DIR="${SCRIPT_DIR}/.import-pr-temp" |
25 | | -PATCH_DIR="${TEMP_DIR}/patches" |
| 24 | +# TEMP_DIR will be set later with repo name and PR number |
| 25 | +TEMP_DIR="" |
| 26 | +PATCH_DIR="" |
26 | 27 |
|
27 | 28 | # Repository mapping function (compatible with bash 3.2+) |
28 | 29 | get_repo_info() { |
@@ -70,15 +71,23 @@ log_step() { |
70 | 71 | echo -e "${BLUE}[STEP]${NC} $1" |
71 | 72 | } |
72 | 73 |
|
73 | | -# Cleanup function |
| 74 | +# Cleanup function - only clean up on success |
74 | 75 | cleanup() { |
75 | 76 | local exit_code=$? |
76 | | - if [ -d "${TEMP_DIR}" ]; then |
77 | | - log_info "Cleaning up temporary directory..." |
78 | | - rm -rf "${TEMP_DIR}" |
79 | | - fi |
80 | | - if [ $exit_code -ne 0 ]; then |
81 | | - log_warn "Script exited with errors. Any partial changes may need to be reverted." |
| 77 | + if [ $exit_code -eq 0 ]; then |
| 78 | + if [ -n "${TEMP_DIR}" ] && [ -d "${TEMP_DIR}" ]; then |
| 79 | + log_info "Cleaning up temporary directory..." |
| 80 | + rm -rf "${TEMP_DIR}" |
| 81 | + fi |
| 82 | + else |
| 83 | + if [ -n "${TEMP_DIR}" ] && [ -d "${TEMP_DIR}" ]; then |
| 84 | + echo "" |
| 85 | + log_warn "Script failed. Temporary directory preserved for debugging:" |
| 86 | + log_warn " ${TEMP_DIR}" |
| 87 | + echo "" |
| 88 | + log_warn "To clean up manually after debugging:" |
| 89 | + log_warn " rm -rf ${TEMP_DIR}" |
| 90 | + fi |
82 | 91 | fi |
83 | 92 | } |
84 | 93 |
|
@@ -342,10 +351,23 @@ apply_patches() { |
342 | 351 | if [ "$failed" -gt 0 ]; then |
343 | 352 | log_error "Failed to apply ${failed} patch(es)." |
344 | 353 | echo "" |
345 | | - echo "The patch may have conflicts. You can try to resolve them manually:" |
346 | | - echo " 1. git checkout main" |
347 | | - echo " 2. git branch -D ${branch_name}" |
348 | | - echo " 3. Manually apply the changes from the upstream PR" |
| 354 | + echo "Debug information:" |
| 355 | + echo " - Patches directory: ${PATCH_DIR}" |
| 356 | + echo " - Upstream repo clone: ${TEMP_DIR}/repo" |
| 357 | + echo " - Current branch: ${branch_name}" |
| 358 | + echo "" |
| 359 | + echo "To investigate the failure:" |
| 360 | + echo " 1. Examine the failed patch:" |
| 361 | + echo " cat ${PATCH_DIR}/*.patch | less" |
| 362 | + echo "" |
| 363 | + echo " 2. Try applying manually to see the conflict:" |
| 364 | + echo " git am --directory=${subdir} ${PATCH_DIR}/*.patch" |
| 365 | + echo "" |
| 366 | + echo " 3. If you want to start over:" |
| 367 | + echo " git checkout main" |
| 368 | + echo " git branch -D ${branch_name}" |
| 369 | + echo " rm -rf ${TEMP_DIR}" |
| 370 | + echo "" |
349 | 371 | exit 1 |
350 | 372 | fi |
351 | 373 |
|
@@ -396,6 +418,10 @@ main() { |
396 | 418 | # Validate arguments |
397 | 419 | validate_args "$@" |
398 | 420 |
|
| 421 | + # Set temp directory with descriptive name |
| 422 | + TEMP_DIR="${SCRIPT_DIR}/.import-pr-temp-${repo_name}-${pr_number}" |
| 423 | + PATCH_DIR="${TEMP_DIR}/patches" |
| 424 | + |
399 | 425 | # Check dependencies |
400 | 426 | check_dependencies |
401 | 427 | echo "" |
|
0 commit comments