A testing cleanup.
This pull request replaces `os.MkdirTemp` with `t.TempDir`. We can use the `T.TempDir` function from the `testing` package to create temporary directory. The directory created by `T.TempDir` is automatically removed when the test and all its subtests complete.
This saves us at least 2 lines (error check, and cleanup) on every instance, or in some cases adds cleanup that we forgot.
Reference: https://pkg.go.dev/testing#T.TempDir
```go
func TestFoo(t *testing.T) {
// before
tmpDir, err := os.MkdirTemp("", "")
require.NoError(t, err)
defer os.RemoveAll(tmpDir)
// now
tmpDir := t.TempDir()
}
```
Signed-off-by: Eng Zer Jun <[email protected]>
The LastCommitCache code is a little complex and there is unnecessary
duplication between the gogit and nogogit variants.
This PR adds the LastCommitCache as a field to the git.Repository and
pre-creates it in the ReferencesGit helpers etc. There has been some
simplification and unification of the variant code.
Signed-off-by: Andrew Thornton <[email protected]>
* Ensure git tag tests and other create test repos in tmpdir
There are a few places where tests appear to reuse testing repos which
causes random CI failures.
This PR simply changes these tests to ensure that cloning always happens
into new temporary directories.
Fix#18444
* Change log root for integration tests to use the REPO_TEST_DIR
There is a potential race in the drone integration tests whereby test-mysql etc
will start writing to log files causing make test-check fail.
Fix#18077
Signed-off-by: Andrew Thornton <[email protected]>
This PR continues the work in #17125 by progressively ensuring that git
commands run within the request context.
This now means that the if there is a git repo already open in the context it will be used instead of reopening it.
Signed-off-by: Andrew Thornton <[email protected]>
* Make modules/context.Context a context.Context
Signed-off-by: Andrew Thornton <[email protected]>
* Simplify context calls
Signed-off-by: Andrew Thornton <[email protected]>
* Set the base context for requests to the HammerContext
Signed-off-by: Andrew Thornton <[email protected]>
* pass context into get-last-commit
Signed-off-by: Andrew Thornton <[email protected]>
* Make commit_info cancellable
Signed-off-by: Andrew Thornton <[email protected]>
* use context as context
Signed-off-by: Andrew Thornton <[email protected]>
Co-authored-by: 6543 <[email protected]>
* Move last commit cache back into modules/git
Signed-off-by: Andrew Thornton <[email protected]>
* Remove go-git from the interface for last commit cache
Signed-off-by: Andrew Thornton <[email protected]>
* move cacheref to last_commit_cache
Signed-off-by: Andrew Thornton <[email protected]>
* Remove go-git from routers/private/hook
Signed-off-by: Andrew Thornton <[email protected]>
* Move FindLFSFiles to pipeline
Signed-off-by: Andrew Thornton <[email protected]>
* Make no-go-git variants
Signed-off-by: Andrew Thornton <[email protected]>
* Submodule RefID
Signed-off-by: Andrew Thornton <[email protected]>
* fix issue with GetCommitsInfo
Signed-off-by: Andrew Thornton <[email protected]>
* fix GetLastCommitForPaths
Signed-off-by: Andrew Thornton <[email protected]>
* Improve efficiency
Signed-off-by: Andrew Thornton <[email protected]>
* More efficiency
Signed-off-by: Andrew Thornton <[email protected]>
* even faster
Signed-off-by: Andrew Thornton <[email protected]>
* Reduce duplication
* As per @lunny
Signed-off-by: Andrew Thornton <[email protected]>
* attempt to fix drone
Signed-off-by: Andrew Thornton <[email protected]>
* fix test-tags
Signed-off-by: Andrew Thornton <[email protected]>
* default to use no-go-git variants and add gogit build tag
Signed-off-by: Andrew Thornton <[email protected]>
* placate lint
Signed-off-by: Andrew Thornton <[email protected]>
* as per @6543
Signed-off-by: Andrew Thornton <[email protected]>
Co-authored-by: 6543 <[email protected]>
Co-authored-by: techknowlogick <[email protected]>
Replace all calls to os.Remove/os.RemoveAll by retrying util.Remove/util.RemoveAll and remove circular dependencies from util.
Fix#12339
Signed-off-by: Andrew Thornton <[email protected]>
Co-authored-by: silverwind <[email protected]>
In investigating #7947 it has become clear that the storage component of go-git repositories needs closing.
This PR adds this Close function and adds the Close functions as necessary.
In TransferOwnership the ctx.Repo.GitRepo is closed if it is open to help prevent the risk of multiple open files.
Fixes#7947
* Use go-git for tree reading and commit info lookup.
Signed-off-by: Filip Navara <[email protected]>
* Use TreeEntry.IsRegular() instead of ObjectType that was removed.
Signed-off-by: Filip Navara <[email protected]>
* Use the treePath to optimize commit info search.
Signed-off-by: Filip Navara <[email protected]>
* Extract the latest commit at treePath along with the other commits.
Signed-off-by: Filip Navara <[email protected]>
* Fix listing commit info for a directory that was created in one commit and never modified after.
Signed-off-by: Filip Navara <[email protected]>
* Avoid nearly all external 'git' invocations when doing directory listing (.editorconfig code path is still hit).
Signed-off-by: Filip Navara <[email protected]>
* Use go-git for reading blobs.
Signed-off-by: Filip Navara <[email protected]>
* Make SHA1 type alias for plumbing.Hash in go-git.
Signed-off-by: Filip Navara <[email protected]>
* Make Signature type alias for object.Signature in go-git.
Signed-off-by: Filip Navara <[email protected]>
* Fix GetCommitsInfo for repository with only one commit.
Signed-off-by: Filip Navara <[email protected]>
* Fix PGP signature verification.
Signed-off-by: Filip Navara <[email protected]>
* Fix issues with walking commit graph across merges.
Signed-off-by: Filip Navara <[email protected]>
* Fix typo in condition.
Signed-off-by: Filip Navara <[email protected]>
* Speed up loading branch list by keeping the repository reference (and thus all the loaded packfile indexes).
Signed-off-by: Filip Navara <[email protected]>
* Fix lising submodules.
Signed-off-by: Filip Navara <[email protected]>
* Fix build
Signed-off-by: Filip Navara <[email protected]>
* Add back commit cache because of name-rev
Signed-off-by: Filip Navara <[email protected]>
* Fix tests
Signed-off-by: Filip Navara <[email protected]>
* Fix code style
* Fix spelling
* Address PR feedback
Signed-off-by: Filip Navara <[email protected]>
* Update vendor module list
Signed-off-by: Filip Navara <[email protected]>
* Fix getting trees by commit id
Signed-off-by: Filip Navara <[email protected]>
* Fix remaining unit test failures
* Fix GetTreeBySHA
* Avoid running `git name-rev` if not necessary
Signed-off-by: Filip Navara <[email protected]>
* Move Branch code to git module
* Clean up GPG signature verification and fix it for tagged commits
* Address PR feedback (import formatting, copyright headers)
* Make blob lookup by SHA working
* Update tests to use public API
* Allow getting content from any type of object through the blob interface
* Change test to actually expect the object content that is in the GIT repository
* Change one more test to actually expect the object content that is in the GIT repository
* Add comments