45
45
# -u Exit if a variable is referenced before assigned
46
46
# -x Print out commands before they are executed
47
47
# -o pipefail Include non-zero exit codes, even if a command piped into another command fails
48
- set -euxo pipefail
48
+ # -o pipefail seems to cause all piping to fail
49
+ # set -euxo pipefail
50
+ set -eux
49
51
50
52
# Get the repo's root directory as the first parameter
51
53
# Assumes this directory has a .git subdirectory
@@ -74,6 +76,7 @@ cd "$REPOSITORY_DIRECTORY"
74
76
# Print the sizes of files in the repo's directory
75
77
echo " Sizes in the repo's .git directory, before garbage collection:"
76
78
du -sc .git/*
79
+ start_size=" $( du -s .git | awk ' {print $1}' ) "
77
80
78
81
# Track files to be cleaned up on exit
79
82
declare -a files_to_cleanup
@@ -229,8 +232,11 @@ git pack-refs --all --prune
229
232
# Continue the script if this command fails
230
233
set +e
231
234
# Try to get the git config values, if they exist
232
- git config get gc.reflogExpire
233
- git config get gc.reflogExpireUnreachable
235
+ # If they don't exist, git config returns a non-zero exit code
236
+ reflogExpire=$( git config get gc.reflogExpire)
237
+ reflogExpireUnreachable=$( git config get gc.reflogExpireUnreachable)
238
+ echo " gc.reflogExpire: $reflogExpire "
239
+ echo " gc.reflogExpireUnreachable: $reflogExpireUnreachable "
234
240
# Revert back to the previous Bash options
235
241
set -e
236
242
#
@@ -290,7 +296,7 @@ git repack -d -A --unpack-unreachable=now --write-bitmap-index -l --window-memor
290
296
git commit-graph write --reachable --changed-paths --progress
291
297
292
298
# Reset Bash option for pipefail, because it seems to break piping git | head
293
- set +o pipefail
299
+ # set +o pipefail
294
300
295
301
# Test if the repo is corrupted
296
302
git show HEAD | head -n 1
@@ -301,4 +307,13 @@ git log --all | head -n 1
301
307
# Print the sizes of files in the repo's directory
302
308
echo " Sizes in the repo's .git directory, after garbage collection:"
303
309
du -sc .git/*
310
+
311
+ # Subtract 4 KB for the lock files which haven't been removed yet
312
+ end_size=" $( du -s .git | awk ' {print $1}' ) "
313
+ end_size=" $(( end_size - 4 )) "
314
+
315
+ echo " Repo $REPOSITORY_DIRECTORY "
316
+ echo " Size before garbage collection: $start_size KB"
317
+ echo " Size after garbage collection: $end_size KB"
318
+ echo " Storage saved: $(( start_size - end_size)) KB"
304
319
# ##############################################################################
0 commit comments