aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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)