mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2025-08-11 17:50:58 +00:00
* fix: remove local cache if remote is changed * test: TestCloneIfRequired https://github.com/nektos/act/pull/2284 Co-authored-by: Jason Song <i@wolfogre.com> Reviewed-on: https://code.forgejo.org/forgejo/act/pulls/142 Reviewed-by: earl-warren <earl-warren@noreply.code.forgejo.org> Co-authored-by: achyrva <achyrva@noreply.code.forgejo.org> Co-committed-by: achyrva <achyrva@noreply.code.forgejo.org>
This commit is contained in:
parent
e21cc1ef63
commit
422e17bc27
2 changed files with 39 additions and 0 deletions
|
@ -238,6 +238,15 @@ type NewGitCloneExecutorInput struct {
|
|||
|
||||
// CloneIfRequired ...
|
||||
func CloneIfRequired(ctx context.Context, refName plumbing.ReferenceName, input NewGitCloneExecutorInput, logger log.FieldLogger) (*git.Repository, error) {
|
||||
// If the remote URL has changed, remove the directory and clone again.
|
||||
if r, err := git.PlainOpen(input.Dir); err == nil {
|
||||
if remote, err := r.Remote("origin"); err == nil {
|
||||
if len(remote.Config().URLs) > 0 && remote.Config().URLs[0] != input.URL {
|
||||
_ = os.RemoveAll(input.Dir)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
r, err := git.PlainOpen(input.Dir)
|
||||
if err != nil {
|
||||
var progressWriter io.Writer
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue