Last active
October 18, 2023 08:55
-
-
Save matias-pizarro/f941621317f0c81cc9e27ff1b8c80c0c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Usage | |
chmod a+x barenaked_repos.sh | |
./barenaked_repos.sh | |
# To be able to interact with the created structure you can import the aliases and paths your bash session: | |
source ./environment.sh | |
# to clean up and start again | |
rm -rf ${HOME}/test_bare/shared_volume | |
# to remove everything | |
rm -rf ${HOME}/test_bare | |
This file contains hidden or 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
#! /usr/bin/env sh | |
# Set up a few shorter path variables | |
SANDBOX=${HOME}/test_bare | |
# Remote | |
GITHUB_REPO=${SANDBOX}/remote/github_repo | |
# Local | |
## Workspaces | |
LOCAL_WORKSPACES=${SANDBOX}/shared_volume/workspaces | |
WORKSPACE_STEFFIE=${LOCAL_WORKSPACES}/steffie | |
WORKSPACE_MARKUS=${LOCAL_WORKSPACES}/markus | |
## Repos | |
LOCAL_REPOS=${SANDBOX}/shared_volume/repos | |
CENTRAL_REPO=${LOCAL_REPOS}/central | |
REPO_STEFFIE=${LOCAL_REPOS}/steffie | |
REPO_MARKUS=${LOCAL_REPOS}/markus | |
# Create empty directory structure | |
mkdir -p ${SANDBOX}/remote ${WORKSPACE_STEFFIE} ${WORKSPACE_MARKUS} | |
# Set up a fake GitHub repo | |
if [ ! -d "${GITHUB_REPO}" ]; then | |
git clone --bare [email protected]:michael-yuji/xc.git ${GITHUB_REPO} | |
fi | |
# Create the shared volume central repo | |
git clone --bare ${GITHUB_REPO} ${CENTRAL_REPO} | |
# Setup new user-specific local repos | |
git clone --bare ${CENTRAL_REPO} ${REPO_STEFFIE} | |
git clone --bare ${CENTRAL_REPO} ${REPO_MARKUS} | |
# Set up a few handy aliases. | |
# You could also add them to your .bash_profile | |
alias git_steffie='/usr/bin/env git --git-dir=${REPO_STEFFIE} --work-tree=${WORKSPACE_STEFFIE}' | |
alias git_markus='/usr/bin/env git --git-dir=${REPO_MARKUS} --work-tree=${WORKSPACE_MARKUS}' | |
# Set up some remotes | |
git_steffie remote add github_repo ${GITHUB_REPO} | |
git_steffie remote add central_repo ${CENTRAL_REPO} | |
git_markus remote add github_repo ${GITHUB_REPO} | |
git_markus remote add central_repo ${CENTRAL_REPO} | |
# Checkout existing branches in each user workspace | |
git_steffie checkout main | |
git_steffie diff | |
git_steffie status | |
git_markus checkout jailfile | |
git_markus diff | |
git_markus status | |
# Let's change some code... | |
echo 'A shorter README' > ${WORKSPACE_MARKUS}/README.md | |
git_markus diff | |
git_markus status | |
# ... and commit it | |
git_markus commit -am "Write a clearly much better README" | |
git_markus diff | |
git_markus status | |
git_markus log -2 | |
# ... and push it back to the central repo | |
git_markus push central_repo jailfile | |
# Let's add a new user (Gonçalo) from scratch | |
WORKSPACE_GONCALO=${LOCAL_WORKSPACES}/goncalo | |
mkdir -p ${WORKSPACE_GONCALO} | |
REPO_GONCALO=${LOCAL_REPOS}/goncalo | |
alias git_goncalo='/usr/bin/env git --git-dir=${REPO_GONCALO} --work-tree=${WORKSPACE_GONCALO}' | |
git_goncalo clone --bare ${CENTRAL_REPO} ${REPO_GONCALO} | |
git_goncalo remote add github_repo ${GITHUB_REPO} | |
git_goncalo remote add central_repo ${CENTRAL_REPO} | |
git_goncalo checkout jailfile | |
cat ${WORKSPACE_GONCALO}/README.md | |
# We can make everyone aware of everyone else | |
# though that would probably not be a good idea in our case | |
git_steffie remote add repo_markus ${REPO_MARKUS} | |
git_steffie remote add repo_goncalo ${REPO_GONCALO} | |
git_markus remote add repo_steffie ${REPO_STEFFIE} | |
git_markus remote add repo_goncalo ${REPO_GONCALO} | |
git_goncalo remote add repo_steffie ${REPO_STEFFIE} | |
git_goncalo remote add repo_markus ${REPO_MARKUS} | |
git_steffie fetch --all | |
git_markus fetch --all | |
git_goncalo fetch --all | |
# Push repo_goncalo/jailfile to repo_steffie | |
git_goncalo push repo_steffie jailfile | |
git_steffie checkout jailfile | |
cat ${WORKSPACE_STEFFIE}/README.md | |
git_steffie diff | |
git_steffie status | |
# We could also push directly to GitHub | |
# Though this would again probably not be a good idea in our case | |
git_steffie push github_repo --all |
This file contains hidden or 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
#! /usr/bin/env sh | |
# Set up a few shorter path variables | |
SANDBOX=${HOME}/test_bare | |
# Remote | |
GITHUB_REPO=${SANDBOX}/remote/github_repo | |
# Local | |
## Workspaces | |
LOCAL_WORKSPACES=${SANDBOX}/shared_volume/workspaces | |
WORKSPACE_STEFFIE=${LOCAL_WORKSPACES}/steffie | |
WORKSPACE_MARKUS=${LOCAL_WORKSPACES}/markus | |
WORKSPACE_GONCALO=${LOCAL_WORKSPACES}/goncalo | |
## Repos | |
LOCAL_REPOS=${SANDBOX}/shared_volume/repos | |
CENTRAL_REPO=${LOCAL_REPOS}/central | |
REPO_STEFFIE=${LOCAL_REPOS}/steffie | |
REPO_MARKUS=${LOCAL_REPOS}/markus | |
REPO_GONCALO=${LOCAL_REPOS}/goncalo | |
alias git_steffie='/usr/bin/env git --git-dir=${REPO_STEFFIE} --work-tree=${WORKSPACE_STEFFIE}' | |
alias git_markus='/usr/bin/env git --git-dir=${REPO_MARKUS} --work-tree=${WORKSPACE_MARKUS}' | |
alias git_goncalo='/usr/bin/env git --git-dir=${REPO_GONCALO} --work-tree=${WORKSPACE_GONCALO}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment