From d91fa140ba3808b056ca2c2aed126a978601dfe3 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Fri, 3 Oct 2025 02:48:03 -0500 Subject: common 'git commit' function --- common.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'common.go') diff --git a/common.go b/common.go index 11c2c6d..1bf6c6b 100644 --- a/common.go +++ b/common.go @@ -1,5 +1,12 @@ package gitpb +import ( + "os" + + "go.wit.com/lib/gui/shell" + "go.wit.com/log" +) + func (repo *Repo) SetReadOnly(b bool) { repo.ReadOnly = b } @@ -56,3 +63,27 @@ func (repo *Repo) IsDevelBranch() bool { } return false } + +func (repo *Repo) GitCommit() error { + if !repo.CheckDirty() { + // repo is not dirty. nothing to do! + return nil + } + os.Chdir(repo.GetFullPath()) + + os.Setenv("LESS", "-XR") + if err := shell.Exec([]string{"git", "diff"}); err != nil { + return err + } + + if err := shell.ExecCheck([]string{"git", "add", "--all"}); err != nil { + return err + } + + if err := shell.ExecCheck([]string{"git", "commit", "--all"}); err != nil { + shell.ExecCheck([]string{"git", "reset"}) + return err + } + log.Info("git commit ok.") + return nil +} -- cgit v1.2.3