check for notes before deleting them

This commit is contained in:
Jeff Carr 2024-12-13 17:31:40 -06:00
parent 2574ec733a
commit 1e4b0c0d37
1 changed files with 7 additions and 2 deletions

View File

@ -13,11 +13,16 @@ import (
// del : true means empty out existing notes, otherwise append // del : true means empty out existing notes, otherwise append
func (repo *Repo) AutogenSave(files []string, refname string, del bool) error { func (repo *Repo) AutogenSave(files []string, refname string, del bool) error {
if del { if del {
cmd := []string{"git", "notes", "show", refname}
if err := repo.StrictRun(cmd); err != nil {
// if there are not any notes, no need to remove them
} else {
cmd := []string{"git", "notes", "remove", refname} cmd := []string{"git", "notes", "remove", refname}
if err := repo.StrictRun(cmd); err != nil { if err := repo.StrictRun(cmd); err != nil {
return err return err
} }
} }
}
for _, fname := range files { for _, fname := range files {
autotag := "// `autogen:" + fname + "`" autotag := "// `autogen:" + fname + "`"
cmd := []string{"git", "notes", "append", "-m", autotag, refname} cmd := []string{"git", "notes", "append", "-m", autotag, refname}