sync: Try to improve git-lfs support

This commit is contained in:
nemunaire 2021-12-07 16:33:11 +01:00
parent 7896579189
commit e6d8f2db1b
3 changed files with 19 additions and 10 deletions

View File

@ -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. // SyncExercices imports new or updates existing exercices, in a given theme.
func SyncExercices(i Importer, theme *fic.Theme) (errs []string) { 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 { if exercices, err := GetExercices(i, theme); err != nil {
errs = append(errs, err.Error()) errs = append(errs, err.Error())
} else { } else {

View File

@ -186,9 +186,11 @@ func SyncThemeDeep(i Importer, theme *fic.Theme, tid int, themeStep uint8) (errs
oneThemeDeepSync.Lock() oneThemeDeepSync.Lock()
defer oneThemeDeepSync.Unlock() defer oneThemeDeepSync.Unlock()
if !avoidImporterSync() {
if err := i.Sync(); err != nil { if err := i.Sync(); err != nil {
errs = append(errs, err.Error()) errs = append(errs, err.Error())
} }
}
DeepSyncProgress = 3 + uint8(tid)*themeStep DeepSyncProgress = 3 + uint8(tid)*themeStep
errs = SyncExercices(i, theme) errs = SyncExercices(i, theme)

View File

@ -6,6 +6,7 @@ package sync
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"log"
"os/exec" "os/exec"
"strings" "strings"
) )
@ -55,11 +56,13 @@ func (i GitImporter) Init() error {
if n, err := countFileInDir(i.li.Base); err != nil { if n, err := countFileInDir(i.li.Base); err != nil {
return err return err
} else if n == 0 { } 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() stdout, err := cmdclone.CombinedOutput()
if err != nil { if err != nil {
return fmt.Errorf("%w:\n%s", err, stdout) 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 // 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 { 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() stdout, err := cmdremote.CombinedOutput()
if err != nil { if err != nil {
log.Printf("Local git repository synchronization failed: %s\n%s", err, stdout)
return fmt.Errorf("%w:\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 return nil
} }