#!/bin/bash function current_branch() { ref="$(git symbolic-ref HEAD)" echo ${ref#refs/heads/} } case "$1" in "" | "tyndur") repo=~/entwicklung/tyndur ;; "cdi") repo=~/entwicklung/cdi ;; *) echo "Unknown repository" >&2 exit ;; esac cd $repo stash_pop=0 if git stash | grep -v "No local changes" > /dev/null; then stash_pop=1 fi old_branch="$(current_branch)" git checkout queue-in if ! git am -3 -s --whitespace fix; then echo -e "\033[31mAborting git am\033[0m" git am --abort else echo -e "\033[32mPatch applied\033[0m" fi git checkout "$old_branch" if [ $stash_pop = "1" ]; then git stash pop > /dev/null fi