Skip to content

Commit

Permalink
gitweb: check given hash before trying to create snapshot
Browse files Browse the repository at this point in the history
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 <marada@uwaterloo.ca>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
  • Loading branch information
Mark Rada authored and Shawn O. Pearce committed Sep 29, 2009
1 parent 1be224b commit fdb0c36
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
7 changes: 5 additions & 2 deletions gitweb/gitweb.perl
Original file line number Diff line number Diff line change
Expand Up @@ -5196,8 +5196,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;
Expand Down
39 changes: 39 additions & 0 deletions t/t9501-gitweb-standalone-http-status.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,43 @@ test_expect_success \
test_debug 'cat gitweb.output'


# ----------------------------------------------------------------------
# snapshot hash ids

test_expect_success 'snapshots: good tree-ish id' '
gitweb_run "p=.git;a=snapshot;h=master;sf=tgz" &&
grep "Status: 200 OK" gitweb.output
'
test_debug 'cat gitweb.output'

test_expect_success 'snapshots: bad tree-ish id' '
gitweb_run "p=.git;a=snapshot;h=frizzumFrazzum;sf=tgz" &&
grep "404 - Object does not exist" gitweb.output
'
test_debug 'cat gitweb.output'

test_expect_success 'snapshots: bad tree-ish id (tagged object)' '
echo object > tag-object &&
git add tag-object &&
git commit -m "Object to be tagged" &&
git tag tagged-object `git hash-object tag-object` &&
gitweb_run "p=.git;a=snapshot;h=tagged-object;sf=tgz" &&
grep "400 - Object is not a tree-ish" gitweb.output
'
test_debug 'cat gitweb.output'

test_expect_success 'snapshots: good object id' '
ID=`git rev-parse --verify HEAD` &&
gitweb_run "p=.git;a=snapshot;h=$ID;sf=tgz" &&
grep "Status: 200 OK" gitweb.output
'
test_debug 'cat gitweb.output'

test_expect_success 'snapshots: bad object id' '
gitweb_run "p=.git;a=snapshot;h=abcdef01234;sf=tgz" &&
grep "404 - Object does not exist" gitweb.output
'
test_debug 'cat gitweb.output'


test_done

0 comments on commit fdb0c36

Please sign in to comment.