sourcebot-dev / sourcebot

Blazingly fast code search 🏎️ Deployed as a single Docker image 📦 Search million+ lines of code in your GitHub and GitLab repositories 🪄 MIT licensed ✅
MIT License
750 stars 17 forks source link

FR: Support indexing of local directories #19

Open BojanKV opened 3 days ago

BojanKV commented 3 days ago

Hej :)

It would be great if Sourcebot could handle local directory with one or more git repositories.

(Also, any pointers can be useful to implement such support by myself - also great learning) :)

Thanks! :)

mdaniel commented 8 hours ago

(Also, any pointers can be useful to implement such support by myself - also great learning) :)

I had a similar need, made worse by the fact that the repo I wanted indexed was several gigs and thus I didn't want sourcebot to reclone it since I already have it locally

So, I cheated and just moved the .git into the directory that zoekt-mirror-github was expecting:

mkdir -p /data/.sourcebot/repos/github.com/ExAmPlEOrG/my-awesome-repo
mv $WHATEVER/.git /data/.sourcebot/repos/github.com/ExAmPlEOrG/my-awesome-repo
docker run ...

if that work-around is good enough for your situation, too


The other trick I was going to try if that one didn't work was to stub out the GitHub API handlers inside sourcebot so the config would say

  "Configs": [
    {
      "Type": "github",
      "GitHubUrl": "http://127.0.0.1:3000/fake-github",
      "GitHubOrg": "whatever",
    }]

which would cause zoekt-mirror-github to request "http://127.0.0.1:3000/fake-github/api/v3/orgs/whatever/repos" and we're all friends. However, that trickery didn't work because zoekt assumes there are no path segments and it actually requested "http://127.0.0.1:3000/api/v3/orgs/whatever/repos" made worse by the fact that it requested it so early in the boot process that express wasn't running yet, causing it to "dial tcp 127.0.0.1:3000: connect: connection refused"

brendan-kellam commented 2 hours ago

We are planning on doing some refactoring of how repositories cloned and managed soon. We will include local repository support as requirement. For now, @mdaniel's first solution is a good workaround currently.

Another option is zoekt includes a zoekt-git-index command, which can be used to index local git repositories and produce a .zoekt index. You could try using that command and placing the produced index files into .sourcebot/index