Skip to content

Commit dbbf76d

Browse files
committed
Cleanup in context
1 parent 47cef73 commit dbbf76d

File tree

3 files changed

+1
-85
lines changed

3 files changed

+1
-85
lines changed

command/testing.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ const defaultTestConfig = `hosts:
2929
func initBlankContext(cfg, repo, branch string) {
3030
initContext = func() context.Context {
3131
ctx := context.NewBlank()
32-
ctx.SetBaseRepo(repo)
33-
ctx.SetBranch(branch)
34-
ctx.SetRemotes(map[string]string{
35-
"origin": "OWNER/REPO",
36-
})
3732

3833
if cfg == "" {
3934
cfg = defaultTestConfig

context/blank_context.go

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@ package context
22

33
import (
44
"fmt"
5-
"strings"
65

7-
"github.com/cli/cli/git"
86
"github.com/cli/cli/internal/config"
9-
"github.com/cli/cli/internal/ghrepo"
107
)
118

129
// NewBlank initializes a blank Context suitable for testing
@@ -16,9 +13,6 @@ func NewBlank() *blankContext {
1613

1714
// A Context implementation that queries the filesystem
1815
type blankContext struct {
19-
branch string
20-
baseRepo ghrepo.Interface
21-
remotes Remotes
2216
}
2317

2418
func (c *blankContext) Config() (config.Config, error) {
@@ -28,51 +22,3 @@ func (c *blankContext) Config() (config.Config, error) {
2822
}
2923
return cfg, nil
3024
}
31-
32-
func (c *blankContext) Branch() (string, error) {
33-
if c.branch == "" {
34-
return "", fmt.Errorf("branch was not initialized: %w", git.ErrNotOnAnyBranch)
35-
}
36-
return c.branch, nil
37-
}
38-
39-
func (c *blankContext) SetBranch(b string) {
40-
c.branch = b
41-
}
42-
43-
func (c *blankContext) Remotes() (Remotes, error) {
44-
if c.remotes == nil {
45-
return nil, fmt.Errorf("remotes were not initialized")
46-
}
47-
return c.remotes, nil
48-
}
49-
50-
func (c *blankContext) SetRemotes(stubs map[string]string) {
51-
c.remotes = make([]*Remote, 0, len(stubs))
52-
for remoteName, repo := range stubs {
53-
ownerWithName := strings.SplitN(repo, "/", 2)
54-
c.remotes = append(c.remotes, &Remote{
55-
Remote: &git.Remote{Name: remoteName},
56-
Repo: ghrepo.New(ownerWithName[0], ownerWithName[1]),
57-
})
58-
}
59-
}
60-
61-
func (c *blankContext) BaseRepo() (ghrepo.Interface, error) {
62-
if c.baseRepo != nil {
63-
return c.baseRepo, nil
64-
}
65-
remotes, err := c.Remotes()
66-
if err != nil {
67-
return nil, err
68-
}
69-
if len(remotes) < 1 {
70-
return nil, fmt.Errorf("remotes are empty")
71-
}
72-
return remotes[0], nil
73-
}
74-
75-
func (c *blankContext) SetBaseRepo(nwo string) {
76-
repo, _ := ghrepo.FromFullName(nwo)
77-
c.baseRepo = repo
78-
}

context/context.go

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"strings"
99

1010
"github.com/cli/cli/api"
11-
"github.com/cli/cli/git"
1211
"github.com/cli/cli/internal/config"
1312
"github.com/cli/cli/internal/ghrepo"
1413
)
@@ -154,9 +153,7 @@ func New() Context {
154153

155154
// A Context implementation that queries the filesystem
156155
type fsContext struct {
157-
config config.Config
158-
branch string
159-
baseRepo ghrepo.Interface
156+
config config.Config
160157
}
161158

162159
func (c *fsContext) Config() (config.Config, error) {
@@ -171,25 +168,3 @@ func (c *fsContext) Config() (config.Config, error) {
171168
}
172169
return c.config, nil
173170
}
174-
175-
func (c *fsContext) Branch() (string, error) {
176-
if c.branch != "" {
177-
return c.branch, nil
178-
}
179-
180-
currentBranch, err := git.CurrentBranch()
181-
if err != nil {
182-
return "", fmt.Errorf("could not determine current branch: %w", err)
183-
}
184-
185-
c.branch = currentBranch
186-
return c.branch, nil
187-
}
188-
189-
func (c *fsContext) SetBranch(b string) {
190-
c.branch = b
191-
}
192-
193-
func (c *fsContext) SetBaseRepo(nwo string) {
194-
c.baseRepo, _ = ghrepo.FromFullName(nwo)
195-
}

0 commit comments

Comments
 (0)