Skip to content

Instantly share code, notes, and snippets.

@ajtowns
Last active March 13, 2018 19:45
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ajtowns/d0cf97678dc83efdf3f6cbf7083a35a0 to your computer and use it in GitHub Desktop.
Save ajtowns/d0cf97678dc83efdf3f6cbf7083a35a0 to your computer and use it in GitHub Desktop.
github conflicting PRs
Assuming you have pull requests as part of your github remote:
[remote "origin"]
url = https://github.com/bitcoin/bitcoin.git
fetch = +refs/heads/*:refs/remotes/origin/*
fetch = +refs/pull/*/head:refs/pull/origin/*
You can do a plausible looking check for conflicts between pull requests 1, 2, 3, 4 and 5 with:
tsts="1 2 3 4 5"
for xa in $tsts; do
a=pull/origin/$xa
if (git reset --hard origin/master && git merge $a -m "merge $a to master") >/dev/null; then
for xb in $tsts; do
git reset --hard $a >/dev/null
if [ "$xa" -ge "$xb" ]; then continue; fi
b=pull/origin/$xb
if (git format-patch $(git merge-base $a $b)..$b --stdout | git apply --check -) > APPLY_${xa}_${xb} 2>&1; then
echo "no conflict between $xa $xb"
else
echo "merge conflict $xa $xb ?"
fi
done
else
echo "conflict with $a and master"
fi
done > CONFLICT
format-patch and apply --check don't touch the working tree, so it's not too inefficient.
Graphing:
(echo "graph compat {"; cat CONFLICT | sed -n 's/merge conflict \([0-9]*\) \([0-9]*\) .$/ \1 -- \2/p'; echo }) | dot -Tpng > CONFLICT.png
(echo "graph compat {"; cat CONFLICT | sed -n 's/no conflict between \([0-9]*\) \([0-9]*\)/ \1 -- \2/p'; echo }) | dot -Tpng > COMPAT.png
@PierreRochard
Copy link

Awesome! I'm going to use your logic to build a python script so that I can wrap my head around it and learn more git

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment