2025-02-01 11:57:52 -06:00
|
|
|
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
|
|
|
|
// Use of this source code is governed by the GPL 3.0
|
|
|
|
|
2025-01-20 01:47:27 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"go.wit.com/lib/gui/shell"
|
2025-02-20 09:37:42 -06:00
|
|
|
"go.wit.com/lib/protobuf/gitpb"
|
2025-01-20 01:47:27 -06:00
|
|
|
"go.wit.com/log"
|
|
|
|
)
|
|
|
|
|
|
|
|
func doCommit() {
|
2025-02-20 09:37:42 -06:00
|
|
|
if argv.All {
|
|
|
|
log.Info("do a commit everywhere")
|
|
|
|
doCheckDirtyAndConfigSave()
|
2025-02-21 18:31:26 -06:00
|
|
|
found := findDirty()
|
|
|
|
all := found.All()
|
2025-02-20 09:37:42 -06:00
|
|
|
for all.Scan() {
|
|
|
|
repo := all.Next()
|
|
|
|
log.Info("do a commit on repo", repo.GetGoPath())
|
|
|
|
if err := doCommitRepo(repo); err != nil {
|
|
|
|
badExit(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
okExit("")
|
|
|
|
}
|
|
|
|
|
2025-01-20 01:47:27 -06:00
|
|
|
pwd, _ := os.Getwd()
|
|
|
|
repo := me.forge.Repos.FindByFullPath(pwd)
|
|
|
|
if repo == nil {
|
2025-01-29 01:12:44 -06:00
|
|
|
log.Info("todo: forge doesn't know how to work here yet")
|
2025-01-20 01:47:27 -06:00
|
|
|
okExit("")
|
|
|
|
}
|
2025-02-15 17:07:07 -06:00
|
|
|
|
2025-01-20 01:47:27 -06:00
|
|
|
if repo.GetCurrentBranchName() != repo.GetUserBranchName() {
|
|
|
|
me.found.Append(repo)
|
|
|
|
me.forge.PrintHumanTable(me.found)
|
|
|
|
log.Info("")
|
|
|
|
log.Info("wrong branch. Can not commit on", repo.GetCurrentBranchName())
|
|
|
|
log.Info("")
|
|
|
|
okExit("")
|
|
|
|
}
|
2025-02-15 17:07:07 -06:00
|
|
|
|
2025-01-20 01:47:27 -06:00
|
|
|
os.Setenv("LESS", "-XR")
|
|
|
|
if err := shell.Exec([]string{"git", "diff"}); err != nil {
|
|
|
|
badExit(err)
|
|
|
|
}
|
2025-02-15 17:07:07 -06:00
|
|
|
|
2025-01-20 01:47:27 -06:00
|
|
|
if argv.All {
|
|
|
|
if err := shell.ExecCheck([]string{"git", "add", "--all"}); err != nil {
|
|
|
|
badExit(err)
|
|
|
|
}
|
|
|
|
}
|
2025-02-15 17:07:07 -06:00
|
|
|
|
2025-01-20 01:47:27 -06:00
|
|
|
if err := shell.ExecCheck([]string{"git", "commit", "--all"}); err != nil {
|
|
|
|
badExit(err)
|
|
|
|
}
|
|
|
|
log.Info("git commit ok. forge done")
|
|
|
|
}
|
2025-02-20 09:37:42 -06:00
|
|
|
|
|
|
|
func doCommitRepo(repo *gitpb.Repo) error {
|
|
|
|
if repo.GetCurrentBranchName() != repo.GetUserBranchName() {
|
|
|
|
me.found.Append(repo)
|
|
|
|
me.forge.PrintHumanTable(me.found)
|
|
|
|
log.Info("")
|
|
|
|
log.Info("wrong branch. Can not commit on", repo.GetCurrentBranchName())
|
|
|
|
log.Info("")
|
|
|
|
return nil
|
|
|
|
}
|
2025-02-20 09:39:00 -06:00
|
|
|
os.Chdir(repo.GetFullPath())
|
2025-02-20 09:37:42 -06:00
|
|
|
|
|
|
|
os.Setenv("LESS", "-XR")
|
|
|
|
if err := shell.Exec([]string{"git", "diff"}); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if argv.All {
|
|
|
|
if err := shell.ExecCheck([]string{"git", "add", "--all"}); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := shell.ExecCheck([]string{"git", "commit", "--all"}); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
log.Info("git commit ok. forge done")
|
|
|
|
return nil
|
|
|
|
}
|