Enhance commit logging with detailed change summaries and branch info
This commit is contained in:
45
main.go
45
main.go
@@ -2,15 +2,14 @@ package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
logger "git.site.quack-lab.dev/dave/cylogger"
|
||||
"github.com/go-git/go-git/v5/plumbing/object"
|
||||
"github.com/go-git/go-git/v5"
|
||||
"github.com/go-git/go-git/v5/plumbing/object"
|
||||
)
|
||||
|
||||
var ROOT string
|
||||
@@ -18,7 +17,6 @@ var ROOT string
|
||||
func main() {
|
||||
scanIntervalF := flag.String("interval", "2s", "scan interval")
|
||||
flag.Parse()
|
||||
log.SetFlags(log.Lmicroseconds)
|
||||
|
||||
scanInterval, err := time.ParseDuration(*scanIntervalF)
|
||||
if err != nil {
|
||||
@@ -76,7 +74,21 @@ func doRun() {
|
||||
logger.Info("Nothing to commit")
|
||||
return
|
||||
}
|
||||
logger.Info("Changes detected")
|
||||
|
||||
// Count changes by type
|
||||
var added, modified, deleted int
|
||||
for _, s := range status {
|
||||
switch s.Worktree {
|
||||
case git.Modified:
|
||||
modified++
|
||||
case git.Added:
|
||||
added++
|
||||
case git.Deleted:
|
||||
deleted++
|
||||
}
|
||||
}
|
||||
|
||||
logger.Info("Changes detected: %d added, %d modified, %d deleted", added, modified, deleted)
|
||||
|
||||
// Add all changes
|
||||
err = w.AddWithOptions(&git.AddOptions{All: true})
|
||||
@@ -93,18 +105,39 @@ func doRun() {
|
||||
return
|
||||
}
|
||||
|
||||
// Get current branch
|
||||
head, err := r.Head()
|
||||
if err != nil {
|
||||
logger.Error("Error getting HEAD: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Commit changes
|
||||
_, err = w.Commit("Update", &git.CommitOptions{
|
||||
commit, err := w.Commit("Update", &git.CommitOptions{
|
||||
Author: &object.Signature{
|
||||
Name: "system",
|
||||
Email: "system@localhost",
|
||||
When: time.Now(),
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
logger.Error("Error committing changes: %v", err)
|
||||
return
|
||||
}
|
||||
logger.Info("Changes committed")
|
||||
|
||||
// Get commit details
|
||||
commitObj, err := r.CommitObject(commit)
|
||||
if err != nil {
|
||||
logger.Error("Error getting commit details: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
logger.Info("Changes committed successfully:")
|
||||
logger.Info(" Branch: %s", head.Name().Short())
|
||||
logger.Info(" Commit: %s", commitObj.Hash.String())
|
||||
logger.Info(" Author: %s <%s>", commitObj.Author.Name, commitObj.Author.Email)
|
||||
logger.Info(" Date: %s", commitObj.Author.When.Format(time.RFC3339))
|
||||
logger.Info(" Message: %s", commitObj.Message)
|
||||
}
|
||||
|
||||
func setIdentity(r *git.Repository) error {
|
||||
|
Reference in New Issue
Block a user