Skip to content

Commit fd49e56

Browse files
jnarebgitster
authored andcommitted
gitweb: Fix "heads" view when there is no current branch
In a repository whose HEAD points to an unborn branch with no commits, "heads" view and "summary" view (which shows what is shown in "heads" view) compared the object names of commits at the tip of branches with the output from "git rev-parse HEAD", which caused comparison of a string with undef and resulted in a warning in the server log. This can happen if non-bare repository (with default 'master' branch) is updated not via committing but by other means like push to it, or Gerrit. It can happen also just after running "git checkout --orphan <new branch>" but before creating any new commit on this branch. Rewrite the comparison so that it also works when $head points at nothing; in such a case, no branch can be "the current branch", add a test for it. While at it, rename local variable $head to $head_at, as it points to current commit rather than current branch name (HEAD contents). The code still incorrectly shows all branches that point at the same commit as what HEAD points as "the current branch", even when HEAD is detached. Fixing this bug is outside the scope of this patch. Reported-by: Rajesh Boyapati Signed-off-by: Jakub Narebski <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 90020e3 commit fd49e56

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

gitweb/gitweb.perl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5568,7 +5568,7 @@ sub git_tags_body {
55685568

55695569
sub git_heads_body {
55705570
# uses global variable $project
5571-
my ($headlist, $head, $from, $to, $extra) = @_;
5571+
my ($headlist, $head_at, $from, $to, $extra) = @_;
55725572
$from = 0 unless defined $from;
55735573
$to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
55745574

@@ -5577,7 +5577,7 @@ sub git_heads_body {
55775577
for (my $i = $from; $i <= $to; $i++) {
55785578
my $entry = $headlist->[$i];
55795579
my %ref = %$entry;
5580-
my $curr = $ref{'id'} eq $head;
5580+
my $curr = defined $head_at && $ref{'id'} eq $head_at;
55815581
if ($alternate) {
55825582
print "<tr class=\"dark\">\n";
55835583
} else {

t/t9500-gitweb-standalone-no-errors.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,4 +731,13 @@ test_expect_success \
731731
'echo "\$projects_list_group_categories = 1;" >>gitweb_config.perl &&
732732
gitweb_run'
733733

734+
# ----------------------------------------------------------------------
735+
# unborn branches
736+
737+
test_expect_success \
738+
'unborn HEAD: "summary" page (with "heads" subview)' \
739+
'git checkout orphan_branch || git checkout --orphan orphan_branch &&
740+
test_when_finished "git checkout master" &&
741+
gitweb_run "p=.git;a=summary"'
742+
734743
test_done

0 commit comments

Comments
 (0)