Fix the rerun functionality when using an inventory from a git repo

Changed the way the cloneInventoryRepo() function handles git repositories:
The function will now try to pull the git repo if it can be pulled, else it will be cloned.
This behaviour is based on what is done in the updateRepository() function

Renamed the file from "LobalJob_inventory.go" to "LocalJob_inventory.go"
This commit is contained in:
Arnaud V 2024-07-01 10:42:40 +02:00
parent 59ef3f8a12
commit 70f4b7397e

View File

@ -1,13 +1,14 @@
package tasks
import (
"github.com/ansible-semaphore/semaphore/db"
"github.com/ansible-semaphore/semaphore/db_lib"
log "github.com/sirupsen/logrus"
"os"
"path"
"strconv"
"github.com/ansible-semaphore/semaphore/db"
"github.com/ansible-semaphore/semaphore/db_lib"
log "github.com/sirupsen/logrus"
"github.com/ansible-semaphore/semaphore/util"
)
@ -61,9 +62,20 @@ func (t *LocalJob) cloneInventoryRepo() error {
Client: db_lib.CreateDefaultGitClient(),
}
err := repo.Clone()
// Try to pull the repo before trying to clone it
if repo.CanBePulled() {
err := repo.Pull()
if err == nil {
return nil
}
}
return err
err := os.RemoveAll(repo.GetFullPath())
if err != nil {
return err
}
return repo.Clone()
}
func (t *LocalJob) installStaticInventory() error {