From 776a6ca1e48a3e5938dd838813b3b8d8cfd5f4db Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Mon, 10 May 2021 17:01:54 +0200 Subject: [PATCH] sh: add commit propagator tool --- garlic/sh/default.nix | 2 + garlic/sh/garlic-propagate-commit | 63 +++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100755 garlic/sh/garlic-propagate-commit diff --git a/garlic/sh/default.nix b/garlic/sh/default.nix index 8d5c6f9..e88a616 100644 --- a/garlic/sh/default.nix +++ b/garlic/sh/default.nix @@ -35,5 +35,7 @@ in mkdir -p $out/share/man/man1 cp garlic.1 $out/share/man/man1 cp garlic-git-table $out/bin + patchShebangs garlic-propagate-commit + cp garlic-propagate-commit $out/bin ''; } diff --git a/garlic/sh/garlic-propagate-commit b/garlic/sh/garlic-propagate-commit new file mode 100755 index 0000000..04617e1 --- /dev/null +++ b/garlic/sh/garlic-propagate-commit @@ -0,0 +1,63 @@ +#!/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