forked from stanfordnlp/dspy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
61 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,59 @@ | ||
#!/bin/bash | ||
|
||
# Exit if insufficient arguments are provided | ||
# Ensure the script exits on any error | ||
set -e | ||
|
||
if [ "$#" -lt 1 ]; then | ||
echo "Usage: ./sync_to_public.sh <branch-name> [--squash]" | ||
echo "Usage: ./sync_to_public.sh <branch_name> [--squash]" | ||
exit 1 | ||
fi | ||
|
||
BRANCH_NAME=$1 | ||
SQUASH_COMMITS=false | ||
|
||
# Check if the squash option is provided | ||
if [ "$#" -eq 2 ] && [ "$2" == "--squash" ]; then | ||
SQUASH_COMMITS=true | ||
fi | ||
BRANCH=$1 | ||
SQUASH=$2 | ||
|
||
# Variables | ||
PRIVATE_REMOTE="origin" | ||
PUBLIC_REMOTE="upstream" | ||
CURRENT_DATE=$(date +%Y%m%d%H%M%S) | ||
TEMP_BRANCH="temp-public-sync-$CURRENT_DATE" | ||
|
||
# Ensure we are on the specified branch and have the latest changes | ||
git checkout $BRANCH_NAME | ||
git pull $PRIVATE_REMOTE $BRANCH_NAME | ||
|
||
# If squash option is true, squash the commits | ||
if [ "$SQUASH_COMMITS" = true ]; then | ||
# Count the number of commits since the last public sync | ||
NUM_COMMITS=$(git rev-list --count $PUBLIC_REMOTE/$BRANCH_NAME..HEAD) | ||
|
||
# Squash the last NUM_COMMITS into one | ||
if [ "$NUM_COMMITS" -gt 1 ]; then | ||
git reset --soft HEAD~$NUM_COMMITS && git commit | ||
fi | ||
fi | ||
# Ensure we are in the correct branch | ||
git checkout $BRANCH | ||
|
||
# Create a new temporary branch | ||
# Create a temporary branch for this sync process | ||
TEMP_BRANCH="temp-public-sync-$(date +%Y%m%d%H%M%S)" | ||
git checkout -b $TEMP_BRANCH | ||
|
||
# Remove private_* directories and commit | ||
git rm -r private_* 2> /dev/null | ||
git commit -m "Remove private content for public sync" | ||
# Pull any new changes from the public repo (this should ideally be a fast-forward merge) | ||
git pull upstream $BRANCH | ||
|
||
# List the private directories to be removed | ||
echo "The following private directories will be removed:" | ||
find . -type d -name 'private_*' | ||
|
||
# Ask for confirmation | ||
read -p "Are you sure you want to remove these directories for public sync? [y/N] " response | ||
|
||
if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]] | ||
then | ||
# Remove the private directories | ||
find . -type d -name 'private_*' -exec rm -r {} + | ||
|
||
# Stage the removal changes | ||
git add -A | ||
|
||
# Commit the removal of private directories (this will be a no-op if no private directories were present) | ||
git commit -m "Prepare for public sync" || echo "No private directories to remove" | ||
else | ||
echo "Aborted removing private directories." | ||
exit 1 | ||
fi | ||
|
||
# If squash option is provided, squash all the commits | ||
if [ "$SQUASH" == "--squash" ]; then | ||
echo "Squashing commits..." | ||
git reset $(git commit-tree HEAD^{tree} -m "Squash all commits for public sync") | ||
fi | ||
|
||
# Push the temporary branch to the corresponding branch of the public repo | ||
git push $PUBLIC_REMOTE $TEMP_BRANCH:$BRANCH_NAME | ||
# Push the changes to the public repo | ||
git push upstream $TEMP_BRANCH:$BRANCH | ||
|
||
# Return to the specified branch and delete the temporary branch | ||
git checkout $BRANCH_NAME | ||
# Return to the original branch and delete the temporary branch | ||
git checkout $BRANCH | ||
git branch -D $TEMP_BRANCH | ||
|
||
echo "Sync completed successfully!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters