Created
July 11, 2017 00:29
-
-
Save robison/8c4f25acadbce15c7106f32816f2a906 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
#!/bin/sh | |
OLDIFS=$IFS | |
IFS=$'\n\t' | |
for commit in $( git fsck --unreachable HEAD | awk '$2 == "commit" {print substr($3,1,7)}' ) | |
do | |
printf "\nGit orphan: ${commit}\n" | |
printf "%s\n" $( TZ=UTC git log -1 --date=iso-local --pretty=format:"parents: %<(24)%porphan: %<(10)%h%<(30)%an%<(26)%ad%s" ${commit} ) | |
parents=() | |
IFS=$' \n\t' | |
for parent in $( git log -1 --pretty=format:"%p" ${commit} ) | |
do | |
IFS=$'\n\t' | |
parent_result="$( TZ=UTC git log --date=iso-local --pretty=format:"parents: %<(24)%pcommit: %<(10)%h%<(30)%an%<(26)%ad%s" HEAD | grep "$parent\|$commit" )" | |
if [[ ${#parent_result} -gt 0 ]] | |
then | |
for i in ${parent_result[@]} | |
do | |
parents+=( "${i}" ) | |
done | |
else | |
parents+=( "<parent ${parent} is also orphaned>" ) | |
fi | |
done | |
IFS=$'\n\t' | |
# this is super hacky | |
for line in ${parents[@]} | |
do | |
printf "%s\n" ${line} | |
done | |
done | |
IFS=$OLDIFS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment