Skip to content

Instantly share code, notes, and snippets.

@Exadra37
Created March 18, 2015 22:46
Show Gist options
  • Save Exadra37/0dba72504ab36c5a424c to your computer and use it in GitHub Desktop.
Save Exadra37/0dba72504ab36c5a424c to your computer and use it in GitHub Desktop.
Maintain your Prestashop fork synchronized / updated with the original repository.
#!/bin/bash
# @author Exadra37 <exadra37ingmailpointcom>
# @since 2015/03/18
# @link exadra37.com
# @see Heavily inspired in http://stackoverflow.com/a/7244456
#
#
# I use this script to update my Prestashop fork when i want to make a contribution
#
# exit immediately from script on error
set -e
#################################################################################################################################################################
# Functions
#################################################################################################################################################################
function getScriptDir {
script_dir=$( cd "$( dirname "$0" )" && pwd )
}
function defineColors {
# defining colors vars
black=`tput setaf 0`
red=`tput setaf 1`
green=`tput setaf 2`
yellow=`tput setaf 3`
blue=`tput setaf 4`
magenta=`tput setaf 5`
cyan=`tput setaf 6`
white=`tput setaf 7`
reset=`tput sgr0`
}
#################################################################################################################################################################
# Start Execution
#################################################################################################################################################################
start_time=`date +%s`
defineColors
getScriptDir
use_defaults='false'
# check if we want to run with default settings
while getopts 'D' flag; do
case "${flag}" in
D) use_defaults='true' ;;
*) printf "\n${red}Error: option is not valid. ${reset}\n" && exit 1 ;;
esac
done
printf "\n${yellow}By Exadra37 - Prestashop Moderator in Portuguese Community \n"
printf "\nGithub Repositories: https://github.com/Exadra37?tab=repositories"
printf "\n Github Gists: https://gist.github.com/Exadra37"
printf "\n Prestashop Profile: https://prestashop.com/forums/user/34974-exadra37"
printf "\n My Website: http://exadra37.com ${reset}\n"
printf "\n${green}##### Start Fork Synchronization With Original Repository ##### ${reset}\n\n"
#################################################################################################################################################################
# Get Arguments
#################################################################################################################################################################
if [ "false" = "$use_defaults" ]
then
if [ "$1" ]
then
sync_path="$1"
else
read -p "${magenta}Absolute path to synchronize folder: ${reset}" sync_path
fi
fi
if [ -z "$sync_path" ]
then
datetime="`date +%F_%H:%M:%S`"
sync_path="$HOME/Downloads/syncfork/sync_$datetime"
fi
#################################################################################################################################################################
# Logic
#################################################################################################################################################################
# Preparing the working space
[ -d "$sync_path" ] || mkdir -p "$sync_path"
cd "$sync_path"
# Start by clone your fork into your local machine
# git clone [email protected]:github_user/github_repo.git
git clone [email protected]:Exadra37/PrestaShop.git
# cd github_repo
cd PrestaShop
# Add the remote, call it "upstream":
# using ssh
# git remote add upstream [email protected]:github_user/github_repo.git
git remote add upstream [email protected]:Prestashop/Prestashop.git
# using https
# git remote add upstream https://github.com/github_user/github_repo.git
# git remote add upstream https://github.com/Prestashop/Prestashop.git
# Fetch all the branches of that remote into remote-tracking branches,
# such as upstream/master:
git fetch upstream
# Normally the default branch in the repo should be the master,
# but sometimes you have repos that the default branch have another name, despite of master branch existence...
# Make sure that you're on your master(default) branch:
# for a repo with master as the default branch
# git checkout master
# for repos like Prestashop, that the default branch have another name, in this case 1.6
git checkout 1.6
# another approach
# git checkout -b sync/upstream origin/master
# Rewrite your master(default) branch so that any commits of yours that
# aren't already in upstream/master are replayed on top of that
# other branch:
# for a repo with master as the default branch
# git rebase upstream/master
# for repos like Prestashop, that the default branch have another name, in this case 1.6
git rebase upstream/1.6
# force update of our fork
# for a repo with master as the default branch
# git push -f origin master
# for repos like Prestashop, that the default branch have another name, in this case 1.6
git push -f origin 1.6
# start developing in a new branch
# for a repo with master as the default branch
# git checkout -b env/dev origin/master
# for repos like Prestashop, that the default branch have another name, in this case 1.6
git checkout -b env/dev origin/1.6
#################################################################################################################################################################
# End Execution
#################################################################################################################################################################
end_time=`date +%s`
execution_time=$((end_time-start_time))
printf "\n\n${yellow}Total Execution Time: ${reset}$(($execution_time / 60)).$(($execution_time % 60))s"
printf "\n${green}##### End Fork Synchronization With Original Repository #####${reset}\n\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment