summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-02-02 11:45:40 -0600
committerJeff Carr <[email protected]>2025-02-02 15:09:04 -0600
commit81c72468a11f1685a8fbe696636d7b95cd0b36dc (patch)
tree5d03c14ebccc2121dd2b524b272e9293c8147974
parent260f4c67e701dd4215fab516e4d883eaacf57e3f (diff)
code for a new user to start from scratch
-rw-r--r--Makefile2
-rw-r--r--doCheckout.go59
-rw-r--r--doClean.go134
-rw-r--r--doVerifyDevel.go16
-rw-r--r--doVerifyUser.go16
5 files changed, 133 insertions, 94 deletions
diff --git a/Makefile b/Makefile
index 111da5c..27188c2 100644
--- a/Makefile
+++ b/Makefile
@@ -9,7 +9,7 @@ BUILDTIME = $(shell date +%Y.%m.%d_%H%M)
default: install
# forge dirty --verbose
# forge patch list
- forge
+ forge dirty
vet:
@GO111MODULE=off go vet
diff --git a/doCheckout.go b/doCheckout.go
index e2598ab..c77c336 100644
--- a/doCheckout.go
+++ b/doCheckout.go
@@ -5,6 +5,7 @@ package main
import (
"fmt"
+ "path/filepath"
"time"
"go.wit.com/lib/gui/shell"
@@ -254,11 +255,27 @@ func doAllCheckoutMaster() error {
func doCheckout() error {
if argv.Checkout.User != nil {
+ if argv.Force {
+ // make the user directories
+ if err := makeUserBranches(); err != nil {
+ badExit(err)
+ }
+ okExit("make user branches done")
+ }
+ // this uses rill and is super fast
doAllCheckoutUser()
okExit("")
}
if argv.Checkout.Devel != nil {
+ if argv.Force {
+ // make the devel directories
+ if err := makeDevelBranches(); err != nil {
+ badExit(err)
+ }
+ okExit("make devel branches done")
+ }
+ // this uses rill and is super fast
doAllCheckoutDevel()
okExit("")
}
@@ -269,3 +286,45 @@ func doCheckout() error {
}
return nil
}
+
+func makeDevelBranches() error {
+ all := me.forge.Repos.SortByFullPath()
+ for all.Scan() {
+ repo := all.Next()
+ branch := repo.GetDevelBranchName()
+ if repo.Exists(filepath.Join(".git/refs/heads", branch)) {
+ continue
+ }
+ if repo.Exists(filepath.Join(".git/refs/remotes/origin", branch)) {
+ cmd := []string{"git", "checkout", branch}
+ repo.RunVerbose(cmd)
+ continue
+ }
+ cmd := []string{"git", "branch", branch}
+ repo.RunVerbose(cmd)
+ cmd = []string{"git", "checkout", branch}
+ repo.RunVerbose(cmd)
+ }
+ return nil
+}
+
+func makeUserBranches() error {
+ all := me.forge.Repos.SortByFullPath()
+ for all.Scan() {
+ repo := all.Next()
+ branch := repo.GetUserBranchName()
+ if repo.Exists(filepath.Join(".git/refs/heads", branch)) {
+ continue
+ }
+ if repo.Exists(filepath.Join(".git/refs/remotes/origin", branch)) {
+ cmd := []string{"git", "checkout", branch}
+ repo.RunVerbose(cmd)
+ continue
+ }
+ cmd := []string{"git", "branch", branch}
+ repo.RunVerbose(cmd)
+ cmd = []string{"git", "checkout", branch}
+ repo.RunVerbose(cmd)
+ }
+ return nil
+}
diff --git a/doClean.go b/doClean.go
index 240b9be..bf732de 100644
--- a/doClean.go
+++ b/doClean.go
@@ -62,30 +62,39 @@ func doCleanUser() error {
return nil
}
+func doesLocalBranchExist(repo *gitpb.Repo, branch string) bool {
+ return repo.Exists(filepath.Join(".git/refs/heads", branch))
+}
+
func doCleanDevel() error {
var total int
var count int
all := me.forge.Repos.SortByFullPath()
for all.Scan() {
repo := all.Next()
- if argv.Verbose {
- // log.Info("Cleaning:", repo.GetGoPath())
- }
total += 1
+ devel := repo.GetDevelBranchName()
+ if !doesLocalBranchExist(repo, devel) {
+ if argv.Verbose {
+ log.Info("local branch was already deleted:", repo.GetGoPath())
+ }
+ continue
+ }
if repo.GetCurrentBranchName() != repo.GetMasterBranchName() {
- // repos must be in the master branch to clean the devel branch
- return nil
+ log.Info("Repo not on master branch:", repo.GetGoPath())
+ continue
}
if repo.IsDirty() {
- return nil
+ log.Info("Repo is dirty:", repo.GetGoPath())
+ continue
}
count += 1
- if err := doCleanDevelRepo(repo); err != nil {
- log.Info(repo.GetGoPath(), err)
- return err
+ if err := justDeleteTheDevelBranchAlready(repo); err != nil {
+ log.Info("justDeleteTheDevel() err", repo.GetGoPath(), err)
}
}
- log.Printf("attempted cleaning %d branches of %d total branches\n", count, total)
+ log.Info("")
+ log.Printf("attempted cleaning %d devel branches of %d total branches\n", count, total)
return nil
}
@@ -117,75 +126,6 @@ func checkhashes(repo *gitpb.Repo, hashes []string, refpath string) ([]string, e
return hashes, nil
}
-func doCleanDevelRepo(repo *gitpb.Repo) error {
- var hashes []string
- devel := repo.GetDevelBranchName()
- if argv.Verbose {
- log.Printf("Start clean devel branch: %s %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 {
- if repo.GetCurrentBranchName() == devel {
- cmd := []string{"git", "merge", master}
- // only run this if branch is local
- _, err := repo.RunVerbose(cmd)
- return err
- } else {
- 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
-}
-
// removes all local branches
func doCleanUserRepo(repo *gitpb.Repo) error {
var hasLocal bool
@@ -560,3 +500,39 @@ func doCleanPub() error {
log.Printf("clearing %d total repos\n", total)
return nil
}
+
+// if you call this, there is no going back. no checks anymore. nothing
+// it deletes the 'devel' branch. git branch -D "devel". END OF STORY
+func justDeleteTheDevelBranchAlready(repo *gitpb.Repo) error {
+ branch := repo.GetDevelBranchName()
+ remote := filepath.Join("origin", branch)
+
+ // check against remote if it exists
+ if repo.Exists(filepath.Join(".git/refs/remotes", remote)) {
+ b1 := countGitDiffLog(repo, branch, remote) // should be zero
+ if b1 == 0 {
+ cmd := []string{"git", "branch", "-D", repo.GetDevelBranchName()}
+ log.Info("DEVEL IS IN REMOTE", repo.GetGoPath(), cmd)
+ _, err := repo.RunVerbose(cmd)
+ return err
+ }
+ cmd := []string{"git", "push"}
+ log.Info("DEVEL LOCAL NEEDS GIT PUSH TO REMOTE", repo.GetGoPath(), cmd)
+ _, err := repo.RunVerbose(cmd)
+ return err
+ }
+
+ // remote doesn't exist, check against master
+ master := repo.GetMasterBranchName()
+ b1 := countGitDiffLog(repo, branch, master) // should be zero
+ if b1 == 0 {
+ cmd := []string{"git", "branch", "-D", repo.GetDevelBranchName()}
+ log.Info("DEVEL IS IN REMOTE", repo.GetGoPath(), cmd)
+ _, err := repo.RunVerbose(cmd)
+ return err
+ }
+ cmd := []string{"git", "merge something somehow"}
+ log.Info("DEVEL LOCAL NEEDS GIT MERGE TO MASTER", repo.GetGoPath(), cmd)
+ // _, err := repo.RunVerbose(cmd)
+ return nil
+}
diff --git a/doVerifyDevel.go b/doVerifyDevel.go
index 0851f09..51fec2c 100644
--- a/doVerifyDevel.go
+++ b/doVerifyDevel.go
@@ -30,14 +30,16 @@ func doVerifyDevel() error {
log.Printf("Start clean devel branch: %s %s\n", repo.GetGoPath(), devel)
}
- // check if devel branch exists in remote repo
- if repo.IsBranchRemote(devel) {
- if err := doCleanDevelRepo(repo); err != nil {
- log.Info(repo.GetGoPath(), "verify clean failed")
+ /*
+ // check if devel branch exists in remote repo
+ if repo.IsBranchRemote(devel) {
+ if err := doCleanDevelRepo(repo); err != nil {
+ log.Info(repo.GetGoPath(), "verify clean failed")
+ }
+ // can not continue
+ continue
}
- // can not continue
- continue
- }
+ */
// devel branch is only local
/*
todo: something?
diff --git a/doVerifyUser.go b/doVerifyUser.go
index aa8305e..2f5cf5c 100644
--- a/doVerifyUser.go
+++ b/doVerifyUser.go
@@ -33,14 +33,16 @@ func doVerifyUser() error {
log.Printf("Start clean devel branch: %s %s\n", repo.GetGoPath(), devel)
}
- // check if devel branch exists in remote repo
- if repo.IsBranchRemote(devel) {
- if err := doCleanDevelRepo(repo); err != nil {
- log.Info(repo.GetGoPath(), "verify clean failed")
+ /*
+ // check if devel branch exists in remote repo
+ if repo.IsBranchRemote(devel) {
+ if err := doCleanDevelRepo(repo); err != nil {
+ log.Info(repo.GetGoPath(), "verify clean failed")
+ }
+ // can not continue
+ continue
}
- // can not continue
- continue
- }
+ */
// devel branch is only local
/*
todo: something?