MCPcopy Create free account
hub / github.com/containers/fetchit / GetLatest

Method GetLatest

pkg/engine/apply.go:21–53  ·  view source on GitHub ↗

* For any given target, will get the head of the branch in the repository specified by the target's url */

(target *Target)

Source from the content-addressed store, hash-verified

19in the repository specified by the target's url
20*/
21func (fc *FetchitConfig) GetLatest(target *Target) (plumbing.Hash, error) {
22 directory := filepath.Base(target.Url)
23
24 repo, err := git.PlainOpen(directory)
25 if err != nil {
26 return plumbing.Hash{}, utils.WrapErr(err, "Error opening repository: %s", directory)
27 }
28
29 refSpec := config.RefSpec(fmt.Sprintf("+refs/heads/%s:refs/heads/%s", target.Branch, target.Branch))
30 if err = repo.Fetch(&git.FetchOptions{
31 RefSpecs: []config.RefSpec{refSpec, "HEAD:refs/heads/HEAD"},
32 Force: true,
33 }); err != nil && err != git.NoErrAlreadyUpToDate {
34 return plumbing.Hash{}, utils.WrapErr(err, "Error fetching branch %s from remote repository %s", target.Branch, target.Url)
35 }
36
37 branch, err := repo.Reference(plumbing.ReferenceName(fmt.Sprintf("refs/heads/%s", target.Branch)), false)
38 if err != nil {
39 return plumbing.Hash{}, utils.WrapErr(err, "Error getting reference to branch %s", target.Branch)
40 }
41
42 wt, err := repo.Worktree()
43 if err != nil {
44 return plumbing.Hash{}, utils.WrapErr(err, "Error getting reference to worktree for repository", target.Name)
45 }
46
47 err = wt.Checkout(&git.CheckoutOptions{Hash: branch.Hash()})
48 if err != nil {
49 return plumbing.Hash{}, utils.WrapErr(err, "Error checking out %s on branch %s", branch.Hash(), target.Branch)
50 }
51
52 return branch.Hash(), err
53}
54
55func (fc *FetchitConfig) GetCurrent(target *Target, method string) (plumbing.Hash, error) {
56 directory := filepath.Base(target.Url)

Callers 5

processRawMethod · 0.95
processAnsibleMethod · 0.95
processSystemdMethod · 0.95
processFileTransferMethod · 0.95
processKubeMethod · 0.95

Calls 1

WrapErrFunction · 0.92

Tested by

no test coverage detected