git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Narebski <jnareb@gmail.com>
To: git@vger.kernel.org
Cc: rajesh boyapati <boyapatisrajesh@gmail.com>,
	Junio C Hamano <gitster@pobox.com>,
	Jakub Narebski <jnareb@gmail.com>
Subject: [PATCHv2 1/3] gitweb: Deal with HEAD pointing to unborn branch in "heads" view
Date: Wed, 15 Feb 2012 16:36:41 +0100	[thread overview]
Message-ID: <1329320203-20272-2-git-send-email-jnareb@gmail.com> (raw)
In-Reply-To: <1329320203-20272-1-git-send-email-jnareb@gmail.com>

Gitweb has problems if HEAD points to an unborn branch, with no
commits on it yet, but there are other branches present (so it is not
newly initialized repository).

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.

This commit adds test and fixes the issue of being on unborn branch
(of HEAD not pointing to a commit) in "heads" view, and also in
"summary" view -- which includes "heads" excerpt as subview.

While at it rename local variable $head to $head_at, as it points to
current commit rather than current branch name (HEAD contents).

Includes simple test for 'summary' view and being on unborn branch.

Reported-by: rajesh boyapati <boyapatisrajesh@gmail.com>
Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
This patch first appeared on git mailing list in "Fwd: Git-web error"
as

  [PATCH] gitweb: Deal with HEAD pointing to unborn branch in "heads" view
  Message-Id: <201202032233.05324.jnareb@gmail.com>
  http://article.gmane.org/gmane.comp.version-control.git/189805

The $head -> $head_at change is not really necessary, but while we are
changing that area of code I felt it would be good to make it better.


What we should do in the future is rework git_heads_body to work with
symbolic references rather than mark branches that point to the same
commit as HEAD does.

That would also help in the "detached HEAD" case...

 gitweb/gitweb.perl                     |    4 ++--
 t/t9500-gitweb-standalone-no-errors.sh |    9 +++++++++
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 87a95e2..0fdca5b 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -5633,7 +5633,7 @@ sub git_tags_body {
 
 sub git_heads_body {
 	# uses global variable $project
-	my ($headlist, $head, $from, $to, $extra) = @_;
+	my ($headlist, $head_at, $from, $to, $extra) = @_;
 	$from = 0 unless defined $from;
 	$to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
 
@@ -5642,7 +5642,7 @@ sub git_heads_body {
 	for (my $i = $from; $i <= $to; $i++) {
 		my $entry = $headlist->[$i];
 		my %ref = %$entry;
-		my $curr = $ref{'id'} eq $head;
+		my $curr = defined $head_at && $ref{'id'} eq $head_at;
 		if ($alternate) {
 			print "<tr class=\"dark\">\n";
 		} else {
diff --git a/t/t9500-gitweb-standalone-no-errors.sh b/t/t9500-gitweb-standalone-no-errors.sh
index 0f771c6..81246a6 100755
--- a/t/t9500-gitweb-standalone-no-errors.sh
+++ b/t/t9500-gitweb-standalone-no-errors.sh
@@ -739,4 +739,13 @@ test_expect_success \
 	'echo "\$projects_list_group_categories = 1;" >>gitweb_config.perl &&
 	 gitweb_run'
 
+# ----------------------------------------------------------------------
+# unborn branches
+
+test_expect_success \
+	'unborn HEAD: "summary" page (with "heads" subview)' \
+	'git checkout orphan_branch || git checkout --orphan orphan_branch &&
+	 test_when_finished "git checkout master" &&
+	 gitweb_run "p=.git;a=summary"'
+
 test_done
-- 
1.7.9

  reply	other threads:[~2012-02-15 15:37 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-15 15:36 [PATCHv2 0/3] gitweb: Dealing with being on unborn branch Jakub Narebski
2012-02-15 15:36 ` Jakub Narebski [this message]
2012-02-16 20:29   ` [PATCHv2 1/3] gitweb: Deal with HEAD pointing to unborn branch in "heads" view Junio C Hamano
2012-02-16 22:41     ` Jakub Narebski
2012-02-16 23:28       ` Junio C Hamano
2012-02-17 13:41         ` Jakub Narebski
2012-02-17 14:28           ` Junio C Hamano
2012-02-15 15:36 ` [PATCHv2/RFC 2/3] gitweb: Harden parse_commit and parse_commits Jakub Narebski
2012-02-15 15:36 ` [RFC/PATCHv2 3/3] gitweb: Silence stderr in parse_commit*() subroutines Jakub Narebski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1329320203-20272-2-git-send-email-jnareb@gmail.com \
    --to=jnareb@gmail.com \
    --cc=boyapatisrajesh@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).