Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
373 views
in Technique[技术] by (71.8m points)

Looking for folders containing valid git bare repositories

In big storages, how to detect all folders containing only bare git repositories?

I don't mean just looking for the usual content or some content of git bare repositories, but real valid repositories.

CURRENT APPROACH:

The answer here just find folders having basic content that may look like a git bare repository, so we could improve it trying to execute git status on every folder matching this basic structure, but I'm not sure it would be the best approach to ensure this is a bare repository, not to say that git status returns the error fatal: this operation must be run in a work tree on bare repositories requiring us to assume it means a bare repository. So we would have to expect to receive that output for each checking and only thus assume it's a valid git bare repository.

Is there any better way to find them?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You should detect them the way Git detects them, which is outlined in the answer you quoted. To wit, you need the following:

  • an objects/ directory;
  • a refs/ directory; and
  • either a HEAD symlink or a HEAD file that is properly formatted.

The exact specification is documented in the source code in setup.c.

If you have what you suspect is a Git repository, you can change into it and run git rev-parse --git-dir, which will exit successfully if you're in a Git repository, and exit unsuccessfully if you're not. You can also use git rev-parse --is-bare-repository and look for either true or false to determine whether your repository is bare.

If you don't want to change into the repository, you can use git -C <DIR> rev-parse --git-dir and similar to operate on the mentioned directory instead.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...