I’m stuck on Stage #kp1 Read a Tree Object. Well, not quite stuck, but I have an issue with the output.
Here is my output:
> ruby app/main.rb ls-tree ff6701c8e530eba2971947371969961b452a262b
040000 tree ee82ed095fba59cc4813fe531c34d0c902e1c .codecrafters
100644 blob 176a458f94e0ea5272ce67c36bf3b6be9caf623 .gitattributes
100644 blob f5f8981fa3cf5b9354bbe3201a7ad0517c73b8 Gemfile
100644 blob 5bcfb0539d67a86ebfdf012718b223861b92346 Gemfile.lock
100644 blob f2c66328f79f85f856079812a55b64ac6170b4 README.md
040000 tree 31a982d7bbc82617594409b7a2ef9fe3fd3cd69 app
100644 blob ddced257417d3c76a282e412c4931f2b2d0887d codecrafters.yml
100644 blob 685a6166843fa19d48fafb9b8829fa1bbd74d73 newfile
100644 blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 testfile
100755 blob 6751f3a8e1f5cdfc43bad7c1aec91729865ff3d6 your_program.sh
And here is the output of the actual git command:
> git ls-tree ff6701c8e530eba2971947371969961b452a262b
040000 tree ee820ed095fba59cc48103fe531c34d0c9002e1c .codecrafters
100644 blob 176a458f94e0ea5272ce67c36bf30b6be9caf623 .gitattributes
100644 blob f5f89801fa3cf5b9354b0be3201a7ad0517c73b8 Gemfile
100644 blob 5bcfb0539d067a86ebfdf012718b223861b92346 Gemfile.lock
100644 blob f2c663028f79f85f8560790812a55b64ac6170b4 README.md
040000 tree 31a9820d7bbc82617594409b7a2ef9fe3fd3cd69 app
100644 blob ddce0d257417d3c76a282e412c4931f2b2d0887d codecrafters.yml
100644 blob 685a6166843fa19d48fa0fb9b8829fa1bbd74d73 newfile
100644 blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 testfile
100755 blob 6751f3a8e1f5cdfc43bad7c1aec91729865ff3d6 your_program.sh
I would really like to have the output nicely aligned too!
Here is my code for formatting the output:
entries << if mode =~ /.40000/
'040000 tree %-40<sha>s %<name>s' % {name: name, sha: bin_to_hex(sha)}
else
'%<mode>s blob %-40<sha>s %<name>s' % {mode: mode, sha: bin_to_hex(sha), name: name}
end
But as shown above, that does not align the hashes as desired. Any help would be greatly appreciated.



