0

If they were working copy of git repositories, we could start simply with the approach of looking for every folder with the name ".git" (find . -type d -name ".git"), as answered here.

But in big storages, how to detect all folders containing bare git repositories?

Luciano
  • 2,695
  • 6
  • 38
  • 53

1 Answers1

0

I use the following code:

locate -b \*.git |
    while read path; do
        if [ -f "$path" ]; then
            echo "$path is a gitlink file (perhaps in a submodule)"
        elif [ -d "$path" ]; then
            if [ "`basename \"$path\"`" = .git ]; then
                echo "$path is repository"
            else
                echo "$path is bare repo"
            fi
        fi
    done

Warning 1: To use locate you need your system to be configured to run updatedb regularly (usually nightly from cron)

Warning 2: The code supposes all your bare repositories are named name.git. Mine are.

phd
  • 82,685
  • 13
  • 120
  • 165
  • This doesn't find bare repositories, but regular ones. – Luciano Feb 04 '20 at 20:24
  • Works for me. `name/.git` are regular repositories, `name.git` are bare ones. – phd Feb 04 '20 at 20:49
  • That's the problem, they might have lots of different names not following the convention `name.git` – Luciano Feb 04 '20 at 21:46
  • Conventions are to make things convenient. Those who don't follow them punish themselves unnecessary. Well, then testing for the content like in the linked duplicate is the only solution. – phd Feb 04 '20 at 22:28