Skip to content

Commit

Permalink
feat: add git registry
Browse files Browse the repository at this point in the history
Signed-off-by: Kasper J. Hermansen <[email protected]>
  • Loading branch information
kjuulh committed Jun 13, 2024
1 parent 77c56c5 commit 9c865a6
Showing 1 changed file with 31 additions and 16 deletions.
47 changes: 31 additions & 16 deletions internal/extensions/git_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,36 +50,51 @@ func newGitRegistry(url string, globalStore *global.GlobalStore) Registry {
func (g *gitRegistry) fetchGitRepository(ctx context.Context) error {
registry := getRegistryPath(g.globalStore)

cmd := exec.CommandContext(ctx, "git", "pull")
return g.executeGit(ctx, "git", gitOptions{
args: []string{
"pull",
},
dir: registry,
})
}

cmd.Dir = registry
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
func (g *gitRegistry) cloneGitRepository(ctx context.Context) error {
registry := getRegistryPath(g.globalStore)

if err := cmd.Start(); err != nil {
return err
}
return g.executeGit(ctx, "git", gitOptions{
args: []string{
"clone",
g.url,
registry,
},
})

return cmd.Wait()
}

func (g *gitRegistry) cloneGitRepository(ctx context.Context) error {
func (g *gitRegistry) registryClonedAlready() bool {
registry := getRegistryPath(g.globalStore)

cmd := exec.CommandContext(ctx, "git", "clone", g.url, registry)
return exists(path.Join(registry, ".git"))
}

type gitOptions struct {
args []string
dir string
}

func (g *gitRegistry) executeGit(ctx context.Context, name string, gitOptions gitOptions) error {
cmd := exec.CommandContext(ctx, name, gitOptions.args...)

cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

if gitOptions.dir != "" {
cmd.Dir = gitOptions.dir
}

if err := cmd.Start(); err != nil {
return err
}

return cmd.Wait()
}

func (g *gitRegistry) registryClonedAlready() bool {
registry := getRegistryPath(g.globalStore)

return exists(path.Join(registry, ".git"))
}

0 comments on commit 9c865a6

Please sign in to comment.