Created
August 22, 2019 20:23
-
-
Save jmgao/681b34e242e5392ac690bd3b7e26d92c to your computer and use it in GitHub Desktop.
This file contains 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
function _cherry() { | |
local dry=$1 | |
local src_branch=$2 | |
local local_path=$3 | |
if [[ -z "$local_path" ]]; then | |
local_path="." | |
fi | |
echo "git cherry $src_branch HEAD | grep '^+' | cut -d' ' -f2" | |
for sha in `git cherry $src_branch HEAD | grep '^+' | cut -d' ' -f2`; do | |
if [[ -e $local_path ]]; then | |
local color_reset="\x1b[0m" | |
local color_bold="\x1b[1m" | |
local color_red="\x1b[31;1m" | |
local color_green="\x1b[32;1m" | |
local check=`git show $sha $local_path | wc -l` | |
local commit_description="`git --no-pager log --oneline -n1 $sha`" | |
if [[ $check == "0" ]]; then | |
echo "${color_red}[SKIP]${color_reset} $commit_description" | |
continue | |
else | |
echo "${color_green}[PICK]${color_reset}${color_bold} $commit_description${color_reset}" | |
if [[ $dry != true ]]; then | |
git cherry-pick -x $sha || return | |
fi | |
fi | |
fi | |
done | |
} | |
function cherry() { | |
_cherry false $@ | |
} | |
function cherry_dry() { | |
_cherry true $@ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment