Cincinnati Joe
Cincinnati Joe

Reputation: 2127

Way to search source in Gitolite repos?

There are a bunch of git projects in a couple of Gitolite repositories. Is there a way to search the source contained in a Gitolite repo for a keyword?

I'd like to be able to search all the git projects for keywords without having to manually clone every one of them locally first. For those projects that are built by Jenkins, the source is exposed in directories that can be searched. But not all of them are currently built in this way.

Upvotes: 2

Views: 406

Answers (3)

Sitaram
Sitaram

Reputation: 141

Well, you could always create a "grep" command. After all, if you can run 'symbolic-ref', what's grep?

One issue will be that gitolite's restrictions on allowed characters would put a crimp in arbitrary regexes being supplied. (If someone really, really wants this -- and by that I mean they ask on the mailing list and at least a couple more people chime in saying "yes we want it!"), I could create a way to allow some programs to have unrestricted arguments. That code is just waiting to be pulled off from the 'git-annex' branch, but getting no love for testing, so far).

You could even make it search multiple projects. For example, to make it search all the projects the user has read access to, you could start with this:

gitolite list-phy-repos | gitolite access % $GL_USER W any | grep -v DENIED | cut -f1

and then for each repo that comes up with, you cd into it and run 'git grep'

The next stage in complexity would be a list of repos you want to search/not search (because you just happen to be the guy who has access to all the repos, and that's not really what you want!). This gets a little harder to design effectively. It may be easier to mark searchable repos in the conf file itself, using a groupname of some sort. The grep command could easily check for membership in that special group as an additional constraint.

Sitaram

Upvotes: 0

Cincinnati Joe
Cincinnati Joe

Reputation: 2127

A former coworker that I emailed knew a way to do this. On the machine where the repo is stored, cd into the repository directory that contains the projects. Inside an individual project's .git dir, you can use "git grep" on HEAD or a branch. To search across all dirs, use a loop from the dir of project dirs:

for x in *; do
  cd $x
  git grep "MyString" HEAD
  cd ..
done

An example with more options, including the name of the project that contains each match:

for x in *; do
  cd $x
  git grep -i "mystring" HEAD -- '*.java' | sed "s|\(.*\)|$x-->\1|"
  cd ..
done

Upvotes: 1

VonC
VonC

Reputation: 1329082

Gitolite is just an authorization layer, which intercepts:

  • git command
  • user id

, and decides if the git command is allowed to proceed.

It has nothing to do with the search feature itself.

You need another app to implement the search itself in your git repo, like Elasticsearch.
See "Searching a git repository with ElasticSearch".

You can then couple it with gitolite (in order to allow the search or to filter the search results, depending on gitolite access rules).

Upvotes: 0

Related Questions