automated snapshot
This commit is contained in:
10
storage.go
10
storage.go
@@ -94,7 +94,7 @@ func (s *Storage) Save(img *rl.Image) (string, error) {
|
||||
|
||||
rl.ExportImage(*img, snapshotPng)
|
||||
|
||||
hash, branch, committed, err := CommitAllIfDirty(s.repoRoot, "automated snapshot")
|
||||
hash, branch, committed, err := CommitAllIfDirty(s.repoRoot, "automated snapshot", s.log)
|
||||
|
||||
if err != nil {
|
||||
s.log.Printf("Error getting working tree in a known clean state: %v", err)
|
||||
@@ -157,15 +157,17 @@ func IsDirty(repoPath string) (bool, error) {
|
||||
return !status.IsClean(), nil
|
||||
}
|
||||
|
||||
func CommitAllIfDirty(repoPath, message string) (commitHash string, branch string, committed bool, err error) {
|
||||
func CommitAllIfDirty(repoPath, message string, log *log.Logger) (commitHash string, branch string, committed bool, err error) {
|
||||
r, err := git.PlainOpen(repoPath)
|
||||
if err != nil {
|
||||
log.Printf("Error opening git repo")
|
||||
return
|
||||
}
|
||||
|
||||
// Determine branch (may be empty if detached)
|
||||
ref, err := r.Head()
|
||||
if err != nil {
|
||||
log.Printf("Error determining head commit")
|
||||
return
|
||||
}
|
||||
if ref.Name().IsBranch() {
|
||||
@@ -174,11 +176,13 @@ func CommitAllIfDirty(repoPath, message string) (commitHash string, branch strin
|
||||
|
||||
wt, err := r.Worktree()
|
||||
if err != nil {
|
||||
log.Printf("Error getting worktree state")
|
||||
return
|
||||
}
|
||||
|
||||
status, err := wt.Status()
|
||||
if err != nil {
|
||||
log.Printf("Error getting worktree status")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -188,6 +192,7 @@ func CommitAllIfDirty(repoPath, message string) (commitHash string, branch strin
|
||||
|
||||
// Stage everything (git add -A)
|
||||
if err = wt.AddWithOptions(&git.AddOptions{All: true}); err != nil {
|
||||
log.Printf("Error adding git changes to index")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -199,6 +204,7 @@ func CommitAllIfDirty(repoPath, message string) (commitHash string, branch strin
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
log.Printf("Error creating commit")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user