radicle-dev / radicle-git

Everything Radicle growing around Git
Other
35 stars 5 forks source link

radicle-surf: fails to retrieve a tree for an empty branch with a single empty commit #103

Closed keepsimple1 closed 1 year ago

keepsimple1 commented 1 year ago

reported from discord by @xphoniex :

for e2e suite of radicle-interface we have an empty branch with a single commit and no files (you can re-create one with git commit --allow-empty) and surf has trouble displaying it:

$ git checkout remotes/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi/orphaned-branch
...
HEAD is now at af3641c Add empty orphaned branch

$ ls -lha
total 12K
drwxrwxr-x 3 da da 4.0K Jan 27 16:47 ./
drwxrwxr-x 3 da da 4.0K Jan 27 16:30 ../
drwxrwxr-x 7 da da 4.0K Jan 27 16:47 .git/

$ git log
commit af3641c3e038698a75649f924d5a39bb551409cd (HEAD, z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi/orphaned-branch)
Author: Alice Liddell <alice@radicle.xyz>
Date:   Thu Nov 17 17:58:14 2022 +0100

    Add empty orphaned branch

    This branch is not connected to any history.

and when hitting http://0.0.0.0:8080/api/v1/projects/rad:zKtT7DmF9H34KkvcKj9PHW19WzjT/tree/af3641c3e038698a75649f924d5a39bb551409cd/, httpd shows:

2023-01-27T13:20:59.356566Z ERROR request{method=GET uri=/api/v1/projects/rad:zKtT7DmF9H34KkvcKj9PHW19WzjT/tree/af3641c3e038698a75649f924d5a39bb551409cd/}: radicle_httpd::api::error: Error: Surf(PathNotFound(""))
2023-01-27T13:20:59.356919Z  INFO request{method=GET uri=/api/v1/projects/rad:zKtT7DmF9H34KkvcKj9PHW19WzjT/tree/af3641c3e038698a75649f924d5a39bb551409cd/ status=500 latency=2.037304ms}: radicle_httpd: Processed
2023-01-27T13:20:59.356971Z ERROR request{method=GET uri=/api/v1/projects/rad:zKtT7DmF9H34KkvcKj9PHW19WzjT/tree/af3641c3e038698a75649f924d5a39bb551409cd/ status=500 latency=2.037304ms}: tower_http::trace::on_failure: response failed classification=Status code: 500 Internal Server Error latency=2 ms
keepsimple1 commented 1 year ago

Upon debugging, the root cause is that repo::tree() fails to retrieve the last_commit and returns error. In more details, the repo::last_commit() method uses a filter to iterate the history of the tree. However, when the filter path was empty, the only empty commit was filtered out and the iterator returned None.

keepsimple1 commented 1 year ago

The fix is merged. Thanks.