diff options
| author | jet2tlf <jet2tlf@gmail.com> | 2024-06-01 04:52:24 +0000 |
|---|---|---|
| committer | jet2tlf <jet2tlf@gmail.com> | 2024-06-01 04:52:24 +0000 |
| commit | 4234f96a8e52ce2eb329ee9b92f0eaa195fe2a7c (patch) | |
| tree | fe985e7bbe63b0dc0c741537738711776291448c /cmd/mygit/main.go | |
| parent | 1028bb5cf5b3cddce0582bdabbf520facbaf2f9b (diff) | |
| download | git-go-4234f96a8e52ce2eb329ee9b92f0eaa195fe2a7c.tar.gz git-go-4234f96a8e52ce2eb329ee9b92f0eaa195fe2a7c.zip | |
codecrafters submit [skip ci]
Diffstat (limited to 'cmd/mygit/main.go')
| -rw-r--r-- | cmd/mygit/main.go | 19 |
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) |