code for a new user to start from scratch
This commit is contained in:
parent
260f4c67e7
commit
81c72468a1
2
Makefile
2
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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
134
doClean.go
134
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
|
||||
}
|
||||
|
|
|
@ -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?
|
||||
|
|
|
@ -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?
|
||||
|
|
Loading…
Reference in New Issue