Skip to content

Commit 8de05f5

Browse files
committed
update import pr
1 parent d2e609c commit 8de05f5

1 file changed

Lines changed: 39 additions & 13 deletions

File tree

import_pr.sh

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ set -e
2121

2222
# Configuration
2323
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=""
2627

2728
# Repository mapping function (compatible with bash 3.2+)
2829
get_repo_info() {
@@ -70,15 +71,23 @@ log_step() {
7071
echo -e "${BLUE}[STEP]${NC} $1"
7172
}
7273

73-
# Cleanup function
74+
# Cleanup function - only clean up on success
7475
cleanup() {
7576
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
8291
fi
8392
}
8493

@@ -342,10 +351,23 @@ apply_patches() {
342351
if [ "$failed" -gt 0 ]; then
343352
log_error "Failed to apply ${failed} patch(es)."
344353
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 ""
349371
exit 1
350372
fi
351373

@@ -396,6 +418,10 @@ main() {
396418
# Validate arguments
397419
validate_args "$@"
398420

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+
399425
# Check dependencies
400426
check_dependencies
401427
echo ""

0 commit comments

Comments
 (0)