sync: Try to improve git-lfs support
This commit is contained in:
parent
7896579189
commit
e6d8f2db1b
3 changed files with 19 additions and 10 deletions
|
@ -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
|
||||
}
|
||||
|
|
Reference in a new issue