#!/bin/bash -e function printHelp() { >&2 echo "Usage: garlic-propagate-commit " >&2 echo cat >&2 </dev/null | sed 's/^..//'` == $1 ]]; then return 0 else return 1 fi } if [ $# -lt 1 ]; then printHelp exit 1 fi # Obtain all the tracked branches branches=(`git branch | sed 's/^..//'`) currentBranch=`git rev-parse --abbrev-ref HEAD` # Make sure that the commit SHA exists commit=$1 if branchContainsCommit $currentBranch $commit; then echo "Commit $commit exists in current branch, proceeding..." else echo "Error: Commit $commit does not exist in the current branch" exit 1 fi # Distribute the commit for all tracked branches for branch in ${branches[@]}; do if [[ $branch != $currentBranch ]]; then echo "Trying to add commit $commit to branch $branch" if branchContainsCommit $branch $commit; then echo "Branch $branch already contains commit $commit, skipping" else git checkout $branch git cherry-pick $commit git push fi fi done # Return to the original branch git checkout $currentBranch