From 4234f96a8e52ce2eb329ee9b92f0eaa195fe2a7c Mon Sep 17 00:00:00 2001 From: jet2tlf Date: Sat, 1 Jun 2024 01:52:24 -0300 Subject: codecrafters submit [skip ci] --- cmd/mygit/main.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'cmd/mygit') diff --git a/cmd/mygit/main.go b/cmd/mygit/main.go index 52312b2..2f84bde 100644 --- a/cmd/mygit/main.go +++ b/cmd/mygit/main.go @@ -8,6 +8,8 @@ import ( "io" "os" "path/filepath" + "sort" + "strings" ) func main() { @@ -112,6 +114,23 @@ func main() { fmt.Print(hash) + case "ls-tree": + fileNames := []string{} + files, err := os.ReadDir(".") + if err != nil { + fmt.Fprintf(os.Stderr, "Unknown error %s\n", err) + os.Exit(1) + } + + for _, file := range files { + if file.Name() != ".git" { + fileNames = append(fileNames, file.Name()) + } + } + + sort.Strings(fileNames) + fmt.Println(strings.Join(fileNames, "\n")) + default: fmt.Fprintf(os.Stderr, "Unknown command %s\n", command) os.Exit(1) -- cgit v1.2.3