Last active
September 10, 2024 02:16
-
-
Save jesstelford/7762134 to your computer and use it in GitHub Desktop.
List the Pull Requests which have been merged into one branch but not another. Execute this from within a git directory that has it's `origin` remote set to github.
This file contains hidden or 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
#!/bin/sh | |
if (( $# < 2 )) || (( $# > 3 )) | |
then | |
echo "$0 <are-in-this-branch> <are-not-in-this-branch> [<url-of-repo>]" | |
exit 1 | |
fi | |
URLPREFIX= | |
if (( $# == 3 )) | |
then | |
URLPREFIX=$(echo "$3/pull/" | sed -e 's/[\/&]/\\&/g') | |
fi | |
echo "PR's which are merged in branch '$1', but not in '$2':" | |
# Get all the Pull Request head commits | |
git fetch origin "+refs/pull/*/head:refs/remotes/origin/pr/*" &>/dev/null | |
# Generate a list of all PR's contained in the specified branches | |
git branch -r --merged $1 | grep "origin/pr/*" | sort > /tmp/inthis.txt | |
git branch -r --merged $2 | grep "origin/pr/*" | sort > /tmp/notinthis.txt | |
# Clean up after getting all the PR head commits | |
git remote prune origin &>/dev/null | |
# Compare the lists of PR's contained in branches, and output result | |
comm -23 /tmp/inthis.txt /tmp/notinthis.txt | sed "s, origin/pr/,$URLPREFIX,g" | |
# Clean up temp files | |
rm /tmp/inthis.txt | |
rm /tmp/notinthis.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment