3 #==============================================================================
5 # File ID: 13613774-3334-11e0-bfdc-fefdb24f8e10
7 # Create branches on every dangling commit
9 # Author: Øyvind A. Holm <sunny@sunbase.org>
10 # License: GNU General Public License version 2 or later.
11 #==============================================================================
22 while test -n "$1"; do
24 -b|
--blobs) opt_blobs
=1; shift ;;
25 -c|
--check-part) opt_checkpart
=1; shift ;;
26 -D|
--delete-only) opt_deleteonly
=1; shift ;;
27 -h|
--help) opt_help
=1; shift ;;
28 -q|
--quiet) opt_quiet
=$
(($opt_quiet + 1)); shift ;;
29 -v|
--verbose) opt_verbose
=$
(($opt_verbose + 1)); shift ;;
30 --version) echo $progname $VERSION; exit 0 ;;
33 if printf '%s\n' "$1" |
grep -q ^
-; then
34 echo "$progname: $1: Unknown option" >&2
42 opt_verbose
=$
(($opt_verbose - $opt_quiet))
44 if test "$opt_help" = "1"; then
45 test $opt_verbose -gt 0 && { echo; echo $progname $VERSION; }
48 Restore dangling branches, tags or blobs. Branches will be stored as
49 commit-[SHA1], tags as tag-[SHA1] and blobs as blob-[SHA1].
51 Usage: $progname [options]
56 Store dangling blobs as blob-[SHA1] files.
58 Check if any commit-* branches are part of any other branch. Does
59 not scan for dangling objects.
61 Only delete commit-* branches and tag-* tags, don't check for
62 dangling branches, tags or blobs.
66 Be more quiet. Can be repeated to increase silence.
68 Increase level of verbosity. Can be repeated.
70 Print version information.
76 bannedfile
=$HOME/.git-dangling-banned
77 dangfile
=.git
/dangling-result.tmp
80 if test "$opt_blobs" = "1"; then
84 if test "$opt_checkpart" = "1"; then
85 # Check if commit-* branches are part of any other branch
86 for f
in $
(git branch | cut
-c 3- |
grep '^commit-'); do
87 echo ============ $progname: $f
88 git branch
-a --contains=$f |
grep -v "^ $f\$"
93 if test "$opt_deleteonly" = "1"; then
94 # Delete all commit-* branches
95 git branch | cut
-c 3- |
grep -E '^commit-[0-9a-f]{40}$' |
96 grep -Ev commit-0
{40} |
xargs -r git branch
-D
98 # Delete all tag-* tags
99 git tag |
grep -E '^tag-[0-9a-f]{40}$' |
while read f
; do
105 cd "$(git rev-parse --show-toplevel)" ||
{
106 echo $progname: Could not chdir to top level of repo
>&2
109 test -d .git
/. || dangfile
=$
(basename $dangfile)
111 git fsck
--no-reflogs >$dangfile
112 for f
in `grep "^dangling commit" $dangfile | cut -f 3 -d ' '`; do
113 git branch commit-
$f $f && echo $progname: Creating commit-
$f
115 for f
in `grep "^dangling tag" $dangfile | cut -f 3 -d ' '`; do
116 git tag tag-
$f $f && echo $progname: Creating tag-
$f
118 if test "$store_blobs" = "1"; then
119 for f
in `grep "^dangling blob" $dangfile | cut -f 3 -d ' '`; do
120 git show
$f >blob-
$f && echo $progname: Creating blob-
$f
124 test "$dangfile" = "$(basename $dangfile)" && rm $dangfile
127 # vim: set ts=8 sw=8 sts=8 noet fo+=w tw=79 fenc=UTF-8 :