Find all Git Bare and non-Bare repositories?

I want to loop over all the directories and find out all the git repositories (both Bare and non-Bare). However, I need to identify which one is Bare and which one is non-Bare so that I can run different operations on them.

I checked Check if current directory is a Git repository and How do I check if a repository is bare?.

The script I came up with is:

#!/bin/bash

for d in $(find /media/ismail/8TBRaid0/ABC -path '*/.git*' -prune -o -print -type d); do

 if git --git-dir=$d rev-parse --is-inside-work-tree > /dev/null 2>&1; then

 echo ${d} is a non-Bare Repository

 elif git --git-dir=$d rev-parse --is-bare-repository > /dev/null 2>&1; then

 echo ${d} is a is a Bare Repository

 fi

done

The output I am getting is:

/media/ismail/8TBRaid0/ABC/d is a non-Bare Repository
/media/ismail/8TBRaid0/ABC/e is a non-Bare Repository

The problem is:

ABC has 5 directories.

ABC% ls -la
total 28
drwxrwxr-x  7 ismail ismail 4096 Jun  9 16:44 .
drwxr--r-- 16 ismail ismail 4096 Jun  9 16:44 ..
drwxrwxr-x  3 ismail ismail 4096 Jun  9 16:44 a
drwxrwxr-x  3 ismail ismail 4096 Jun  9 16:44 b
drwxrwxr-x  3 ismail ismail 4096 Jun  9 16:44 c
drwxrwxr-x  7 ismail ismail 4096 Jun  9 16:44 d
drwxrwxr-x  7 ismail ismail 4096 Jun  9 16:44 e

Here a,b,c are non-Bare Repositories with .git directory. And d,e are Bare Repositories without .git directory.

So, the output I am getting is definitely wrong. What i need for my case is:

a is a non-Bare Repository
b is a non-Bare Repository
c is a non-Bare Repository
d is a Bare Repository
e is a Bare Repository

How can I get the expected result?

Update 1:

My directory structure is actually deeper and scattered. The structure I gave above is as an example. For example: the structure can be:

.
├── 1
│   └── a
├── 2
│   └── 3
│       ├── b
│       └── e
│           ├── branches
│           ├── config
│           ├── description
│           ├── HEAD
│           ├── hooks
│           │   ├── applypatch-msg.sample
│           │   ├── commit-msg.sample
│           │   ├── fsmonitor-watchman.sample
│           │   ├── post-update.sample
│           │   ├── pre-applypatch.sample
│           │   ├── pre-commit.sample
│           │   ├── pre-merge-commit.sample
│           │   ├── prepare-commit-msg.sample
│           │   ├── pre-push.sample
│           │   ├── pre-rebase.sample
│           │   ├── pre-receive.sample
│           │   └── update.sample
│           ├── info
│           │   └── exclude
│           ├── objects
│           │   ├── info
│           │   └── pack
│           └── refs
│               ├── heads
│               └── tags
├── c
├── d
│   ├── branches
│   ├── config
│   ├── description
│   ├── HEAD
│   ├── hooks
│   │   ├── applypatch-msg.sample
│   │   ├── commit-msg.sample
│   │   ├── fsmonitor-watchman.sample
│   │   ├── post-update.sample
│   │   ├── pre-applypatch.sample
│   │   ├── pre-commit.sample
│   │   ├── pre-merge-commit.sample
│   │   ├── prepare-commit-msg.sample
│   │   ├── pre-push.sample
│   │   ├── pre-rebase.sample
│   │   ├── pre-receive.sample
│   │   └── update.sample
│   ├── info
│   │   └── exclude
│   ├── objects
│   │   ├── info
│   │   └── pack
│   └── refs
│       ├── heads
│       └── tags
└── f
    └── ADOC Document.adoc


Comments

Popular posts from this blog

Spring Elasticsearch Operations

Network Error and Timeout on Authorize.net JS

Object oriented programming concepts (OOPs)