-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(fs): use git commit hash as cache key for clean repositories (#8278
- Loading branch information
Showing
18 changed files
with
345 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package gittest | ||
|
||
import ( | ||
"log/slog" | ||
"path/filepath" | ||
"runtime" | ||
|
||
"github.com/go-git/go-git/v5" | ||
"github.com/magefile/mage/target" | ||
"golang.org/x/xerrors" | ||
) | ||
|
||
const ( | ||
repoURL = "https://github.com/aquasecurity/trivy-test-repo/" | ||
repoDir = "test-repo" // subdirectory for the cloned repository | ||
) | ||
|
||
// Fixtures clones a Git repository for unit tests | ||
func Fixtures() error { | ||
_, filePath, _, _ := runtime.Caller(0) | ||
dir := filepath.Dir(filePath) | ||
cloneDir := filepath.Join(dir, repoDir) | ||
|
||
// Check if the directory already exists and is up to date | ||
if updated, err := target.Path(cloneDir, filePath); err != nil { | ||
return err | ||
} else if !updated { | ||
return nil | ||
} | ||
|
||
slog.Info("Cloning...", slog.String("url", repoURL)) | ||
|
||
// Clone the repository with all branches and tags | ||
_, err := git.PlainClone(cloneDir, false, &git.CloneOptions{ | ||
URL: repoURL, | ||
Tags: git.AllTags, | ||
}) | ||
if err != nil { | ||
return xerrors.Errorf("error cloning repository: %w", err) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.