Skip to content

Commit 0d824c4

Browse files
committed
feat: add guard for checking if the repository is already migrated
1 parent 004af07 commit 0d824c4

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

monorepo-migration/migrate.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ git clean -fd
7777
git checkout -f main
7878
git reset --hard origin/main
7979

80+
# Check if the repository is already migrated
81+
if [ -d "$SOURCE_REPO_NAME" ]; then
82+
echo "Error: Directory $SOURCE_REPO_NAME already exists in the monorepo." >&2
83+
echo "This repository seems to have already been migrated." >&2
84+
exit 1
85+
fi
86+
87+
8088
# 2.5 Create a new feature branch for the migration
8189
BRANCH_NAME="migrate-$SOURCE_REPO_NAME"
8290
echo "Creating feature branch: $BRANCH_NAME"
@@ -102,9 +110,6 @@ git merge --allow-unrelated-histories --no-ff "$SOURCE_REPO_NAME/main" -s ours -
102110

103111
# 6. Read the tree from the source repo into the desired subdirectory
104112
echo "Reading tree into prefix $SOURCE_REPO_NAME/..."
105-
if [ -d "$SOURCE_REPO_NAME" ]; then
106-
rm -rf "$SOURCE_REPO_NAME"
107-
fi
108113
git read-tree --prefix="$SOURCE_REPO_NAME/" -u "$SOURCE_REPO_NAME/main"
109114

110115
# 7. Commit the migration

0 commit comments

Comments
 (0)