Skip to content

Instantly share code, notes, and snippets.

@thewisenerd
Last active February 9, 2022 17:17
Show Gist options
  • Save thewisenerd/75f47b03cd878b3c3659f18f97dc96cf to your computer and use it in GitHub Desktop.
Save thewisenerd/75f47b03cd878b3c3659f18f97dc96cf to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -euo pipefail
if [[ $# -eq 2 ]]; then
upstream="$1"
topic="$2"
elif [[ $# -eq 1 ]]; then
upstream="$1"
topic="HEAD"
else
# assumptions on both remote and default branch
upstream="github/master"
topic="HEAD"
fi
# shellcheck disable=SC2207
naive_list=( $(git log "$upstream"..."$topic" --no-merges --pretty=%H) )
if [[ ${#naive_list[@]} -eq 0 ]]; then
exit 0
fi
last_commit=${naive_list[ (${#naive_list[@]} - 1) ]}
last_commit_time=$(git show -s --format=%ci "$last_commit")
# shellcheck disable=SC2207
since_list=( $( git log "$upstream" --oneline --after "$last_commit_time" --no-merges --pretty=%H ) )
if [[ ${#since_list[@]} -eq 0 ]]; then
since_patches="null"
else
since_patches=$(for hash in "${since_list[@]}"; do
git show --patch-with-raw "$hash" | git patch-id --stable | cut -d' ' -f1
done)
fi
thence_patches=$(for hash in "${naive_list[@]}"; do
git show --patch-with-raw "$hash" | git patch-id --stable
done)
thence_patches_uniq=$(echo "$thence_patches" | tac | awk -F' ' '{ map[$1]++ } (map[$1] == 1){ print }' | tac)
if [[ -n "${DEBUG+x}" ]]; then
>&2 echo "---"
>&2 echo "last_commit_time"
>&2 echo "$last_commit_time"
>&2 echo "naive_list"
>&2 echo "${naive_list[@]}"
>&2 echo "since_list"
>&2 echo "${since_list[@]}"
>&2 echo "thence_patches"
>&2 echo "$thence_patches"
>&2 echo "thence_patches_uniq"
>&2 echo "$thence_patches_uniq"
>&2 echo "---"
fi
# shellcheck disable=SC2207
diff_list=( $(echo "$thence_patches_uniq" | grep -F "$since_patches" -v | cut -d' ' -f2) )
if [[ ${#diff_list[@]} -eq 0 ]]; then
exit 0;
fi
for hash in "${diff_list[@]}"; do
git show -s --format="%h %s" "$hash"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment