Created
October 15, 2012 02:28
-
-
Save JasonMillward/3890517 to your computer and use it in GitHub Desktop.
For cloning individual repos from Bitbucket into Github. Dirty, but it works.
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
#!/bin/bash | |
# | |
# Stupid script for importing Bitbucket changes into Github | |
# Because seriously, who uses Bitbucket when you have Github? | |
# | |
# | |
# Define the URLs and the paths and the things | |
GIT_CLONE_URL="" | |
BIT_CLONE_URL="" | |
MASTER_PATH="" | |
WEB_DIR="" | |
# Get the commit ID from Bitbucket using the special API | |
COMMITID=$(cat $WEB_DIR/api/post.txt) | |
# Go to the master path | |
cd $MASTER_PATH | |
# Remove everything in the path for a fresh start | |
echo "Removing the repos" | |
rm -rf $MASTER_PATH/repos | |
# Create the temp repo path again | |
mkdir -p $MASTER_PATH/repos | |
# Get ready for the creation of the repos | |
cd $MASTER_PATH/repos/ | |
# Clone time | |
echo "Cloning the repos" | |
git clone $BIT_CLONE_URL bitbucket --quiet | |
git clone $GIT_CLONE_URL github --quiet | |
# Clense the github repo | |
echo "Cleansing github" | |
rm -rf $MASTER_PATH/repos/github/* | |
# Copy all files from the Bitbucket to the Github | |
cp -r $MASTER_PATH/repos/bitbucket/* $MASTER_PATH/repos/github/ | |
# Go to the github | |
cd $MASTER_PATH/repos/github/ | |
# Put the statusOutput into the temp file for later | |
git status > /tmp/gitStatus | |
# Add all of the files (Just to be sure) | |
git add * | |
# Go through the status ouput file and find every file that's been deleted | |
# and then delete it | |
while read line | |
do | |
if [[ "$line" == *deleted:* ]] | |
then | |
line=${line/deleted:/} | |
line=${line/\#/} | |
git rm -r $line | |
fi | |
done < /tmp/gitStatus | |
# Make a commit message with the bitbucket commit ID | |
git commit -m "Auto sync from Bitbucket [$COMMITID]" | |
# Push all changes | |
git push | |
# Remove the temp file, but keep the repos, | |
# incase they need debugging | |
rm /tmp/gitStatus |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment