Skip to content

Commit 7267c0f

Browse files
committed
fix: make git.DefaultRemoteBranch function private
1 parent 1086deb commit 7267c0f

File tree

1 file changed

+26
-25
lines changed

1 file changed

+26
-25
lines changed

Diff for: internal/git/git.go

+26-25
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ func (r Repo) Clone(pluginURL, ref string) error {
5353
var stdErr strings.Builder
5454
cmd.Stdout = &stdOut
5555
cmd.Stderr = &stdErr
56+
5657
err := cmd.Run()
5758

5859
if err != nil {
@@ -92,30 +93,6 @@ func (r Repo) RemoteURL() (string, error) {
9293
return remotes[0].Config().URLs[0], nil
9394
}
9495

95-
func (r Repo) RemoteDefaultBranch() (string, error) {
96-
// @jiminychris - https://github.com/go-git/go-git/issues/510#issuecomment-2560116147
97-
repo, err := gitOpen(r.Directory)
98-
if err != nil {
99-
return "", err
100-
}
101-
102-
// Get the remote you want to find the default for
103-
remote, err := repo.Remote("origin")
104-
if err != nil {
105-
return "", err
106-
}
107-
108-
references, _ := remote.List(&git.ListOptions{})
109-
// Search through the list of references in that remote for a symbolic reference named HEAD;
110-
// Its target should be the default branch name.
111-
for _, reference := range references {
112-
if reference.Name() == "HEAD" && reference.Type() == plumbing.SymbolicReference {
113-
return reference.Target().String(), nil
114-
}
115-
}
116-
return "", fmt.Errorf("unable to find default branch for git directory %s", r.Directory)
117-
}
118-
11996
// Update updates the plugin's Git repository to the ref if provided, or the
12097
// latest commit on the current branch
12198
func (r Repo) Update(ref string) (string, string, string, error) {
@@ -131,7 +108,7 @@ func (r Repo) Update(ref string) (string, string, string, error) {
131108

132109
// If no ref is provided we take the default branch of the remote
133110
if strings.TrimSpace(ref) == "" {
134-
ref, err = r.RemoteDefaultBranch()
111+
ref, err = r.remoteDefaultBranch()
135112
if err != nil {
136113
return "", "", "", err
137114
}
@@ -167,6 +144,30 @@ func (r Repo) Update(ref string) (string, string, string, error) {
167144
return ref, oldHash.String(), newHash.Hash().String(), nil
168145
}
169146

147+
func (r Repo) remoteDefaultBranch() (string, error) {
148+
// @jiminychris - https://github.com/go-git/go-git/issues/510#issuecomment-2560116147
149+
repo, err := gitOpen(r.Directory)
150+
if err != nil {
151+
return "", err
152+
}
153+
154+
// Get the remote you want to find the default for
155+
remote, err := repo.Remote("origin")
156+
if err != nil {
157+
return "", err
158+
}
159+
160+
references, _ := remote.List(&git.ListOptions{})
161+
// Search through the list of references in that remote for a symbolic reference named HEAD;
162+
// Its target should be the default branch name.
163+
for _, reference := range references {
164+
if reference.Name() == "HEAD" && reference.Type() == plumbing.SymbolicReference {
165+
return reference.Target().String(), nil
166+
}
167+
}
168+
return "", fmt.Errorf("unable to find default branch for git directory %s", r.Directory)
169+
}
170+
170171
func stdErrToErrMsg(stdErr string) string {
171172
lines := strings.Split(strings.TrimSuffix(stdErr, "\n"), "\n")
172173
return lines[len(lines)-1]

0 commit comments

Comments
 (0)