git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Johannes Löthberg" <johannes@kyriasis.com>
To: git@vger.kernel.org
Cc: "Johannes Löthberg" <johannes@kyriasis.com>
Subject: [PATCH v4] receive-pack: Create a HEAD ref for ref namespace
Date: Fri,  5 Jun 2015 19:42:22 +0200	[thread overview]
Message-ID: <1433526142-2413-1-git-send-email-johannes@kyriasis.com> (raw)
In-Reply-To: <1433193883-11577-1-git-send-email-johannes@kyriasis.com>

Each ref namespace have their own separate branches, tags, and HEAD, so
when pushing to a namespace we need to make sure that there exists a
HEAD ref for the namespace, otherwise you will not be able to check out
the repo after cloning from a namespace

Signed-off-by: Johannes Löthberg <johannes@kyriasis.com>
---
Changes since v3:
  test:
    * Use a single printf statement
    * Check that the contents of the file and sha of the commits in the
      initial and cloned repositories matches

 builtin/receive-pack.c           | 12 +++++++++-
 t/t5509-fetch-push-namespaces.sh | 50 +++++++++++++++++++++++++++++++++++++++-
 2 files changed, 60 insertions(+), 2 deletions(-)

diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index d2ec52b..0c18c92 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -864,7 +864,9 @@ static const char *update(struct command *cmd, struct shallow_info *si)
 {
 	const char *name = cmd->ref_name;
 	struct strbuf namespaced_name_buf = STRBUF_INIT;
-	const char *namespaced_name, *ret;
+	struct strbuf namespaced_head_buf = STRBUF_INIT;
+	const char *namespaced_name, *ret, *namespace;
+	const char *namespaced_head_path;
 	unsigned char *old_sha1 = cmd->old_sha1;
 	unsigned char *new_sha1 = cmd->new_sha1;
 
@@ -981,6 +983,14 @@ static const char *update(struct command *cmd, struct shallow_info *si)
 		return NULL; /* good */
 	}
 	else {
+		namespace = get_git_namespace();
+		if (strcmp(namespace, "refs/namespaces/")) {
+			strbuf_addf(&namespaced_head_buf, "%s%s", namespace, "HEAD");
+			namespaced_head_path = strbuf_detach(&namespaced_head_buf, NULL);
+
+			create_symref(namespaced_head_path, namespaced_name, NULL);
+		}
+
 		struct strbuf err = STRBUF_INIT;
 		if (shallow_update && si->shallow_ref[cmd->index] &&
 		    update_shallow_ref(cmd, si))
diff --git a/t/t5509-fetch-push-namespaces.sh b/t/t5509-fetch-push-namespaces.sh
index cc0b31f..88c8aa9 100755
--- a/t/t5509-fetch-push-namespaces.sh
+++ b/t/t5509-fetch-push-namespaces.sh
@@ -1,6 +1,7 @@
 #!/bin/sh
 
-test_description='fetch/push involving ref namespaces'
+test_description='fetch/push/clone involving ref namespaces'
+
 . ./test-lib.sh
 
 test_expect_success setup '
@@ -82,4 +83,51 @@ test_expect_success 'mirroring a repository using a ref namespace' '
 	)
 '
 
+test_expect_success 'cloning from ref namespace' '
+	rm -rf initial bare clone &&
+	git init initial &&
+	git init --bare bare &&
+	(
+		cd initial &&
+		echo "commit one" >file &&
+		git add file &&
+		git commit -m "commit one" &&
+		git push ../bare master &&
+
+		echo refs/heads/master >expect &&
+		git -C ../bare symbolic-ref HEAD >actual &&
+		test_cmp expect actual &&
+
+		git rev-parse HEAD >expect &&
+		git -C ../bare rev-parse HEAD >actual &&
+		test_cmp expect actual &&
+
+		echo "commit two" >>file &&
+		git add file &&
+		git commit -m "commit two" &&
+		GIT_NAMESPACE=new_namespace git push ../bare master &&
+
+		echo "ref: refs/namespaces/new_namespace/refs/heads/master" >expect &&
+		test_cmp expect ../bare/refs/namespaces/new_namespace/HEAD &&
+
+		printf "%s commit\t%s\n" \
+		    $(git rev-parse master^) refs/heads/master \
+		    $(git rev-parse master) refs/namespaces/new_namespace/HEAD \
+		    $(git rev-parse master) refs/namespaces/new_namespace/refs/heads/master >expect &&
+		git -C ../bare for-each-ref refs/ >actual &&
+		test_cmp expect actual
+	) &&
+	GIT_NAMESPACE=new_namespace git clone bare clone &&
+	(
+		git -C initial cat-file blob master:file >expect &&
+		git -C clone cat-file blob master:file >actual &&
+		test_cmp expect actual &&
+
+		git -C initial rev-parse master >expect &&
+		git -C clone rev-parse master >actual &&
+		test_cmp expect actual
+	)
+'
+
+
 test_done
-- 
2.4.2

  parent reply	other threads:[~2015-06-05 17:42 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-01 21:24 [PATCH] receive-pack: Create a HEAD ref for ref namespace Johannes Löthberg
2015-06-05 11:53 ` Johannes Löthberg
2015-06-05 12:55   ` Michael J Gruber
2015-06-05 13:50     ` Johannes Löthberg
2015-06-05 14:10     ` Johannes Löthberg
2015-06-05 14:12 ` [PATCH v2] Fix cloning from " Johannes Löthberg
2015-06-05 14:12   ` [PATCH v2 1/2] receive-pack: Create a HEAD ref for " Johannes Löthberg
2015-06-05 14:12   ` [PATCH v2 2/2] t: Add test for cloning from " Johannes Löthberg
2015-06-05 15:33     ` Junio C Hamano
2015-06-05 16:12       ` Johannes Löthberg
2015-06-05 16:22         ` Junio C Hamano
2015-06-05 16:31           ` Johannes Löthberg
2015-06-05 16:25         ` Johannes Löthberg
2015-06-05 16:46           ` Junio C Hamano
2015-06-05 17:02 ` [PATCH v3] receive-pack: Create a HEAD ref for " Johannes Löthberg
2015-06-05 17:08   ` Johannes Löthberg
2015-06-05 17:19   ` Junio C Hamano
2015-06-05 17:27     ` Johannes Löthberg
2015-06-05 17:42 ` Johannes Löthberg [this message]
2015-06-10 23:39   ` [PATCH v4] " Johannes Löthberg
2015-06-15 20:48   ` Junio C Hamano
2015-06-15 20:59     ` Johannes Löthberg

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=1433526142-2413-1-git-send-email-johannes@kyriasis.com \
    --to=johannes@kyriasis.com \
    --cc=git@vger.kernel.org \
    /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).