File: git.go

package info (click to toggle)
gh 2.46.0-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 15,548 kB
  • sloc: sh: 227; makefile: 117
file content (60 lines) | stat: -rw-r--r-- 1,556 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package extension

import (
	"context"

	"github.com/cli/cli/v2/git"
)

type gitClient interface {
	CheckoutBranch(branch string) error
	Clone(cloneURL string, args []string) (string, error)
	CommandOutput(args []string) ([]byte, error)
	Config(name string) (string, error)
	Fetch(remote string, refspec string) error
	ForRepo(repoDir string) gitClient
	Pull(remote, branch string) error
	Remotes() (git.RemoteSet, error)
}

type gitExecuter struct {
	client *git.Client
}

func (g *gitExecuter) CheckoutBranch(branch string) error {
	return g.client.CheckoutBranch(context.Background(), branch)
}

func (g *gitExecuter) Clone(cloneURL string, cloneArgs []string) (string, error) {
	return g.client.Clone(context.Background(), cloneURL, cloneArgs)
}

func (g *gitExecuter) CommandOutput(args []string) ([]byte, error) {
	cmd, err := g.client.Command(context.Background(), args...)
	if err != nil {
		return nil, err
	}
	return cmd.Output()
}

func (g *gitExecuter) Config(name string) (string, error) {
	return g.client.Config(context.Background(), name)
}

func (g *gitExecuter) Fetch(remote string, refspec string) error {
	return g.client.Fetch(context.Background(), remote, refspec)
}

func (g *gitExecuter) ForRepo(repoDir string) gitClient {
	gc := g.client.Copy()
	gc.RepoDir = repoDir
	return &gitExecuter{client: gc}
}

func (g *gitExecuter) Pull(remote, branch string) error {
	return g.client.Pull(context.Background(), remote, branch)
}

func (g *gitExecuter) Remotes() (git.RemoteSet, error) {
	return g.client.Remotes(context.Background())
}