diff options
| -rw-r--r-- | argv.go | 6 | ||||
| -rw-r--r-- | doDebian.go | 2 | ||||
| -rw-r--r-- | doGit.go | 63 | ||||
| -rw-r--r-- | doUpgrade.go | 21 | ||||
| -rw-r--r-- | exit.go | 50 | ||||
| -rw-r--r-- | main.go | 13 | ||||
| -rw-r--r-- | structs.go | 3 |
7 files changed, 121 insertions, 37 deletions
@@ -54,8 +54,10 @@ type DefaultCmd struct { } type GitCmd struct { - Log *EmptyCmd `arg:"subcommand:log" help:"go-clone from a gowebd repomap"` - Who *EmptyCmd `arg:"subcommand:who" help:"go-clone from a gowebd repomap"` + Log *EmptyCmd `arg:"subcommand:log" help:"git log"` + Who *EmptyCmd `arg:"subcommand:who" help:"git who"` + Pull *EmptyCmd `arg:"subcommand:pull" help:"pull the wit standard paths"` + Push *EmptyCmd `arg:"subcommand:push" help:"push the wit standard paths"` } type EmptyCmd struct { diff --git a/doDebian.go b/doDebian.go index 00a1390..160a01d 100644 --- a/doDebian.go +++ b/doDebian.go @@ -21,5 +21,5 @@ func doDebian() { okExit("") } - exitOnError([]string{"do-aptly"}) + exitOnErrorRealtime([]string{"do-aptly"}) } @@ -4,10 +4,59 @@ package main import ( + "os" + "path/filepath" + "go.wit.com/lib/gui/shell" + "go.wit.com/lib/protobuf/gitpb" "go.wit.com/log" ) +func findRepo(wpath string) (*gitpb.Repo, bool) { + d := filepath.Join(me.homedir, wpath) + if !shell.IsDir(d) { + return nil, false + } + repo, err := gitpb.NewRepo(d) + if err != nil { + log.Info("path error", d, err) + return nil, false + } + return repo, true +} + +func doPull(wpath string) { + repo, ok := findRepo(wpath) + if ok { + return + } + os.Chdir(repo.FullPath) + exitOnErrorRealtime([]string{"git", "pull"}) +} + +func doPush(wpath string) { + doPull(wpath) + d := filepath.Join(me.homedir, wpath) + if !shell.IsDir(d) { + return + } + repo, err := gitpb.NewRepo(d) + if err != nil { + log.Info("path error", d, err) + return + } + if repo == nil { + log.Info("repo is nil", d, err) + return + } + + if err := repo.GitCommit(); err != nil { + badExit(err) + } + + repo.RunRealtime([]string{"git", "push"}) +} + func doGit() error { log.DaemonMode(true) defer log.DaemonMode(false) @@ -16,11 +65,25 @@ func doGit() error { fstr := "--format=\"%h %>(24)%ar %>(20)%an %s" cmd := []string{"git", "log", fstr} shell.RunVerbose(cmd) + okExit("") } if argv.Git.Who != nil { cmd := []string{"git", "who"} shell.RunVerbose(cmd) + okExit("") + } + + if argv.Git.Pull != nil { + doPull(".config/wit") + doPull("tools") + okExit("") + } + + if argv.Git.Push != nil { + doPush(".config/wit") + doPush("tools") + okExit("") } return nil diff --git a/doUpgrade.go b/doUpgrade.go index 1938900..83f69ef 100644 --- a/doUpgrade.go +++ b/doUpgrade.go @@ -4,30 +4,9 @@ package main import ( - "fmt" - "os" - - "go.wit.com/lib/gui/shell" "go.wit.com/lib/protobuf/zoopb" - "go.wit.com/log" ) -// exits if not root -func checkSuperuser() { - if os.Getuid() != 0 { - badExit(fmt.Errorf("you must be root")) - } -} - -func exitOnError(cmd []string) { - var err error - log.Info("Running:", cmd) - _, err = shell.RunVerbose(cmd) - if err != nil { - badExit(err) - } -} - func doUpgrade() error { var cmd []string @@ -0,0 +1,50 @@ +// Copyright 2017-2025 WIT.COM Inc. All rights reserved. +// Use of this source code is governed by the GPL 3.0 + +package main + +import ( + "fmt" + "os" + + "go.wit.com/lib/gui/shell" + "go.wit.com/log" +) + +// exits if not root +func checkSuperuser() { + if os.Getuid() != 0 { + badExit(fmt.Errorf("you must be root")) + } +} + +func exitOnError(cmd []string) { + var err error + log.Info("Running:", cmd) + _, err = shell.RunVerbose(cmd) + if err != nil { + badExit(err) + } +} + +func exitOnErrorRealtime(cmd []string) { + var err error + log.Info("Running:", cmd) + _, err = shell.RunRealtimeError(cmd) + if err != nil { + badExit(err) + } +} + +func okExit(thing string) { + if thing != "" { + log.Info(thing, "ok") + } + // log.Info("Finished go-clean on", check.GetGoPath(), "ok") + os.Exit(0) +} + +func badExit(err error) { + log.Info("wit failed: ", err) + os.Exit(-1) +} @@ -114,19 +114,6 @@ func trimNonNumericFromStart(s string) string { return "" } -func okExit(thing string) { - if thing != "" { - log.Info(thing, "ok") - } - // log.Info("Finished go-clean on", check.GetGoPath(), "ok") - os.Exit(0) -} - -func badExit(err error) { - log.Info("go-clean failed: ", err, me.forge.Config.ReposDir) - os.Exit(-1) -} - func dumpDebug() { // Get absolute path of the currently running binary exePath, err := os.Executable() @@ -4,6 +4,7 @@ package main import ( + "os" "sync" "go.wit.com/lib/gui/prep" @@ -20,6 +21,7 @@ type mainType struct { auto *prep.Auto // more experiments for bash handling forge *forgepb.Forge // your customized repo preferences and settings machine *zoopb.Machine // your customized repo preferences and settings + homedir string // where the user homedir is } // move these to mainType @@ -49,5 +51,6 @@ func initMain() { state = make(map[*gitpb.Repo]string) debnames = make(map[*gitpb.Repo]string) + me.homedir, _ = os.UserHomeDir() dumpDebug() } |
