# Подключение Git repository

Анализ истории, diff и blame BSL-кода без live-подключения к 1С (режим `git-only` или дополнение к EDT).

## Prerequisites

- Git repo с выгрузкой конфигурации 1С (EDT project или xml/files layout).
- Локальный clone, доступный процессу gateway (`gitPath` readable).
- Git 2.30+ в PATH для connector (read-only: log, diff, blame).
- SSH keys или credential helper настроены **вне** gateway (секреты не в профиле).

## Пошаговая настройка

### 1. Clone репозитория

```bash
git clone git@git.example.com:team/erp-config.git /opt/1c-projects/erp-config
cd /opt/1c-projects/erp-config
git status   # clean working tree рекомендуется для стабильного blame
```

### 2. Профиль `git-only`

```json
{
  "profileId": "repo-main",
  "type": "git-only",
  "environment": "dev",
  "gitPath": "/opt/1c-projects/erp-config",
  "defaultBranch": "main"
}
```

### 3. Комбинация EDT + Git

Для полного контекста укажите оба пути в `edt-export` профиле:

```json
{
  "profileId": "dev-full",
  "type": "edt-export",
  "environment": "dev",
  "edtExportPath": "/opt/1c-projects/erp-config",
  "gitPath": "/opt/1c-projects/erp-config"
}
```

BSL index обогащается commit/blame metadata.

### 4. Web Console

Organization → Project → Connection Type: **Git-only** → укажите `gitPath` → Save → Set Active.

### 5. Проверка connector

Resource `1c://{profile}/dev/diff` и tools анализа diff доступны после первого index job.

## Copy-ready config

```bash
export ONEC_MCP_DATA_DIR=.data
export ONEC_MCP_ACTOR=local-ai-agent
npm run dev:gateway
```

Для CI read-only см. [CI_READONLY_ENDPOINT.md](./CI_READONLY_ENDPOINT.md) — mount repo + scoped token.

## Проверка tools/list

- `bsl_search`, `bsl_get_module`, `bsl_find_references`
- `discover_1c_context`, `analyze_1c_impact`
- Git-aware context в `bsl_get_context_for_task` (commits, если `gitPath` задан)

Write/patch tools доступны только при `environment: dev|test` и наличии `edtExportPath`.

## Первый тестовый prompt

```
На профиле repo-main найди через bsl_search «ЗаполнитьПоОснованию».
Покажи последние 3 коммита, затрагивающие найденный модуль (через Git metadata в контексте),
и diff текущей ветки относительно main для этого файла.
```

## Типовые ошибки

| Ошибка | Причина | Решение |
|--------|---------|---------|
| `gitPath not accessible` | Права или path | chmod/chown для user gateway |
| `not a git repository` | Нет `.git` | Clone, не копия без history |
| Пустой blame | Uncommitted changes | Commit или stash |
| SSH auth failed | Keys не у user gateway | Deploy key read-only |
| Submodule paths | Nested repos | Инициализируйте submodules |

## Security warning

- Git-only не выполняет код 1С, но patch proposals могут изменять файлы на диске — только dev + approval.
- Не храните deploy keys с write в CI read-only job.
- `.git/config` может содержать credential URLs — redaction в audit, не включайте в prompts.
- Secrets в истории коммитов — используйте secret scanning; gateway не сканирует repo автоматически.

## Related docs

- [EDT_DESIGNER_EXPORT.md](./EDT_DESIGNER_EXPORT.md) — выгрузка и индекс
- [CI_READONLY_ENDPOINT.md](./CI_READONLY_ENDPOINT.md) — PR review agent
- [MCP_CONNECTION.md](./MCP_CONNECTION.md) — patch workflow
- [SECURITY_MODEL.md](./SECURITY_MODEL.md) — write gates
