Skip to content

Enhance checking last commit for git functions #2147

@pPrecel

Description

@pPrecel

Description

Check if it's possible to check the last commit for the function's remote without cloning the whole repository. The current code is costing a lot of memory. To improve that, we can use the current library to build a solution similar to the previous solution based on the libgit2 library.

Code example:

func GetLatestCommit(url, reference string, gitAuth *GitAuth) (string, error) {
gitRepo, _ := git.Init(memory.NewStorage(), nil)
newRemote, _ := gitRepo.CreateRemote(&config.RemoteConfig{
    // implement
})
_ = newRemote.Fetch(&git.FetchOptions{
    // implement
})

ref, _ := gitRepo.Reference(plumbing.ReferenceName(reference), true)
return ref.Hash().String(), nil
}

Reasons

Speed up while process and decrease memory and CPU consumption to avoid problems like this.

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions