From 16b1fbe36cc39a351ef9810b9018d36df833a941 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 2 Mar 2017 23:39:49 +0000 Subject: repobrowse: rename "tree" endpoint to "src" This is shorter, and makes more sense as the endpoint displays both tree listings and actual blob sources. This will also make rewriting existing URLs from cgit installations easier. --- MANIFEST | 4 +- lib/PublicInbox/RepoGitCommit.pm | 6 +- lib/PublicInbox/RepoGitDiffCommon.pm | 8 +- lib/PublicInbox/RepoGitSrc.pm | 249 +++++++++++++++++++++++++++++++++++ lib/PublicInbox/RepoGitSummary.pm | 4 +- lib/PublicInbox/RepoGitTree.pm | 249 ----------------------------------- lib/PublicInbox/Repobrowse.pm | 4 +- t/repobrowse_git_src.t | 33 +++++ t/repobrowse_git_tree.t | 33 ----- 9 files changed, 295 insertions(+), 295 deletions(-) create mode 100644 lib/PublicInbox/RepoGitSrc.pm delete mode 100644 lib/PublicInbox/RepoGitTree.pm create mode 100644 t/repobrowse_git_src.t delete mode 100644 t/repobrowse_git_tree.t diff --git a/MANIFEST b/MANIFEST index 495a63e6..d49b45ce 100644 --- a/MANIFEST +++ b/MANIFEST @@ -97,9 +97,9 @@ lib/PublicInbox/RepoGitRaw.pm lib/PublicInbox/RepoGitSearch.pm lib/PublicInbox/RepoGitSearchIdx.pm lib/PublicInbox/RepoGitSnapshot.pm +lib/PublicInbox/RepoGitSrc.pm lib/PublicInbox/RepoGitSummary.pm lib/PublicInbox/RepoGitTag.pm -lib/PublicInbox/RepoGitTree.pm lib/PublicInbox/RepoRoot.pm lib/PublicInbox/Repobrowse.pm lib/PublicInbox/SaPlugin/ListMirror.pm @@ -197,7 +197,7 @@ t/repobrowse_git_httpd.t t/repobrowse_git_log.t t/repobrowse_git_raw.t t/repobrowse_git_snapshot.t -t/repobrowse_git_tree.t +t/repobrowse_git_src.t t/search.t t/spamcheck_spamc.t t/spawn.t diff --git a/lib/PublicInbox/RepoGitCommit.pm b/lib/PublicInbox/RepoGitCommit.pm index 34f7acc3..8add3006 100644 --- a/lib/PublicInbox/RepoGitCommit.pm +++ b/lib/PublicInbox/RepoGitCommit.pm @@ -40,7 +40,7 @@ sub commit_header { my $rel = $req->{relcmd}; my $x = $self->html_start($req, $s) . "\n" . qq( commit $H (patch)\n) . - qq( tree $t); + qq( tree $t); my $git = $req->{-repo}->{git}; # extra show path information, if any @@ -55,7 +55,7 @@ sub commit_header { my $e = PublicInbox::Hval->utf8($_, join('/', @t)); $ep = $e->as_path; my $eh = $e->as_html; - $ep = "${rel}tree/$ep/$H"; + $ep = "${rel}src/$ep/$H"; qq($eh); } @$extra); $path = "/$ep"; @@ -185,7 +185,7 @@ sub show_unchanged { $p = $p->as_path; $fn = utf8_html($fn); $$dst .= qq(\t); + $$dst .= qq(\nid="$anchor"\nhref="${rel}src/$p">); $$dst .= "$fn\n"; } } diff --git a/lib/PublicInbox/RepoGitDiffCommon.pm b/lib/PublicInbox/RepoGitDiffCommon.pm index 46e243ed..b60a5fbc 100644 --- a/lib/PublicInbox/RepoGitDiffCommon.pm +++ b/lib/PublicInbox/RepoGitDiffCommon.pm @@ -68,7 +68,7 @@ sub git_diff_ab_hunk ($$$$) { $na = defined $na ? "#n$na" : ''; my $p = $req->{p}->[0]; $rv .= qq({path_a}$na">); + $rv .= qq(\nhref="${rel}src/$p/$req->{path_a}$na">); $rv .= "$ca"; } $rv .= ' '; @@ -77,7 +77,7 @@ sub git_diff_ab_hunk ($$$$) { } else { $nb = defined $nb ? "#n$nb" : ''; $rv .= qq({-tip}/$req->{path_b}$nb">); + $rv .= qq(\nhref="${rel}src/$req->{-tip}/$req->{path_b}$nb">); $rv .= "$cb"; } $rv . ' @@' . utf8_html($ctx); @@ -121,14 +121,14 @@ sub git_diff_cc_hunk { } } - # we can use the normal 'tree' endpoint for the result + # we can use the normal 'src' endpoint for the result my ($n) = ($last =~ /\A\+(\d+)/); # line number if ($n == 0) { # deleted file (does this happen with --cc?) $rv .= " $last"; } else { my $H = $req->{H}; $rv .= qq( $last); + $rv .= qq(\nhref="${rel}src/$H/$path#n$n">$last); } $rv .= " $at" . utf8_html($ctx); } diff --git a/lib/PublicInbox/RepoGitSrc.pm b/lib/PublicInbox/RepoGitSrc.pm new file mode 100644 index 00000000..1546830f --- /dev/null +++ b/lib/PublicInbox/RepoGitSrc.pm @@ -0,0 +1,249 @@ +# Copyright (C) 2015 all contributors +# License: AGPL-3.0+ +package PublicInbox::RepoGitSrc; +use strict; +use warnings; +use base qw(PublicInbox::RepoBase); +use PublicInbox::Hval qw(utf8_html); +use PublicInbox::Qspawn; + +my %GIT_MODE = ( + '100644' => ' ', # blob + '100755' => 'x', # executable blob + '040000' => 'd', # tree + '120000' => 'l', # symlink + '160000' => 'g', # commit (gitlink) +); + +my $BINARY_MSG = "Binary file, save using the 'raw' link above"; +my $MAX_ASYNC = 65536; # same as pipe size on Linux +my $BIN_DETECT = 8000; # same as git (buffer_is_binary in git.git) + +sub call_git_src { + my ($self, $req) = @_; + my $repo = $req->{-repo}; + my $git = $repo->{git}; + my $tip = $req->{tip} || $req->{repo}->tip; + sub { + my ($res) = @_; + $git->check_async($req->{env}, "$tip:$req->{expath}", sub { + my ($info) = @_; + my ($hex, $type, $size) = @$info; + unless (defined $type) { + return $res->([404, + ['Content-Type','text/plain'], + ['Not Found']]); + } + show_tree($self, $req, $res, $hex, $type, $size); + }); + } +} + +sub show_tree { + my ($self, $req, $res, $hex, $type, $size) = @_; + my $opts = { nofollow => 1 }; + my $title = "tree: ".utf8_html($req->{expath}); + $req->{thtml} = $self->html_start($req, $title, $opts) . "\n"; + if ($type eq 'tree') { + $opts->{noindex} = 1; + git_tree_show($req, $res, $hex); + } elsif ($type eq 'blob') { + git_blob_show($req, $res, $hex, $size); + } else { + $res->([404, ['Content-Type', 'text/plain; charset=UTF-8'], + ["Unrecognized type ($type) for $hex\n"]]); + } +} + +sub cur_path { + my ($req) = @_; + my @ex = @{$req->{extra}} or return 'root'; + my $s; + my $tip = $req->{tip} || $req->{repo}->tip; + my $rel = $req->{relcmd}; + # avoid relative paths, here, we don't want to propagate + # trailing-slash URLs although we tolerate them + $s = "root/"; + my $cur = pop @ex; + my @t; + $s .= join('/', (map { + push @t, $_; + my $e = PublicInbox::Hval->utf8($_, join('/', @t)); + my $ep = $e->as_path; + my $eh = $e->as_html; + "$eh"; + } @ex), ''.utf8_html($cur).''); +} + +sub git_blob_sed ($$$) { + my ($req, $hex, $size) = @_; + my $pfx = $req->{tpfx}; + my $nl = 0; + my $bytes = 0; + my @lines; + my $buf = ''; + my $rel = $req->{relcmd}; + my $tip = $req->{tip} || $req->{repo}->tip; + my $raw = join('/', "${rel}raw", $tip, @{$req->{extra}}); + $raw = PublicInbox::Hval->utf8($raw)->as_path; + my $t = cur_path($req); + my $end = ''; + $req->{thtml} .= qq{\npath: $t\n\nblob $hex} . + qq{\t$size bytes (raw)}; + $req->{lstart} = '
';
+	my $s;
+
+	sub {
+		my $dst = delete $req->{thtml} || '';
+		if (defined $_[0]) {
+			return '' if $bytes < 0; # binary
+			if ($bytes <= $BIN_DETECT) {
+				if (index($_[0], "\0") >= 0) {
+					$bytes = -1;
+					$s = delete $req->{lstart} and
+						$dst .= $s;
+					$dst .= "\n";
+					$dst .= $BINARY_MSG;
+					return $dst .= '
'; + } + } + $bytes += bytes::length($_[0]); + $buf .= $_[0]; + $_[0] = ''; # save some memory + $s = delete $req->{lstart} and $dst .= $s; + @lines = split(/\r?\n/, $buf, -1); + $buf = pop @lines; # last line, careful... + } else { # EOF + $s = delete $req->{lstart} and $dst .= $s; + @lines = split(/\r?\n/, $buf, -1); + $buf = pop @lines; + $end .= ''; + } + foreach (@lines) { + ++$nl; + $dst .= ""; + $dst .= sprintf("% 5u\t", $nl); + $dst .= utf8_html($_); + $dst .= "\n"; + } + @lines = (); + if ($end && defined $buf && $buf ne '') { + ++$nl; + $dst .= ""; + $dst .= sprintf("% 5u\t", $nl); + $dst .= utf8_html($buf); + $buf = undef; + $dst .= "\n\\ No newline at end of file"; + } + $dst .= $end; + } +} + +sub git_blob_show { + my ($req, $res, $hex, $size) = @_; + my $sed = git_blob_sed($req, $hex, $size); + my $git = $req->{-repo}->{git}; + if ($size <= $MAX_ASYNC) { + my $buf = ''; # we slurp small files + $git->cat_async($req->{env}, $hex, sub { + my ($r) = @_; + my $ref = ref($r); + return if $ref eq 'ARRAY'; # redundant info + if ($ref eq 'SCALAR') { + $buf .= $$r; + if (bytes::length($buf) == $size) { + my $fh = $res->([200, + ['Content-Type', + 'text/html; charset=UTF-8']]); + $fh->write($sed->($buf)); + $fh->write($sed->(undef)); + $fh->close; + } + return; + } + my $cb = $res or return; + $res = undef; + $cb->([500, + ['Content-Type', 'text/plain; charset=UTF-8'], + [ 'Error' ]]); + }); + } else { + $res->([200, ['Content-Type', 'text/plain; charset=UTF-8'], + [ 'Too big' ]]); + } +} + +sub git_tree_sed ($) { + my ($req) = @_; + my @lines; + my $buf = ''; + my $pfx = $req->{tpfx}; + my $end; + sub { + my $dst = delete $req->{thtml} || ''; + if (defined $_[0]) { + @lines = split(/\0/, $buf .= $_[0]); + $buf = pop @lines if @lines; + } else { + @lines = split(/\0/, $buf); + $end = ''; + } + for (@lines) { + my ($m, $x, $s, $path) = + (/\A(\S+) \S+ (\S+)( *\S+)\t(.+)\z/s); + $m = $GIT_MODE{$m} or next; + $path = PublicInbox::Hval->utf8($path); + my $ref = $path->as_path; + $path = $path->as_html; + + if ($m eq 'g') { + # TODO: support cross-repository gitlinks + $dst .= 'g' . (' ' x 15) . "$path @ $x\n"; + next; + } + elsif ($m eq 'd') { $path = "$path/" } + elsif ($m eq 'x') { $path = "$path" } + elsif ($m eq 'l') { $path = "$path" } + $s =~ s/\s+//g; + + # 'raw' and 'log' links intentionally omitted + # for brevity and speed + $dst .= qq($m\t). + qq($s\t$path\n); + } + $dst; + } +} + +sub git_tree_show { + my ($req, $res, $hex) = @_; + my $git = $req->{-repo}->{git}; + my $cmd = $git->cmd(qw(ls-tree -l -z), $git->abbrev, $hex); + my $rdr = { 2 => $git->err_begin }; + my $qsp = PublicInbox::Qspawn->new($cmd, undef, $rdr); + my $t = cur_path($req); + my $pfx; + + $req->{thtml} .= "\npath: $t\n\nmode\tsize\tname\n"; + if (defined(my $last = $req->{extra}->[-1])) { + $pfx = PublicInbox::Hval->utf8($last)->as_path; + } elsif (defined(my $tip = $req->{tip})) { + $pfx = $tip; + } else { + $pfx = 'src/' . $req->{-repo}->tip; + } + $req->{tpfx} = $pfx; + my $env = $req->{env}; + $env->{'qspawn.response'} = $res; + $qsp->psgi_return($env, undef, sub { + my ($r) = @_; + if (defined $r) { + $env->{'qspawn.filter'} = git_tree_sed($req); + [ 200, [ 'Content-Type', 'text/html' ] ]; + } else { + [ 500, [ 'Content-Type', 'text/plain' ], [ $git->err ]]; + } + }); +} + +1; diff --git a/lib/PublicInbox/RepoGitSummary.pm b/lib/PublicInbox/RepoGitSummary.pm index 5eb8087d..96ae9be9 100644 --- a/lib/PublicInbox/RepoGitSummary.pm +++ b/lib/PublicInbox/RepoGitSummary.pm @@ -84,14 +84,14 @@ sub readme_path_links { my ($req, $rel, $readme) = @_; my @path = split(m!/+!, $readme); my $tip = $req->{-repo}->tip; - my $s = "tree root/"; + my $s = "tree root/"; my @t; $s .= join('/', (map { push @t, $_; my $e = PublicInbox::Hval->utf8($_, join('/', @t)); my $ep = $e->as_path; my $eh = $e->as_html; - $e = "$eh"; + $e = "$eh"; # bold the last one scalar(@t) == scalar(@path) ? "$e" : $e; } @path)); diff --git a/lib/PublicInbox/RepoGitTree.pm b/lib/PublicInbox/RepoGitTree.pm deleted file mode 100644 index e8c34a69..00000000 --- a/lib/PublicInbox/RepoGitTree.pm +++ /dev/null @@ -1,249 +0,0 @@ -# Copyright (C) 2015 all contributors -# License: AGPL-3.0+ -package PublicInbox::RepoGitTree; -use strict; -use warnings; -use base qw(PublicInbox::RepoBase); -use PublicInbox::Hval qw(utf8_html); -use PublicInbox::Qspawn; - -my %GIT_MODE = ( - '100644' => ' ', # blob - '100755' => 'x', # executable blob - '040000' => 'd', # tree - '120000' => 'l', # symlink - '160000' => 'g', # commit (gitlink) -); - -my $BINARY_MSG = "Binary file, save using the 'raw' link above"; -my $MAX_ASYNC = 65536; # same as pipe size on Linux -my $BIN_DETECT = 8000; # same as git (buffer_is_binary in git.git) - -sub call_git_tree { - my ($self, $req) = @_; - my $repo = $req->{-repo}; - my $git = $repo->{git}; - my $tip = $req->{tip} || $req->{repo}->tip; - sub { - my ($res) = @_; - $git->check_async($req->{env}, "$tip:$req->{expath}", sub { - my ($info) = @_; - my ($hex, $type, $size) = @$info; - unless (defined $type) { - return $res->([404, - ['Content-Type','text/plain'], - ['Not Found']]); - } - show_tree($self, $req, $res, $hex, $type, $size); - }); - } -} - -sub show_tree { - my ($self, $req, $res, $hex, $type, $size) = @_; - my $opts = { nofollow => 1 }; - my $title = "tree: ".utf8_html($req->{expath}); - $req->{thtml} = $self->html_start($req, $title, $opts) . "\n"; - if ($type eq 'tree') { - $opts->{noindex} = 1; - git_tree_show($req, $res, $hex); - } elsif ($type eq 'blob') { - git_blob_show($req, $res, $hex, $size); - } else { - $res->([404, ['Content-Type', 'text/plain; charset=UTF-8'], - ["Unrecognized type ($type) for $hex\n"]]); - } -} - -sub cur_path { - my ($req) = @_; - my @ex = @{$req->{extra}} or return 'root'; - my $s; - my $tip = $req->{tip} || $req->{repo}->tip; - my $rel = $req->{relcmd}; - # avoid relative paths, here, we don't want to propagate - # trailing-slash URLs although we tolerate them - $s = "root/"; - my $cur = pop @ex; - my @t; - $s .= join('/', (map { - push @t, $_; - my $e = PublicInbox::Hval->utf8($_, join('/', @t)); - my $ep = $e->as_path; - my $eh = $e->as_html; - "$eh"; - } @ex), ''.utf8_html($cur).''); -} - -sub git_blob_sed ($$$) { - my ($req, $hex, $size) = @_; - my $pfx = $req->{tpfx}; - my $nl = 0; - my $bytes = 0; - my @lines; - my $buf = ''; - my $rel = $req->{relcmd}; - my $tip = $req->{tip} || $req->{repo}->tip; - my $raw = join('/', "${rel}raw", $tip, @{$req->{extra}}); - $raw = PublicInbox::Hval->utf8($raw)->as_path; - my $t = cur_path($req); - my $end = ''; - $req->{thtml} .= qq{\npath: $t\n\nblob $hex} . - qq{\t$size bytes (raw)}; - $req->{lstart} = '
';
-	my $s;
-
-	sub {
-		my $dst = delete $req->{thtml} || '';
-		if (defined $_[0]) {
-			return '' if $bytes < 0; # binary
-			if ($bytes <= $BIN_DETECT) {
-				if (index($_[0], "\0") >= 0) {
-					$bytes = -1;
-					$s = delete $req->{lstart} and
-						$dst .= $s;
-					$dst .= "\n";
-					$dst .= $BINARY_MSG;
-					return $dst .= '
'; - } - } - $bytes += bytes::length($_[0]); - $buf .= $_[0]; - $_[0] = ''; # save some memory - $s = delete $req->{lstart} and $dst .= $s; - @lines = split(/\r?\n/, $buf, -1); - $buf = pop @lines; # last line, careful... - } else { # EOF - $s = delete $req->{lstart} and $dst .= $s; - @lines = split(/\r?\n/, $buf, -1); - $buf = pop @lines; - $end .= ''; - } - foreach (@lines) { - ++$nl; - $dst .= ""; - $dst .= sprintf("% 5u\t", $nl); - $dst .= utf8_html($_); - $dst .= "\n"; - } - @lines = (); - if ($end && defined $buf && $buf ne '') { - ++$nl; - $dst .= ""; - $dst .= sprintf("% 5u\t", $nl); - $dst .= utf8_html($buf); - $buf = undef; - $dst .= "\n\\ No newline at end of file"; - } - $dst .= $end; - } -} - -sub git_blob_show { - my ($req, $res, $hex, $size) = @_; - my $sed = git_blob_sed($req, $hex, $size); - my $git = $req->{-repo}->{git}; - if ($size <= $MAX_ASYNC) { - my $buf = ''; # we slurp small files - $git->cat_async($req->{env}, $hex, sub { - my ($r) = @_; - my $ref = ref($r); - return if $ref eq 'ARRAY'; # redundant info - if ($ref eq 'SCALAR') { - $buf .= $$r; - if (bytes::length($buf) == $size) { - my $fh = $res->([200, - ['Content-Type', - 'text/html; charset=UTF-8']]); - $fh->write($sed->($buf)); - $fh->write($sed->(undef)); - $fh->close; - } - return; - } - my $cb = $res or return; - $res = undef; - $cb->([500, - ['Content-Type', 'text/plain; charset=UTF-8'], - [ 'Error' ]]); - }); - } else { - $res->([200, ['Content-Type', 'text/plain; charset=UTF-8'], - [ 'Too big' ]]); - } -} - -sub git_tree_sed ($) { - my ($req) = @_; - my @lines; - my $buf = ''; - my $pfx = $req->{tpfx}; - my $end; - sub { - my $dst = delete $req->{thtml} || ''; - if (defined $_[0]) { - @lines = split(/\0/, $buf .= $_[0]); - $buf = pop @lines if @lines; - } else { - @lines = split(/\0/, $buf); - $end = ''; - } - for (@lines) { - my ($m, $x, $s, $path) = - (/\A(\S+) \S+ (\S+)( *\S+)\t(.+)\z/s); - $m = $GIT_MODE{$m} or next; - $path = PublicInbox::Hval->utf8($path); - my $ref = $path->as_path; - $path = $path->as_html; - - if ($m eq 'g') { - # TODO: support cross-repository gitlinks - $dst .= 'g' . (' ' x 15) . "$path @ $x\n"; - next; - } - elsif ($m eq 'd') { $path = "$path/" } - elsif ($m eq 'x') { $path = "$path" } - elsif ($m eq 'l') { $path = "$path" } - $s =~ s/\s+//g; - - # 'raw' and 'log' links intentionally omitted - # for brevity and speed - $dst .= qq($m\t). - qq($s\t$path\n); - } - $dst; - } -} - -sub git_tree_show { - my ($req, $res, $hex) = @_; - my $git = $req->{-repo}->{git}; - my $cmd = $git->cmd(qw(ls-tree -l -z), $git->abbrev, $hex); - my $rdr = { 2 => $git->err_begin }; - my $qsp = PublicInbox::Qspawn->new($cmd, undef, $rdr); - my $t = cur_path($req); - my $pfx; - - $req->{thtml} .= "\npath: $t\n\nmode\tsize\tname\n"; - if (defined(my $last = $req->{extra}->[-1])) { - $pfx = PublicInbox::Hval->utf8($last)->as_path; - } elsif (defined(my $tip = $req->{tip})) { - $pfx = $tip; - } else { - $pfx = 'tree/' . $req->{-repo}->tip; - } - $req->{tpfx} = $pfx; - my $env = $req->{env}; - $env->{'qspawn.response'} = $res; - $qsp->psgi_return($env, undef, sub { - my ($r) = @_; - if (defined $r) { - $env->{'qspawn.filter'} = git_tree_sed($req); - [ 200, [ 'Content-Type', 'text/html' ] ]; - } else { - [ 500, [ 'Content-Type', 'text/plain' ], [ $git->err ]]; - } - }); -} - -1; diff --git a/lib/PublicInbox/Repobrowse.pm b/lib/PublicInbox/Repobrowse.pm index aad0e8ba..5ef9e59a 100644 --- a/lib/PublicInbox/Repobrowse.pm +++ b/lib/PublicInbox/Repobrowse.pm @@ -22,7 +22,7 @@ use strict; use warnings; use PublicInbox::RepoConfig; -my %CMD = map { lc($_) => $_ } qw(Log Commit Tree Patch Blob Raw Tag Atom +my %CMD = map { lc($_) => $_ } qw(Log Commit Src Patch Blob Raw Tag Atom Diff Snapshot); my %VCS = (git => 'Git'); my %LOADED; @@ -93,7 +93,7 @@ sub call { } # URL syntax: / repo [ / cmd [ / head [ / path ] ] ] - # cmd: log | commit | diff | tree | view | blob | snapshot + # cmd: log | commit | diff | src | view | blob | snapshot # repo and path (@extra) may both contain '/' my $path_info = $env->{PATH_INFO}; my (undef, $repo_path, @extra) = split(m{/+}, $path_info, -1); diff --git a/t/repobrowse_git_src.t b/t/repobrowse_git_src.t new file mode 100644 index 00000000..4d16eac4 --- /dev/null +++ b/t/repobrowse_git_src.t @@ -0,0 +1,33 @@ +# Copyright (C) 2016 all contributors +# License: AGPL-3.0+ +use strict; +use warnings; +my $test = require './t/repobrowse_common_git.perl'; + +test_psgi($test->{app}, sub { + my ($cb) = @_; + + my $req = 'http://example.com/test.git/src/HEAD/dir'; + my $res = $cb->(GET($req)); + is(200, $res->code, 'got 200 response from dir'); + my $noslash_body = dechunk($res); + like($noslash_body, qr{href="dir/dur">dur/}, + 'path ok w/o slash'); + + my $slash = $req . '/'; + my $r2 = $cb->(GET($slash)); + is(301, $r2->code, 'got 301 response from dir with slash'); + is($req, $r2->header('Location'), 'redirected w/o slash'); + + $req = 'http://example.com/test.git/src/master/foo.txt'; + my $blob = $cb->(GET($req)); + is($blob->header('Content-Type'), 'text/html; charset=UTF-8', + 'got text/html blob'); + + my $body = dechunk($blob); + foreach (qw(----- hello world)) { + ok(index($body, $_) >= 0, "substring $_ in body"); + } +}); + +done_testing(); diff --git a/t/repobrowse_git_tree.t b/t/repobrowse_git_tree.t deleted file mode 100644 index d91cfdc9..00000000 --- a/t/repobrowse_git_tree.t +++ /dev/null @@ -1,33 +0,0 @@ -# Copyright (C) 2016 all contributors -# License: AGPL-3.0+ -use strict; -use warnings; -my $test = require './t/repobrowse_common_git.perl'; - -test_psgi($test->{app}, sub { - my ($cb) = @_; - - my $req = 'http://example.com/test.git/tree/HEAD/dir'; - my $res = $cb->(GET($req)); - is(200, $res->code, 'got 200 response from dir'); - my $noslash_body = dechunk($res); - like($noslash_body, qr{href="dir/dur">dur/}, - 'path ok w/o slash'); - - my $slash = $req . '/'; - my $r2 = $cb->(GET($slash)); - is(301, $r2->code, 'got 301 response from dir with slash'); - is($req, $r2->header('Location'), 'redirected w/o slash'); - - $req = 'http://example.com/test.git/tree/master/foo.txt'; - my $blob = $cb->(GET($req)); - is($blob->header('Content-Type'), 'text/html; charset=UTF-8', - 'got text/html blob'); - - my $body = dechunk($blob); - foreach (qw(----- hello world)) { - ok(index($body, $_) >= 0, "substring $_ in body"); - } -}); - -done_testing(); -- cgit v1.2.3-24-ge0c7