Files
runtime/apps/daemon/pkg/git/service.go
zeekay ea80dc3638 feat: Add new Dockerfiles and improve containerization
- Add main Dockerfile for production builds
- Add Dockerfile.runtime for secure code execution
- Add Dockerfile.runtime.fixed with improved configuration
- Include .dockerignore for build optimization
- Add integration documentation and publishing guides
- Update API and CLI components for better runtime support
- Enhance sandbox and container management features
2025-08-16 23:03:39 -05:00

81 lines
2.4 KiB
Go

// Copyright 2025 Hanzo Industries Inc.
// SPDX-License-Identifier: AGPL-3.0
package git
import (
"io"
"os"
"path/filepath"
"github.com/hanzoai/daemon/pkg/gitprovider"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing/transport/http"
)
type GitStatus struct {
CurrentBranch string `json:"currentBranch" validate:"required"`
Files []*FileStatus `json:"fileStatus" validate:"required"`
BranchPublished bool `json:"branchPublished" validate:"optional"`
Ahead int `json:"ahead" validate:"optional"`
Behind int `json:"behind" validate:"optional"`
} // @name GitStatus
type FileStatus struct {
Name string `json:"name" validate:"required"`
Extra string `json:"extra" validate:"required"`
Staging Status `json:"staging" validate:"required"`
Worktree Status `json:"worktree" validate:"required"`
} // @name FileStatus
// Status status code of a file in the Worktree
type Status string // @name Status
const (
Unmodified Status = "Unmodified"
Untracked Status = "Untracked"
Modified Status = "Modified"
Added Status = "Added"
Deleted Status = "Deleted"
Renamed Status = "Renamed"
Copied Status = "Copied"
UpdatedButUnmerged Status = "Updated but unmerged"
)
var MapStatus map[git.StatusCode]Status = map[git.StatusCode]Status{
git.Unmodified: Unmodified,
git.Untracked: Untracked,
git.Modified: Modified,
git.Added: Added,
git.Deleted: Deleted,
git.Renamed: Renamed,
git.Copied: Copied,
git.UpdatedButUnmerged: UpdatedButUnmerged,
}
type IGitService interface {
CloneRepository(repo *gitprovider.GitRepository, auth *http.BasicAuth) error
CloneRepositoryCmd(repo *gitprovider.GitRepository, auth *http.BasicAuth) []string
RepositoryExists() (bool, error)
SetGitConfig(userData *gitprovider.GitUser, providerConfig *gitprovider.GitProviderConfig) error
GetGitStatus() (*GitStatus, error)
}
type Service struct {
ProjectDir string
GitConfigFileName string
LogWriter io.Writer
OpenRepository *git.Repository
}
func (s *Service) RepositoryExists() (bool, error) {
_, err := os.Stat(filepath.Join(s.ProjectDir, ".git"))
if os.IsNotExist(err) {
return false, nil
}
if err != nil {
return false, err
}
return true, nil
}