try to fix defective "Git on Borg" repos

This commit is contained in:
Jeff Carr 2025-04-04 06:03:42 -05:00
parent 7297b63339
commit fcc5a36ad0
2 changed files with 24 additions and 0 deletions

View File

@ -1,6 +1,7 @@
package gitpb
import (
"os"
"path/filepath"
"go.wit.com/log"
@ -8,6 +9,20 @@ import (
func (repo *Repo) CheckoutMaster() bool {
bName := repo.GetMasterBranchName()
if bName == "giterr" {
cmd := []string{"git", "checkout", "main"} // todo: figure out main
repo.RunVerbose(cmd)
os.Exit(-1)
// TODO: try to fix this
if repo.checkoutBranch("main") {
repo.MasterBranchName = "main"
return true
} else {
cmd := []string{"git", "checkout", "main"} // todo: figure out main
repo.RunVerbose(cmd)
return false
}
}
if repo.checkoutBranch(bName) {
return true
}

View File

@ -21,6 +21,15 @@ func (repo *Repo) ReloadCheck() error {
// TODO: clean this up more, but it is working now more or less
func (repo *Repo) Reload() error {
// sometimes, on new repos, if .git/HEAD does not exist
// defective git daemons or badly configured repos, 'git clone' can fail
// if so, 'git fetch origin' can repair the state
if !repo.Exists(".git/HEAD") {
cmd := []string{"git", "fetch", "origin"}
repo.RunVerbose(cmd)
cmd = []string{"git", "checkout", "main"} // todo: figure out main
repo.RunVerbose(cmd)
}
// log.Info("in reload", repo.FullPath)
repo.Tags = new(GitTags)
repo.reloadGitTags()