fix pre delete dirmd set dir bug and implement last git sha and commit#
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
|
||||
"git.flo.fo/FLO/dirmd/internal/git"
|
||||
"git.flo.fo/FLO/dirmd/internal/tree"
|
||||
"git.flo.fo/FLO/dirmd/internal/walker"
|
||||
)
|
||||
@@ -38,9 +39,10 @@ func Write(result *walker.Result, outputPath string, appendMode bool, singleFile
|
||||
|
||||
fmt.Fprintf(&sb, "# %s [ROOT]\n", h1Path)
|
||||
|
||||
// Add timestamp only if creating a new file (not append mode)
|
||||
if !appendMode {
|
||||
fmt.Fprintf(&sb, "> Generated: %s\n\n", time.Now().Format(time.RFC3339))
|
||||
fmt.Fprintf(&sb, "> Generated: %s\n", time.Now().Format(time.RFC3339))
|
||||
sb.WriteString(git.FormatCommitLine(result.Commit))
|
||||
sb.WriteString("\n")
|
||||
}
|
||||
|
||||
if !singleFile {
|
||||
@@ -116,7 +118,7 @@ func WriteSlices(result *walker.Result, outputDir, repoName string) ([]string, e
|
||||
rootPath := filepath.Join(outputDir, indexBasename)
|
||||
generated = append(generated, rootPath)
|
||||
|
||||
if err := writeRootSlice(rootPath, absRoot, rootName, repoName, rootFiles, topLevelDirs, result.OmitTest); err != nil {
|
||||
if err := writeRootSlice(rootPath, absRoot, rootName, repoName, rootFiles, topLevelDirs, result.OmitTest, result.Commit); err != nil {
|
||||
return nil, fmt.Errorf("failed to write root slice: %w", err)
|
||||
}
|
||||
|
||||
@@ -151,7 +153,7 @@ func WriteSlices(result *walker.Result, outputDir, repoName string) ([]string, e
|
||||
}
|
||||
}
|
||||
|
||||
if err := writeDirSlice(slicePath, absDir, absRoot, dirName, treeEntries, dirEntries, indexBasename, result.OmitTest); err != nil {
|
||||
if err := writeDirSlice(slicePath, absDir, absRoot, dirName, treeEntries, dirEntries, indexBasename, result.OmitTest, result.Commit); err != nil {
|
||||
return nil, fmt.Errorf("failed to write slice %s: %w", sliceName, err)
|
||||
}
|
||||
}
|
||||
@@ -159,7 +161,7 @@ func WriteSlices(result *walker.Result, outputDir, repoName string) ([]string, e
|
||||
return generated, nil
|
||||
}
|
||||
|
||||
func writeRootSlice(path, absRoot, rootName, repoName string, rootFiles []walker.Entry, topLevelDirs map[string][]walker.Entry, omitTest bool) error {
|
||||
func writeRootSlice(path, absRoot, rootName, repoName string, rootFiles []walker.Entry, topLevelDirs map[string][]walker.Entry, omitTest bool, commit *git.CommitInfo) error {
|
||||
f, err := os.Create(path)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot create root file: %w", err)
|
||||
@@ -169,8 +171,9 @@ func writeRootSlice(path, absRoot, rootName, repoName string, rootFiles []walker
|
||||
var sb strings.Builder
|
||||
|
||||
fmt.Fprintf(&sb, "# %s [ROOT]\n", absRoot)
|
||||
// Timestamp for new file creation
|
||||
fmt.Fprintf(&sb, "> Generated: %s\n\n", time.Now().Format(time.RFC3339))
|
||||
fmt.Fprintf(&sb, "> Generated: %s\n", time.Now().Format(time.RFC3339))
|
||||
sb.WriteString(git.FormatCommitLine(commit))
|
||||
sb.WriteString("\n")
|
||||
|
||||
treeLines := buildTreeWithRefs(rootName, repoName, topLevelDirs, rootFiles)
|
||||
sb.WriteString("## Directory Tree\n\n")
|
||||
@@ -238,7 +241,7 @@ func writeRootSlice(path, absRoot, rootName, repoName string, rootFiles []walker
|
||||
return err
|
||||
}
|
||||
|
||||
func writeDirSlice(path, absDir, absRoot, dirName string, treeEntries, fileEntries []walker.Entry, rootFileName string, omitTest bool) error {
|
||||
func writeDirSlice(path, absDir, absRoot, dirName string, treeEntries, fileEntries []walker.Entry, rootFileName string, omitTest bool, commit *git.CommitInfo) error {
|
||||
f, err := os.Create(path)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot create slice file: %w", err)
|
||||
@@ -248,8 +251,8 @@ func writeDirSlice(path, absDir, absRoot, dirName string, treeEntries, fileEntri
|
||||
var sb strings.Builder
|
||||
|
||||
fmt.Fprintf(&sb, "# %s [SLICE]\n", absDir)
|
||||
// Timestamp for new file creation
|
||||
fmt.Fprintf(&sb, "> Generated: %s\n\n", time.Now().Format(time.RFC3339))
|
||||
fmt.Fprintf(&sb, "> Generated: %s\n", time.Now().Format(time.RFC3339))
|
||||
sb.WriteString(git.FormatCommitLine(commit))
|
||||
fmt.Fprintf(&sb, "Root document: %s\n\n", rootFileName)
|
||||
|
||||
sb.WriteString("## Directory Tree\n\n")
|
||||
|
||||
Reference in New Issue
Block a user