diff options
Diffstat (limited to 'parent-prune-empty-first')
-rwxr-xr-x | parent-prune-empty-first | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/parent-prune-empty-first b/parent-prune-empty-first new file mode 100755 index 0000000..c9d73df --- /dev/null +++ b/parent-prune-empty-first @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +# Usage: git filter-branch -f --parent-filter ~/git-filters/parent-prune-empty-first HEAD + +has_empty_tree() { + [[ "$(git rev-parse "${1}^{tree}")" == 4b825dc642cb6eb9a060e54bf8d69288fbee4904 ]] +} + +has_parents() { + git rev-parse "${1}^" &>/dev/null +} + +for parent in $(cat); do + if [[ "$parent" == '-p' ]]; then + continue + fi + if has_empty_tree "$parent" && ! has_parents "$parent"; then + continue + fi + printf ' -p %s ' "$parent" +done +echo |