-
-
Notifications
You must be signed in to change notification settings - Fork 0
chore: add remark-definition-links import script #67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,84 @@ | ||||||
| #!/bin/bash | ||||||
|
|
||||||
| set -x | ||||||
| set -e | ||||||
|
|
||||||
| # In this repo | ||||||
| SOURCE_GIT="git@github.com:mcansh/remark-definition-links.git" | ||||||
| # Cloned locally to this folder | ||||||
| SOURCE_REPO_DIR="temp-remark-definition-links" | ||||||
| # Copy files as of this ref | ||||||
| SOURCE_REF="main" | ||||||
| # Using a temp branch named | ||||||
| SOURCE_WORKING_BRANCH="migration-src" | ||||||
|
|
||||||
| # And re-play it in this repo | ||||||
| DEST_GIT="git@github.com:mcansh/packages.git" | ||||||
| # Cloned locally to this folder | ||||||
| DEST_REPO_DIR="temp-packages" | ||||||
| # Onto this branch | ||||||
| DEST_BRANCH="dev" | ||||||
| # Using a temp branch named | ||||||
| DEST_WORKING_BRANCH="import-remark-definition-links" | ||||||
| # Using the source repo as this remote | ||||||
| TEMP_SOURCE_REMOTE_NAME="rtw" | ||||||
|
|
||||||
| rm -rf "$SOURCE_REPO_DIR" | ||||||
| rm -rf "$DEST_REPO_DIR" | ||||||
|
|
||||||
| # Clone fresh copies of the repos | ||||||
| git clone "$SOURCE_GIT" "$SOURCE_REPO_DIR" | ||||||
| git clone "$DEST_GIT" "$DEST_REPO_DIR" | ||||||
|
|
||||||
| # Remove origins so we can't accidentally mess them up | ||||||
| cd "$SOURCE_REPO_DIR" | ||||||
| git remote rm origin | ||||||
| cd .. | ||||||
| cd "$DEST_REPO_DIR" | ||||||
| git checkout $DEST_BRANCH | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The variable
Suggested change
|
||||||
| git remote rm origin | ||||||
| cd .. | ||||||
|
|
||||||
| cd "$SOURCE_REPO_DIR" | ||||||
|
|
||||||
| git checkout -b $SOURCE_WORKING_BRANCH $SOURCE_REF | ||||||
| # git-filter-repo --force \ | ||||||
| # --path .env.example \ | ||||||
| # --path .github \ | ||||||
| # --path .gitignore \ | ||||||
| # --path .prettierrc \ | ||||||
| # --path .vscode \ | ||||||
| # --path CONTRIBUTING.md \ | ||||||
| # --path LICENSE \ | ||||||
| # --path package.json \ | ||||||
| # --path packages \ | ||||||
| # --path pnpm-lock.yaml \ | ||||||
| # --path pnpm-workspace.yaml \ | ||||||
| # --path scripts | ||||||
|
Comment on lines
+45
to
+57
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||
|
|
||||||
| git reset --hard | ||||||
| git gc --aggressive | ||||||
| git prune | ||||||
| cd .. | ||||||
|
|
||||||
| cd $DEST_REPO_DIR | ||||||
| git checkout -b $DEST_WORKING_BRANCH | ||||||
| git remote add $TEMP_SOURCE_REMOTE_NAME ../$SOURCE_REPO_DIR | ||||||
| # Only fetch the migration branch, don't include tags | ||||||
| git fetch $TEMP_SOURCE_REMOTE_NAME $SOURCE_WORKING_BRANCH | ||||||
| git merge $TEMP_SOURCE_REMOTE_NAME/$SOURCE_WORKING_BRANCH --allow-unrelated-histories --no-edit | ||||||
| cd .. | ||||||
|
|
||||||
| set +x | ||||||
| set +e | ||||||
|
|
||||||
| echo "✅ Migration complete!" | ||||||
| echo "" | ||||||
| echo "To finish:" | ||||||
| echo " cd ${DEST_REPO_DIR}" | ||||||
| echo " git remote add origin ${DEST_GIT}" | ||||||
| echo " git push --set-upstream origin $DEST_WORKING_BRANCH" | ||||||
| echo "" | ||||||
| echo "Then open a PR to the ${DEST_BRANCH} branch and perform a **NORMAL MERGE**" | ||||||
| echo " https://github.com/mcansh/packages/compare/${DEST_BRANCH}...${DEST_WORKING_BRANCH}?expand=1" | ||||||
| echo "" | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make the script more robust, I suggest two improvements:
set -u: This will cause the script to exit if it tries to use an uninitialized variable.trapfor cleanup: This ensures that the temporary directories ($SOURCE_REPO_DIRand$DEST_REPO_DIR) are removed when the script exits, whether it succeeds or fails.With the
trapin place, you can then remove therm -rfcommands on lines 26-27.