Skip to content

Commit 0627f15

Browse files
committed
feat(remote): enhance remote function to check and update existing remote URLs
1 parent 83f16a1 commit 0627f15

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

bin/backend_split_single.sh

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,25 @@ function split()
6060

6161
function remote()
6262
{
63-
git remote add $1 $2 || true
63+
# 检查远程仓库是否已存在
64+
if git remote | grep -q "^$1$"; then
65+
CURRENT_URL=$(git remote get-url $1)
66+
if [ "$CURRENT_URL" != "$2" ]; then
67+
echo "⚠️ Warning: Remote '$1' exists but points to a different URL"
68+
echo "Current URL: $CURRENT_URL"
69+
echo "Expected URL: $2"
70+
read -p "Do you want to update the remote URL? (y/n): " update_remote
71+
if [[ $update_remote == "y" || $update_remote == "Y" ]]; then
72+
echo "Updating remote URL..."
73+
git remote set-url $1 $2
74+
else
75+
echo "❌ Operation cancelled: Remote URL mismatch"
76+
exit 1
77+
fi
78+
fi
79+
else
80+
git remote add $1 $2
81+
fi
6482
}
6583

6684
# 更健壮地处理git pull操作
@@ -82,4 +100,4 @@ split "backend/$COMPOSE_NAME" $COMPOSE_NAME
82100

83101
TIME=$(echo "$(date +%s) - $NOW" | bc)
84102

85-
printf "Execution time: %f seconds" $TIME
103+
printf "Execution time: %f seconds" $TIME

0 commit comments

Comments
 (0)