Skip to content

Instantly share code, notes, and snippets.

@toxinu
Created December 10, 2019 17:02
Show Gist options
  • Save toxinu/fc6ebb70a578870a652b1160fdfc43fd to your computer and use it in GitHub Desktop.
Save toxinu/fc6ebb70a578870a652b1160fdfc43fd to your computer and use it in GitHub Desktop.
drifted-code.sh
#!/bin/bash
BRANCH_1=$1
BRANCH_2=$2
# Can be "both", "merged", "not-merged"
SHOW=${SHOW:-'both'}
if [ -z ${BRANCH_1} ] || [ -z ${BRANCH_2} ]; then
printf "Usage: ./drifted-commits.sh <ORIGIN_BRANCH> <TARGET_BRANCH>\n"
exit 1
fi
red=$'\e[1;31m'
grn=$'\e[1;32m'
end=$'\e[0m'
IFS='
'
for line in `git log ^${BRANCH_1} ${BRANCH_2} --oneline`; do
commit=$(echo ${line} | cut -d' ' -f1)
result=$(GIT_PAGER=cat git branch -a -l --contains ${commit})
merged=0
for branch in ${result}; do
if [[ "${branch}" == *"/open-release/"* ]]; then
merged=1
merged_branch=${branch}
fi
done
if [ ${merged} -eq 1 ]; then
if [ ${SHOW} = "both" ] || [ ${SHOW} = "merged" ]; then
printf "${grn}"
printf "${line} -> ${merged_branch}\n"
fi
else
if [ ${SHOW} = "both" ] || [ ${SHOW} = "not-merged" ]; then
printf "${red}"
printf "${line} ( https://github.com/open-craft/edx-platform/commit/${commit} )\n"
fi
fi
printf "${end}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment