diff options
author | Kelley Spoon <kelley.spoon@linaro.org> | 2018-10-05 19:30:33 -0500 |
---|---|---|
committer | Kelley Spoon <kelley.spoon@linaro.org> | 2018-10-05 19:30:33 -0500 |
commit | d0817a97086e058c5feb1243386b8b968803fe53 (patch) | |
tree | 5cb14423d63e740930b2f58392ee7ce0ab14b8ca | |
parent | 40437ecfb9f7663eb798ec6bac02576f936ca5a7 (diff) |
GitCleaner: fix bugs and formatting in script
The previous version of the script did not change
directories before issuing git commands. Solved
by using pushd/popd, fixed misspelled "aggressive"
option, and fixed inconsistent spacing.
Change-Id: I67c6eab16eacbecd2258649207cb60bfd86df266
-rwxr-xr-x | git_cleaner.sh | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/git_cleaner.sh b/git_cleaner.sh index 9ab8ddd..fb69436 100755 --- a/git_cleaner.sh +++ b/git_cleaner.sh @@ -2,28 +2,38 @@ BASE=/srv/repositories +# silence pushd/popd +pushd () { + command pushd "$@" > /dev/null +} + +popd () { + command popd "$@" > /dev/null +} + for repo in $(find $BASE -type d -name "*.git"); do + pushd $repo # the gc.log is a copy of the stderr created by a backgrounded # gc process. It will block further git operations until removed # but we need a chance to at least look at what it's complaining # about first. - if [ -f ${repo}/gc.log ]; - then - echo "WARNING: found ${repo}/gc.log" + if [ -f gc.log ]; + then + echo "WARNING: found ${repo}/gc.log" cat ${repo}/gc.log rm -f ${repo}/gc.log - fi + fi - # check for dangling commits and orphans + # check for dangling commits and orphans if [ ! -z "$(git fsck --connectivity-only --no-progress)" ]; - then - # this causes dangling refs to expire now and prunes + then + # this causes dangling refs to expire now and prunes # them from the object pack. It's expensive, however, # because we end up repacking the object files. - git reflog expire --expire=now --all - ionice -c2 -n7 git gc --prune=now --agressive - else - ionice -c2 -n7 git gc --auto - fi + git reflog expire --expire=now --all + ionice -c2 -n7 -- git gc --prune=now --aggressive >/dev/null + else + ionice -c2 -n7 -- git gc --auto > /dev/null + fi done |