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)
|
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 {
|
if err != nil {
|
||||||
s.log.Printf("Error getting working tree in a known clean state: %v", err)
|
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
|
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)
|
r, err := git.PlainOpen(repoPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Printf("Error opening git repo")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine branch (may be empty if detached)
|
// Determine branch (may be empty if detached)
|
||||||
ref, err := r.Head()
|
ref, err := r.Head()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Printf("Error determining head commit")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if ref.Name().IsBranch() {
|
if ref.Name().IsBranch() {
|
||||||
@@ -174,11 +176,13 @@ func CommitAllIfDirty(repoPath, message string) (commitHash string, branch strin
|
|||||||
|
|
||||||
wt, err := r.Worktree()
|
wt, err := r.Worktree()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Printf("Error getting worktree state")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
status, err := wt.Status()
|
status, err := wt.Status()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Printf("Error getting worktree status")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,6 +192,7 @@ func CommitAllIfDirty(repoPath, message string) (commitHash string, branch strin
|
|||||||
|
|
||||||
// Stage everything (git add -A)
|
// Stage everything (git add -A)
|
||||||
if err = wt.AddWithOptions(&git.AddOptions{All: true}); err != nil {
|
if err = wt.AddWithOptions(&git.AddOptions{All: true}); err != nil {
|
||||||
|
log.Printf("Error adding git changes to index")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,6 +204,7 @@ func CommitAllIfDirty(repoPath, message string) (commitHash string, branch strin
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Printf("Error creating commit")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user