# git utility functions

function git_next_unmerged_file() {
  git status | egrep '(unmerged|both modified)' | head -n 1 | sed 's/.*:   //'
}
alias git-next-unmerged-file=git_next_unmerged_file

function git_repack_all() {
  for repo in $(find . | \
      grep '/objects/pack/' | \
      sed -e 's%\.git/objects/pack/.*%%' | \
      sed -e 's%git/objects/pack/.*%git%' | sort | uniq) ; do
    pushd $repo
    git repack -ad --window 100
    git gc --prune="`date`"
    popd
  done
}

function git_fsck_all() {
  for repo in $(find . | \
      grep '/objects/pack/' | \
      sed -e 's%\.git/objects/pack/.*%%' | \
      sed -e 's%git/objects/pack/.*%git%' | sort | uniq) ; do
    pushd $repo
    git fsck
    popd
  done
}
