Git-Integration¶
Polycrate bietet eine native Git-Integration basierend auf go-git, die ohne externe Git-Installation funktioniert. Alle Git-Operationen werden direkt in der CLI ausgeführt.
Überblick¶
graph LR
User[Entwickler] --> Status[polycrate git status]
User --> Add[polycrate git add]
User --> Commit[polycrate git commit]
User --> Push[polycrate git push]
User --> Pull[polycrate git pull]
User --> Sync[polycrate git sync]
Sync --> |1. Stage| Add
Sync --> |2. Commit| Commit
Sync --> |3. Pull| Pull
Sync --> |4. Push| Push Workspace-Aliase
Alle Git-Commands sind auch als polycrate workspace * Aliase verfügbar:
polycrate workspace pull→polycrate git pullpolycrate workspace push→polycrate git pushpolycrate workspace sync→polycrate git syncpolycrate workspace add→polycrate git addpolycrate workspace commit→polycrate git commit
Diese Aliase ermöglichen eine intuitivere UX, bei der alle Workspace-bezogenen Operationen unter polycrate workspace verfügbar sind.
Verfügbare Commands¶
polycrate git status¶
Zeigt den Status des Workspace-Repositories an.
Ausgabe:
Branch: main
Commit: a1b2c3d (feat: add new feature)
Staged changes:
new: blocks/my-block/block.poly
modified: workspace.poly
Unstaged changes:
modified: artifacts/config.yml
Untracked files:
temp.txt
Farbcodierung:
| Status | Farbe | Bedeutung |
|---|---|---|
new: | Grün | Neue Datei |
modified: | Gelb | Geänderte Datei |
deleted: | Rot | Gelöschte Datei |
renamed: | Cyan | Umbenannte Datei |
copied: | Cyan | Kopierte Datei |
polycrate git add¶
Stagt Dateien für den nächsten Commit.
# Einzelne Datei stagen
polycrate git add <datei>
# Alle Änderungen stagen
polycrate git add --all
polycrate git add -a
Beispiele:
polycrate git commit¶
Erstellt einen neuen Commit mit den gestagten Änderungen.
Optionen:
| Flag | Beschreibung |
|---|---|
-m, --message | Commit-Nachricht (erforderlich) |
Beispiele:
polycrate git commit -m "feat: add database block"
polycrate git commit -m "fix: correct kubeconfig path"
polycrate git push¶
Pusht lokale Commits zum Remote-Repository.
Features:
- Zeigt Spinner während des Push-Vorgangs
- Automatische Authentifizierung via SSH-Key aus dem Workspace
polycrate git pull¶
Pullt Änderungen vom Remote-Repository.
Features:
- Conflict-Erkennung VOR dem Pull: Prüft ob lokale Änderungen mit Remote-Änderungen kollidieren würden
- Zeigt Spinner während des Pull-Vorgangs
Bei Konflikten:
Error: Cannot pull - local changes would be overwritten:
- workspace.poly
- blocks/my-block/config.yml
Please commit or stash your changes before pulling.
polycrate git sync¶
Automatischer Sync-Workflow: Commit, Pull, Push in einem Schritt.
Ablauf:
- Stage: Alle Änderungen werden gestagt (
git add --all) - Commit: Automatischer Commit mit generierter Nachricht
- Pull: Remote-Änderungen werden geholt
- Push: Lokale Commits werden gepusht
Beispiel:
$ polycrate git sync
Staging all changes...
✓ 3 files staged
Creating commit...
✓ Commit created: "polycrate: sync workspace"
Pulling from remote...
✓ Already up to date
Pushing to remote...
✓ Pushed to origin/main
Sync completed successfully.
Anwendungsfall:
Ideal für schnelle Synchronisierung nach Änderungen:
# Nach dem Ausführen einer Action
polycrate run my-block deploy
# Workspace synchronisieren
polycrate git sync
Workflow-Beispiele¶
Täglicher Workflow¶
# 1. Morgens: Remote-Änderungen holen
polycrate git pull
# 2. Arbeiten...
polycrate run my-block configure
# 3. Status prüfen
polycrate git status
# 4. Änderungen committen
polycrate git add --all
polycrate git commit -m "feat: update configuration"
# 5. Pushen
polycrate git push
Schneller Sync¶
Selektives Committen¶
# Nur bestimmte Dateien committen
polycrate git add workspace.poly
polycrate git add blocks/important-block/
polycrate git commit -m "feat: update important block"
polycrate git push
# Andere Änderungen später
polycrate git add --all
polycrate git commit -m "chore: minor updates"
polycrate git push
Integration mit Workspace List¶
Die Workspace List zeigt Git-Informationen für jeden Workspace:
NAME ORG ENC MODIFIED COMMIT STATUS AUTHOR
production acme 🔒 2024-01-15 10:30 a1b2c3d clean John Doe
staging acme 2024-01-14 16:45 d4e5f6g dirty Jane Smith
- COMMIT: Short-Hash des letzten Commits
- STATUS:
clean(keine Änderungen) oderdirty(uncommitted changes) - AUTHOR: Autor des letzten Commits
Auto-Commit (optional)¶
Polycrate kann automatisch nach jeder Action committen:
Oder in der workspace.poly:
Dies erstellt automatisch einen Commit mit Transaction-ID nach jeder erfolgreichen Action.
SSH-Authentifizierung¶
Git-Operationen nutzen den SSH-Key aus dem Workspace:
- Neuer Pfad:
artifacts/secrets/id_rsa - Legacy-Pfad:
id_rsaim Workspace-Root
Bei verschlüsselten Workspaces muss der Workspace vor Git-Operationen entschlüsselt sein:
SSH-Key mit Passphrase¶
Falls Ihr SSH-Key eine Passphrase hat:
Siehe SSH-Dokumentation für Details.
Unterschied zu externem Git¶
| Aspekt | polycrate git | git (extern) |
|---|---|---|
| Installation | Keine nötig (eingebaut) | Erfordert Git-Installation |
| SSH-Key | Nutzt Workspace-Key automatisch | Erfordert Konfiguration |
| Conflict-Check | Vor dem Pull | Nach dem Pull (Merge-Konflikt) |
| Spinner | Ja | Nein |
| Farbige Ausgabe | Optimiert für Polycrate | Standard-Git-Farben |
Best Practices¶
1. Vor Actions synchronisieren¶
2. Aussagekräftige Commit-Messages¶
# Conventional Commits verwenden
polycrate git commit -m "feat: add redis caching"
polycrate git commit -m "fix: correct database connection string"
polycrate git commit -m "chore: update dependencies"
3. Regelmäßig pushen¶
Verlorene Arbeit vermeiden durch regelmäßiges Pushen:
4. Status vor Commit prüfen¶
polycrate git status
# Prüfen was gestagt wird
polycrate git add --all
polycrate git commit -m "..."
Fehlerbehebung¶
"Authentication failed"¶
# Prüfen ob SSH-Key existiert
ls -la artifacts/secrets/id_rsa
# Oder im Root
ls -la id_rsa
# Key-Berechtigungen prüfen
chmod 600 artifacts/secrets/id_rsa
"Remote rejected"¶
"Local changes would be overwritten"¶
# Option 1: Commit vor Pull
polycrate git add --all
polycrate git commit -m "save local changes"
polycrate git pull
# Option 2: Änderungen verwerfen (VORSICHT!)
git checkout -- .
polycrate git pull
Siehe auch¶
- CLI-Referenz - Vollständige Command-Referenz
- Workspaces - Workspace-Grundlagen
- SSH - SSH-Key-Management
- Integrationen - Übersicht aller Integrationen