diff --git a/admin/sync/exercices.go b/admin/sync/exercices.go index ebba4610..6b25115f 100644 --- a/admin/sync/exercices.go +++ b/admin/sync/exercices.go @@ -243,12 +243,6 @@ func SyncExercice(i Importer, theme *fic.Theme, epath string, dmap *map[int64]*f // SyncExercices imports new or updates existing exercices, in a given theme. func SyncExercices(i Importer, theme *fic.Theme) (errs []string) { - if !avoidImporterSync() { - if err := i.Sync(); err != nil { - errs = append(errs, err.Error()) - } - } - if exercices, err := GetExercices(i, theme); err != nil { errs = append(errs, err.Error()) } else { diff --git a/admin/sync/full.go b/admin/sync/full.go index baa08740..a841d0ac 100644 --- a/admin/sync/full.go +++ b/admin/sync/full.go @@ -186,8 +186,10 @@ func SyncThemeDeep(i Importer, theme *fic.Theme, tid int, themeStep uint8) (errs oneThemeDeepSync.Lock() defer oneThemeDeepSync.Unlock() - if err := i.Sync(); err != nil { - errs = append(errs, err.Error()) + if !avoidImporterSync() { + if err := i.Sync(); err != nil { + errs = append(errs, err.Error()) + } } DeepSyncProgress = 3 + uint8(tid)*themeStep diff --git a/admin/sync/importer_gitbin.go b/admin/sync/importer_gitbin.go index 6501864b..2aa1889c 100644 --- a/admin/sync/importer_gitbin.go +++ b/admin/sync/importer_gitbin.go @@ -6,6 +6,7 @@ package sync import ( "bytes" "fmt" + "log" "os/exec" "strings" ) @@ -55,11 +56,13 @@ func (i GitImporter) Init() error { if n, err := countFileInDir(i.li.Base); err != nil { return err } else if n == 0 { - cmdclone := exec.Command("git", "-C", i.li.Base, "clone", "--recursive", i.Remote) + log.Println("Please wait while creating the local git repository...") + cmdclone := exec.Command("git", "clone", "--recursive", "--depth", "1", "--shallow-submodules", i.Remote, i.li.Base) stdout, err := cmdclone.CombinedOutput() if err != nil { return fmt.Errorf("%w:\n%s", err, stdout) } + log.Println("Local git repository successfully cloned") } // Check if the .git directory exists, change the origin remote to our @@ -73,11 +76,21 @@ func (i GitImporter) Init() error { } func (i GitImporter) Sync() error { - cmdremote := exec.Command("git", "-C", i.li.Base, "pull", "--rebase", "--force", "--recurse-submodules=yes", "origin") + log.Println("Synchronizing local git repository...") + cmdremote := exec.Command("git", "-C", i.li.Base, "pull", "--rebase", "--force", "-X", "theirs", "--recurse-submodules=yes", "origin") stdout, err := cmdremote.CombinedOutput() if err != nil { + log.Printf("Local git repository synchronization failed: %s\n%s", err, stdout) return fmt.Errorf("%w:\n%s", err, stdout) } + cmdsubmodule := exec.Command("git", "-C", i.li.Base, "submodule", "foreach", "--recursive", "git", "lfs", "pull") + stdout, err = cmdsubmodule.CombinedOutput() + if err != nil { + log.Printf("Local LFS synchronization failed: %s\n%s", err, stdout) + return fmt.Errorf("%w:\n%s", err, stdout) + } + + log.Println("Local git repository synchronized successfully") return nil }