summaryrefslogtreecommitdiff
path: root/parent-prune-empty-first
blob: c9d73dfb1ade1aeebb68f37650bfe9f26aeee8ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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