git-merge-cache -o does all the automerges in a single shot
[git/repo.git] / git-prune-script
blob1a97ccc91ded1522d3016d76cbdf62557585d514
1 #!/bin/sh
2 dryrun=
3 while case "$#" in 0) break ;; esac
4 do
5 case "$1" in
6 -n) dryrun=echo ;;
7 --) break ;;
8 -*) echo >&2 "usage: git-prune-script [ -n ] [ heads... ]"; exit 1 ;;
9 *) break ;;
10 esac
11 shift;
12 done
14 : ${GIT_DIR=.git}
15 : ${GIT_OBJECT_DIRECTORY="${SHA1_FILE_DIRECTORY-"$GIT_DIR/objects"}"}
17 # Defaulting to include .git/refs/*/* may be debatable from the
18 # purist POV but power users can always give explicit parameters
19 # to the script anyway.
21 case "$#" in
23 x_40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
24 x_40="$x_40$x_40$x_40$x_40$x_40$x_40$x_40$x_40"
25 set x $(sed -ne "/^$x_40\$/p" \
26 "$GIT_DIR"/HEAD "$GIT_DIR"/refs/*/* /dev/null 2>/dev/null)
27 shift ;;
28 esac
30 git-fsck-cache --cache --unreachable "$@" |
31 sed -ne '/unreachable /{
32 s/unreachable [^ ][^ ]* //
33 s|\(..\)|\1/|p
34 }' | {
35 cd "$GIT_OBJECT_DIRECTORY" || exit
36 xargs -r $dryrun rm -f