Skip to content

Commit

Permalink
gitweb: Fix actionless dispatch for non-existent objects
Browse files Browse the repository at this point in the history
When gitweb URL does not provide action explicitly, e.g.

  http://git.example.org/repo.git/branch

dispatch() tries to guess action (view to be used) based on remaining
parameters.  Among others it is based on the type of requested object,
which gave problems when asking for non-existent branch or file (for
example misspelt name).

Now undefined $action from dispatch() should not result in problems.

Signed-off-by: Jakub Narebski <jnareb@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jakub Narebski authored and Junio C Hamano committed Jan 9, 2012
1 parent 5f4d133 commit 18ab83e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion gitweb/gitweb.perl
Original file line number Diff line number Diff line change
Expand Up @@ -1122,8 +1122,10 @@ sub dispatch {
if (!defined $action) {
if (defined $hash) {
$action = git_get_type($hash);
$action or die_error(404, "Object does not exist");
} elsif (defined $hash_base && defined $file_name) {
$action = git_get_type("$hash_base:$file_name");
$action or die_error(404, "File or directory does not exist");
} elsif (defined $project) {
$action = 'summary';
} else {
Expand Down Expand Up @@ -2364,7 +2366,7 @@ sub get_feed_info {
return unless (defined $project);
# some views should link to OPML, or to generic project feed,
# or don't have specific feed yet (so they should use generic)
return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);
return if (!$action || $action =~ /^(?:tags|heads|forks|tag|search)$/x);

my $branch;
# branches refs uses 'refs/heads/' prefix (fullname) to differentiate
Expand Down
8 changes: 8 additions & 0 deletions t/t9500-gitweb-standalone-no-errors.sh
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,14 @@ test_expect_success \
'path_info: project/branch:dir/' \
'gitweb_run "" "/.git/master:foo/"'

test_expect_success \
'path_info: project/branch (non-existent)' \
'gitweb_run "" "/.git/non-existent"'

test_expect_success \
'path_info: project/branch:filename (non-existent branch)' \
'gitweb_run "" "/.git/non-existent:non-existent"'

test_expect_success \
'path_info: project/branch:file (non-existent)' \
'gitweb_run "" "/.git/master:non-existent"'
Expand Down

0 comments on commit 18ab83e

Please sign in to comment.