git/git-prune.sh
Junio C Hamano 2b86976bfd git-prune: never lose objects reachable from our refs.
Explicit <head> arguments to git-prune replaces, instead of
extends, the list of heads used for reachability analysis by
fsck-objects.  By giving a subset of heads by mistake, objects
reachable only from other heads can be removed, resulting in a
corrupted repository.

This commit stops replacing the list of heads, and makes the
command line arguments to add to them instead for safety.

Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-12-08 23:18:41 -08:00

45 lines
788 B
Bash
Executable file

#!/bin/sh
. git-sh-setup
dryrun=
echo=
while case "$#" in 0) break ;; esac
do
case "$1" in
-n) dryrun=-n echo=echo ;;
--) break ;;
-*) echo >&2 "usage: git-prune [ -n ] [ heads... ]"; exit 1 ;;
*) break ;;
esac
shift;
done
sync
case "$#" in
0) git-fsck-objects --full --cache --unreachable ;;
*) git-fsck-objects --full --cache --unreachable $(git-rev-parse --all) "$@" ;;
esac |
sed -ne '/unreachable /{
s/unreachable [^ ][^ ]* //
s|\(..\)|\1/|p
}' | {
cd "$GIT_OBJECT_DIRECTORY" || exit
xargs $echo rm -f
rmdir 2>/dev/null [0-9a-f][0-9a-f]
}
git-prune-packed $dryrun
redundant=$(git-pack-redundant --all)
if test "" != "$redundant"
then
if test "" = "$dryrun"
then
echo "$redundant" | xargs rm -f
else
echo rm -f "$redundant"
fi
fi