Skip to content

Commit

Permalink
Minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
okhat committed Jul 30, 2023
1 parent 625b1ef commit 963855b
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 50 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,4 @@ We'll rebrand to the **DSPy** framework soon.
<img align="center" src="docs/images/DSPy7.png" width="260px" />
</p>
<p align="left">

81 changes: 44 additions & 37 deletions private_docs/sync_to_public.sh
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!"
29 changes: 16 additions & 13 deletions private_docs/workflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Step 3: **Add the Public Repository as an Upstream Remote**
git remote add upstream https://github.com/stanfordnlp/dsp.git
```

### 3) Development Workflow [you do this every day]
### 3) Development Workflow [relevant for what you do every day, especially Steps 2 and 3]

This is what you do in the private repo day to day.

Expand All @@ -36,40 +36,43 @@ Step 1: **Pull Latest Changes from Private Repository**
Ensure you're always working with the latest data from the private repo:

```bash
git checkout main
git pull origin main
git checkout <branch-name>
git pull origin <branch-name>
```

Replace `<branch-name>` with the name of the branch you are working on.

Step 2: **Development** (this is the actual work!)

Conduct your development as usual.

When adding sensitive or private content, make sure to place it within directories prefixed by `private_*`.

We already have `private_docs` for example.
When adding sensitive or private content, make sure to place it within directories prefixed by `private_*/`.

We already have `private_docs/` as an example.

Step 3: **Commit Changes in Private Repository**

```bash
git add .
git commit -m "Your descriptive commit message"
git push origin main
git push origin <branch-name>
```

Replace `<branch-name>` with the name of the branch you are working on.

### 4) Pulling Updates from the Public Repository [you do this when needed]

If the public repository receives contributions, you'll want to incorporate them into your private repository at some point:
If the public repository receives contributions, you'll want to incorporate them into your private repository:

```bash
git checkout main
git pull upstream main # pull and merge anything from public upstream
git push origin main # push now any recent things to the private origin
git checkout <branch-name>
git pull upstream <branch-name> # pull and merge anything from public upstream
git push origin <branch-name> # push now any recent things to the private origin
```

This is definitely important before syncing back to the public repo.
This is important before syncing back to the public repo. It ensures that both repositories are in sync and that you're working with the most recent changes.

You may sometimes do this with other branches.
You may sometimes do this with branches other than `main`.


### 5) Syncing to Public Repository [you do this when needed]
Expand Down

0 comments on commit 963855b

Please sign in to comment.