]> Lady’s Gitweb - Gitweb/commitdiff
gitweb: check given hash before trying to create snapshot
authorMark Rada <redacted>
Sat, 26 Sep 2009 17:46:08 +0000 (13:46 -0400)
committerLady <redacted>
Mon, 6 Apr 2026 04:50:39 +0000 (00:50 -0400)
Makes things nicer in cases when you hand craft the snapshot URL but
make a typo in defining the hash variable (e.g. netx instead of next);
you will now get an error message instead of a broken tarball.

Tests for t9501 are included to demonstrate added functionality.

Signed-off-by: Mark Rada <redacted>
Signed-off-by: Shawn O. Pearce <redacted>
gitweb.perl

index 03900fa1d82a9b3a65baa7b9e5449aacff85cac29d70434ebd3e2ad8c215eefc..7e1e27a35e3b0352183c4ea4f5a3a1be0e11d9b2077b8baaa3a2d99a288b7199 100755 (executable)
@@ -5375,8 +5375,11 @@ sub git_snapshot {
                die_error(403, "Unsupported snapshot format");
        }
 
-       if (!defined $hash) {
-               $hash = git_get_head_hash($project);
+       my $type = git_get_type("$hash^{}");
+       if (!$type) {
+               die_error(404, 'Object does not exist');
+       }  elsif ($type eq 'blob') {
+               die_error(400, 'Object is not a tree-ish');
        }
 
        my $name = $project;
This page took 0.251885 seconds and 4 git commands to generate.