sync: Try to handle new submodules on pull

This commit is contained in:
nemunaire 2023-05-26 21:09:53 +02:00
parent 5b102ad8ea
commit edc5c25a29

View File

@ -122,6 +122,28 @@ func (i GitImporter) Sync() error {
log.Printf("Local git repository submodules clean failed: %s\n%s", err, stdout)
return fmt.Errorf("%w:\n%s", err, stdout)
}
// Start by a light hard reset (without submodules, in order to init new ones)
cmdreset := exec.Command("git", "-C", i.li.Base, "reset", "--hard", "origin/"+i.Branch)
stdout, err = cmdreset.CombinedOutput()
if err != nil {
log.Printf("Local git repository reset failed: %s\n%s", err, stdout)
return fmt.Errorf("%w:\n%s", err, stdout)
}
cmdsubinit := exec.Command("git", "-C", i.li.Base, "submodule", "init")
stdout, err = cmdsubinit.CombinedOutput()
if err != nil {
log.Printf("Local git repository submodule init failed: %s\n%s", err, stdout)
return fmt.Errorf("%w:\n%s", err, stdout)
}
cmdsubupdate := exec.Command("git", "-C", i.li.Base, "submodule", "update")
stdout, err = cmdsubupdate.CombinedOutput()
if err != nil {
log.Printf("Local git repository submodule init failed: %s\n%s", err, stdout)
return fmt.Errorf("%w:\n%s", err, stdout)
}
}
cmdreset := exec.Command("git", "-C", i.li.Base, "reset", "--hard", "--recurse-submodule", "origin/"+i.Branch)