MCPcopy Create free account
hub / github.com/easyp-tech/server / getRepoSwitchedCommit

Function getRepoSwitchedCommit

internal/providers/localgit/localgit.go:256–281  ·  view source on GitHub ↗
(dirName, commit string)

Source from the content-addressed store, hash-verified

254}
255
256func getRepoSwitchedCommit(dirName, commit string) (string, string, error) {
257 r, err := git.PlainOpen(dirName)
258 if err != nil {
259 return "", "", fmt.Errorf("opening git: %w", err)
260 }
261
262 defaultBranch, err := r.Reference(plumbing.NewRemoteHEADReferenceName("origin"), true)
263 if err != nil {
264 return "", "", fmt.Errorf("resolving default branch: %w", err)
265 }
266
267 if commit == "" || commit == "main" {
268 commit = defaultBranch.Hash().String()
269 }
270
271 w, err := r.Worktree()
272 if err != nil {
273 return "", "", fmt.Errorf("getting work tree: %w", err)
274 }
275
276 if err = w.Checkout(&git.CheckoutOptions{Hash: plumbing.NewHash(commit)}); err != nil { //nolint:exhaustruct
277 return "", "", fmt.Errorf("checking out %q: %w", commit, err)
278 }
279
280 return defaultBranch.Name().Short(), commit, nil
281}
282
283func enumerateProto(dirName string, repo filter.Repo) ([]content.File, error) {
284 res := make([]content.File, 0, minNumberOfFiles)

Callers 2

GetMetaMethod · 0.85
GetFilesMethod · 0.85

Calls 3

HashMethod · 0.80
NameMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected