|
| 1 | +--- |
| 2 | +title: Local Git repositories |
| 3 | +--- |
| 4 | + |
| 5 | +import GenericGitHost from '/snippets/schemas/v3/genericGitHost.schema.mdx' |
| 6 | + |
| 7 | +<Note> |
| 8 | +This feature is only supported when [self-hosting](/self-hosting/overview). |
| 9 | +</Note> |
| 10 | + |
| 11 | +Sourcebot can sync code from generic git repositories stored in a local directory. This can be helpful in scenarios where you already have a large number of repos already checked out. Local repositories are treated as **read-only**, meaing Sourcebot will **not** `git fetch` new revisions. |
| 12 | + |
| 13 | +## Getting Started |
| 14 | + |
| 15 | +<Warning> |
| 16 | +Only folders containing git repositories at their root **and** have a `remote.origin.url` set in their git config are supported at this time. All other folders will be skipped. |
| 17 | +</Warning> |
| 18 | + |
| 19 | +Let's assume we have a `repos` directory located at `$(PWD)` with a collection of git repositories: |
| 20 | + |
| 21 | +```sh |
| 22 | +repos/ |
| 23 | +├─ repo_1/ |
| 24 | +├─ repo_2/ |
| 25 | +├─ repo_3/ |
| 26 | +├─ ... |
| 27 | +``` |
| 28 | + |
| 29 | +To get Sourcebot to index these repositories: |
| 30 | + |
| 31 | +<Steps> |
| 32 | + <Step title="Mount a volume"> |
| 33 | + We need to mount a docker volume to the `repos` directory so Sourcebot can read it's contents. Sourcebot will **not** write to local repositories, so we can mount a seperate **read-only** volume: |
| 34 | + |
| 35 | + ``` bash |
| 36 | + docker run \ |
| 37 | + -v $(pwd)/repos:/repos:ro \ |
| 38 | + /* additional args */ \ |
| 39 | + ghcr.io/sourcebot-dev/sourcebot:latest |
| 40 | + ``` |
| 41 | + </Step> |
| 42 | + |
| 43 | + <Step title="Create a connection"> |
| 44 | + We can now create a new git [connection](/docs/connections/overview), specifying local paths with the `file://` prefix. Glob patterns are supported. For example: |
| 45 | + |
| 46 | + ```json |
| 47 | + { |
| 48 | + "type": "git", |
| 49 | + "url": "file:///repos/*" |
| 50 | + } |
| 51 | + ``` |
| 52 | + |
| 53 | + Sourcebot will expand this glob pattern into paths `/repos/repo_1`, `/repos/repo_2`, etc. and index all valid git repositories. |
| 54 | + </Step> |
| 55 | +</Steps> |
| 56 | + |
| 57 | +## Examples |
| 58 | + |
| 59 | + |
| 60 | +<AccordionGroup> |
| 61 | + <Accordion title="Sync individual repo"> |
| 62 | + ```json |
| 63 | + { |
| 64 | + "type": "git", |
| 65 | + "url": "file:///path/to/git_repo" |
| 66 | + } |
| 67 | + ``` |
| 68 | + </Accordion> |
| 69 | + <Accordion title="Sync multiple repos using glob patterns"> |
| 70 | + ```json |
| 71 | + // Attempt to sync directories contained in `repos/` (non-recursive) |
| 72 | + { |
| 73 | + "type": "git", |
| 74 | + "url": "file:///repos/*" |
| 75 | + } |
| 76 | + ``` |
| 77 | + </Accordion> |
| 78 | +</AccordionGroup> |
| 79 | + |
| 80 | +## Schema reference |
| 81 | + |
| 82 | +<Accordion title="Reference"> |
| 83 | +[schemas/v3/genericGitHost.json](https://github.com/sourcebot-dev/sourcebot/blob/main/schemas/v3/genericGitHost.json) |
| 84 | + |
| 85 | +<GenericGitHost /> |
| 86 | + |
| 87 | +</Accordion> |
0 commit comments