From 44cacd6b1cee00c3326d28bffdf18df0356b7204 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sat, 14 Jan 2017 20:34:23 -0500 Subject: Make them my own. --- parent-prune-empty-first | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100755 parent-prune-empty-first (limited to 'parent-prune-empty-first') 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 -- cgit v1.2.3-2-g168b