clean devel now has an EXACT check against upstream and master

This commit is contained in:
Jeff Carr 2025-01-20 04:07:16 -06:00
parent 6386bc4826
commit 55d8abd2a3
1 changed files with 57 additions and 3 deletions

View File

@ -59,7 +59,7 @@ func doCleanDevel() error {
for all.Scan() {
repo := all.Next()
if argv.Verbose {
log.Info("Cleaning:", repo.GetGoPath())
// log.Info("Cleaning:", repo.GetGoPath())
}
total += 1
if repo.GetCurrentBranchName() != repo.GetDevelBranchName() {
@ -79,25 +79,78 @@ func doCleanDevel() error {
return nil
}
func exactDevelRepo(repo *gitpb.Repo) error {
devel := repo.GetDevelBranchName()
master := repo.GetMasterBranchName()
err := isBranchSubsetOfTrunk(repo, devel, master)
if err != nil {
return err
}
return nil
}
func checkhashes(repo *gitpb.Repo, hashes []string, refpath string) ([]string, error) {
if !repo.Exists(refpath) {
return hashes, nil
}
r, err := repo.RunStrictNew([]string{"cat", refpath})
if err != nil {
return hashes, err
}
newhash := r.Stdout[0]
for _, hash := range hashes {
if newhash != hash {
return hashes, fmt.Errorf("%s hash broke %s %s", repo.GetGoPath(), newhash, hash)
}
}
hashes = append(hashes, newhash)
return hashes, nil
}
func doCleanDevelRepo(repo *gitpb.Repo) error {
var hashes []string
devel := repo.GetDevelBranchName()
// log.Printf("%s Start verify devel branch: %s\n", repo.GetGoPath(), devel)
// check if devel branch exists in remote repo
if repo.Exists(filepath.Join(".git/refs/remotes/origin", devel)) {
if argv.Verbose {
var err error
if hashes, err = checkhashes(repo, hashes, filepath.Join(".git/refs/remotes/origin", devel)); err != nil {
return err
}
}
remote := filepath.Join("origin", devel)
if err := isBranchSubsetOfTrunk(repo, devel, remote); err != nil {
if err == ErrorMergeBranch {
log.Info("can not do this yet. need push to upstream", repo.GetGoPath())
if argv.Force {
return nil
}
return err
}
return err
}
// log.Info("todo: verify against remote devel branch", repo.GetGoPath())
}
// verify devel branch is subset of master branch
master := repo.GetMasterBranchName()
if argv.Verbose {
var err error
if hashes, err = checkhashes(repo, hashes, filepath.Join(".git/refs/heads", devel)); err != nil {
return err
}
}
if argv.Verbose {
var err error
if hashes, err = checkhashes(repo, hashes, filepath.Join(".git/refs/heads", devel)); err != nil {
return err
}
}
if argv.Verbose {
log.Info("repo hashes all match. incredible", hashes, repo.GetGoPath())
}
if err := isBranchSubsetOfTrunk(repo, devel, master); err != nil {
if err == ErrorMergeBranch {
if argv.Force {
@ -110,11 +163,12 @@ func doCleanDevelRepo(repo *gitpb.Repo) error {
cmd := []string{"git", "merge", master}
log.Info("can't run. on wrong branch.", cmd, repo.GetGoPath(), "current branch =", repo.GetCurrentBranchName())
}
}
return nil
}
return err
}
return err
}
// log.Info("todo: verify against remote devel branch", repo.GetGoPath())
return nil