summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common.go31
-rw-r--r--reloadCheckDirty.go3
2 files changed, 33 insertions, 1 deletions
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
+}
diff --git a/reloadCheckDirty.go b/reloadCheckDirty.go
index 980cd5f..d17045a 100644
--- a/reloadCheckDirty.go
+++ b/reloadCheckDirty.go
@@ -22,7 +22,8 @@ func (repo *Repo) IsDirty() bool {
return repo.Dirty
}
-// actually os.Exec('git')
+// returns true if the repo is dirty
+// runs os.Exec('git') every time
func (repo *Repo) CheckDirty() bool {
cmd := []string{"git", "status", "--porcelain"}
r := shell.PathRunLog(repo.FullPath, cmd, INFO)