alexander-bauer / grove

Grove is a way for developers to share git repositories directly over HTTP, without needing a central service like GitHub to connect them. Developers can share as many repositories as they like, and don't need to push their changes or branches in order to share them. It offers a featureful but extremely lightweight web interface to allow directory and repository browsing, in addition to retrieval through git. Sharing your work is as simple hitting enter.
Other
23 stars 3 forks source link

Viewing /blob/ should only be allowed if it's a file. #117

Closed lukevers closed 11 years ago

lukevers commented 11 years ago

You can view directories with /blob/ if you so desire, or if a link fails to direct you correctly.

Screen Shot 2013-04-10 at 9 52 17 AM

It just kind of shows all the files in a file holder.

alexander-bauer commented 11 years ago

Alright, I can explain why this is, but I'm not quite sure how to fix it yet. Any references to /blob/ will invoke the function git.GetFile(), which itself invokes git show through the operating system.

// From git.GetFile() in git.go
contents, _ = g.executeB("--no-pager", "show", commit+":"+file)

// From git.GetDir() in git.go
output, _ := g.execute("--no-pager", "show", "--name-only", commit+":"+dir)

git show does not particularly care whether it's reading a file or a directory - it just reads the relevant objects to create some output for the given file (or directory) at the given commit. If it happens to be a file, then it will show the contents of the file. If it's a directory, it will produce a directory listing, as shown above.

As far as Grove knows, it's reading a file with the contents shown above. It had no idea whether it's a directory or a file, and I'm not sure how to make it aware.

lukevers commented 11 years ago

Could we check in MakeTreePage in webui.go to see if it's a directory or file? Then from there we could force it to change to tree/blob if necessary.