aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorjet2tlf <jet2tlf@gmail.com>2024-06-01 04:52:24 +0000
committerjet2tlf <jet2tlf@gmail.com>2024-06-01 04:52:24 +0000
commit4234f96a8e52ce2eb329ee9b92f0eaa195fe2a7c (patch)
treefe985e7bbe63b0dc0c741537738711776291448c /cmd
parent1028bb5cf5b3cddce0582bdabbf520facbaf2f9b (diff)
downloadgit-go-4234f96a8e52ce2eb329ee9b92f0eaa195fe2a7c.tar.gz
git-go-4234f96a8e52ce2eb329ee9b92f0eaa195fe2a7c.zip
codecrafters submit [skip ci]
Diffstat (limited to 'cmd')
-rw-r--r--cmd/mygit/main.go19
1 files changed, 19 insertions, 0 deletions
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)