Commit Diff


commit - 75236079c0b50ee24defebe1509f537bae91aefe
commit + f298ae0fb8ef2fb3645ac256d8e968d564be275e
blob - 88e00352743c1793902d7950c2ab3bdd10f581be
blob + b02072bccaf3d9b6fd8fbcc856402702d6307ba0
--- got/got.c
+++ got/got.c
@@ -885,13 +885,13 @@ fetch_progress(void *arg, const char *message, off_t p
 }
 
 static const struct got_error *
-create_head_ref(struct got_reference *target_ref, int verbosity,
-    struct got_repository *repo)
+create_symref(const char *refname, struct got_reference *target_ref,
+    int verbosity, struct got_repository *repo)
 {
 	const struct got_error *err;
 	struct got_reference *head_symref;
 
-	err = got_ref_alloc_symref(&head_symref, GOT_REF_HEAD, target_ref);
+	err = got_ref_alloc_symref(&head_symref, refname, target_ref);
 	if (err)
 		return err;
 
@@ -1243,6 +1243,7 @@ cmd_clone(int argc, char *argv[])
 			goto done;
 		}
 		error = create_ref(remote_refname, id, verbosity - 1, repo);
+		free(remote_refname);
 		if (error)
 			goto done;
 	}
@@ -1252,6 +1253,7 @@ cmd_clone(int argc, char *argv[])
 		struct got_reference *target_ref;
 		const char *refname = pe->path;
 		const char *target = pe->data;
+		char *remote_refname = NULL, *remote_target = NULL;
 
 		if (strcmp(refname, GOT_REF_HEAD) != 0)
 			continue;
@@ -1265,7 +1267,44 @@ cmd_clone(int argc, char *argv[])
 			goto done;
 		}
 
-		error = create_head_ref(target_ref, verbosity, repo);
+		error = create_symref(refname, target_ref, verbosity, repo);
+		got_ref_close(target_ref);
+		if (error)
+			goto done;
+
+		if (mirror_references)
+			continue;
+
+		if (strncmp("refs/heads/", target, 11) != 0)
+			continue;
+
+		if (asprintf(&remote_refname,
+		    "refs/remotes/%s/%s", GOT_FETCH_DEFAULT_REMOTE_NAME,
+		    refname) == -1) {
+			error = got_error_from_errno("asprintf");
+			goto done;
+		}
+		if (asprintf(&remote_target,
+		    "refs/remotes/%s/%s", GOT_FETCH_DEFAULT_REMOTE_NAME,
+		    target + 11) == -1) {
+			error = got_error_from_errno("asprintf");
+			free(remote_refname);
+			goto done;
+		}
+		error = got_ref_open(&target_ref, repo, remote_target, 0);
+		if (error) {
+			free(remote_refname);
+			free(remote_target);
+			if (error->code == GOT_ERR_NOT_REF) {
+				error = NULL;
+				continue;
+			}
+			goto done;
+		}
+		error = create_symref(remote_refname, target_ref,
+		    verbosity - 1, repo);
+		free(remote_refname);
+		free(remote_target);
 		got_ref_close(target_ref);
 		if (error)
 			goto done;
@@ -1289,7 +1328,8 @@ cmd_clone(int argc, char *argv[])
 				goto done;
 			}
 
-			error = create_head_ref(target_ref, verbosity, repo);
+			error = create_symref(GOT_REF_HEAD, target_ref,
+			    verbosity, repo);
 			got_ref_close(target_ref);
 			if (error)
 				goto done;
blob - 446d7b73e9428139a538555e3c55ae5786cb6eb8
blob + b188613f5c0ab1301b667f94dfbc18bea0f8512c
--- regress/cmdline/clone.sh
+++ regress/cmdline/clone.sh
@@ -76,6 +76,8 @@ function test_clone_basic {
 
 	echo "HEAD: refs/heads/master" > $testroot/stdout.expected
 	echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
+	echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
+		>> $testroot/stdout.expected
 	echo "refs/remotes/origin/master: $commit_id" \
 		>> $testroot/stdout.expected
 
@@ -175,6 +177,8 @@ function test_clone_all {
 	echo "HEAD: refs/heads/master" > $testroot/stdout.expected
 	echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
 	echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
+	echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
+		>> $testroot/stdout.expected
 	echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
 	echo "refs/remotes/origin/master: $commit_id" \
 		>> $testroot/stdout.expected
@@ -282,6 +286,8 @@ function test_clone_reference {
 
 	echo "HEAD: refs/heads/master" > $testroot/stdout.expected
 	echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
+	echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
+		>> $testroot/stdout.expected
 	echo "refs/remotes/origin/hoo/boo/zoo: $commit_id" \
 		>> $testroot/stdout.expected
 	echo "refs/remotes/origin/master: $commit_id" \
blob - fb811d10678197846f753b9591a2ea121483ebc1
blob + 404c994afe6baff215d08dc8f14a1f9437434dac
--- regress/cmdline/fetch.sh
+++ regress/cmdline/fetch.sh
@@ -106,6 +106,8 @@ function test_fetch_basic {
 
 	echo "HEAD: refs/heads/master" > $testroot/stdout.expected
 	echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
+	echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
+		>> $testroot/stdout.expected
 	echo "refs/remotes/origin/master: $commit_id2" \
 		>> $testroot/stdout.expected
 
@@ -205,6 +207,8 @@ function test_fetch_branch {
 	echo "HEAD: refs/heads/master" > $testroot/stdout.expected
 	echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
 	echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
+	echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
+		>> $testroot/stdout.expected
 	echo "refs/remotes/origin/foo: $commit_id3" >> $testroot/stdout.expected
 	# refs/remotes/origin/master is umodified because it wasn't fetched
 	echo "refs/remotes/origin/master: $commit_id" \
@@ -243,6 +247,8 @@ function test_fetch_branch {
 	echo "HEAD: refs/heads/master" > $testroot/stdout.expected
 	echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
 	echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
+	echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
+		>> $testroot/stdout.expected
 	echo "refs/remotes/origin/foo: $commit_id3" >> $testroot/stdout.expected
 	echo "refs/remotes/origin/master: $commit_id2" \
 		>> $testroot/stdout.expected
@@ -280,6 +286,8 @@ function test_fetch_all {
 
 	echo "HEAD: refs/heads/master" > $testroot/stdout.expected
 	echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
+	echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
+		>> $testroot/stdout.expected
 	echo "refs/remotes/origin/master: $commit_id" \
 		>> $testroot/stdout.expected
 	# refs/hoo/boo/zoo is missing because it is outside of refs/heads
@@ -305,6 +313,8 @@ function test_fetch_all {
 	echo "HEAD: refs/heads/master" > $testroot/stdout.expected
 	echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
 	echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
+	echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
+		>> $testroot/stdout.expected
 	echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
 	echo "refs/remotes/origin/master: $commit_id" \
 		>> $testroot/stdout.expected
@@ -343,6 +353,8 @@ function test_fetch_empty_packfile {
 
 	echo "HEAD: refs/heads/master" > $testroot/stdout.expected
 	echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
+	echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
+		>> $testroot/stdout.expected
 	echo "refs/remotes/origin/master: $commit_id" \
 		>> $testroot/stdout.expected
 	# refs/hoo/boo/zoo is missing because it is outside of refs/heads
@@ -369,6 +381,8 @@ function test_fetch_empty_packfile {
 	echo "HEAD: refs/heads/master" > $testroot/stdout.expected
 	echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
 	echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
+	echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
+		>> $testroot/stdout.expected
 	echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
 	echo "refs/remotes/origin/master: $commit_id" \
 		>> $testroot/stdout.expected
@@ -408,6 +422,8 @@ function test_fetch_delete_branch {
 	echo "HEAD: refs/heads/master" > $testroot/stdout.expected
 	echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
 	echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
+	echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
+		>> $testroot/stdout.expected
 	echo "refs/remotes/origin/foo: $commit_id" \
 		>> $testroot/stdout.expected
 	echo "refs/remotes/origin/master: $commit_id" \
@@ -438,6 +454,8 @@ function test_fetch_delete_branch {
 	echo "HEAD: refs/heads/master" > $testroot/stdout.expected
 	echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
 	echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
+	echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
+		>> $testroot/stdout.expected
 	echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
 	echo "refs/remotes/origin/master: $commit_id" \
 		>> $testroot/stdout.expected
@@ -475,6 +493,8 @@ function test_fetch_delete_branch {
 	echo "HEAD: refs/heads/master" > $testroot/stdout.expected
 	# refs/heads/foo is now deleted
 	echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
+	echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
+		>> $testroot/stdout.expected
 	echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
 	echo "refs/remotes/origin/master: $commit_id" \
 		>> $testroot/stdout.expected
@@ -524,6 +544,8 @@ function test_fetch_update_tag {
 	echo "HEAD: refs/heads/master" > $testroot/stdout.expected
 	echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
 	echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
+	echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
+		>> $testroot/stdout.expected
 	echo "refs/remotes/origin/foo: $commit_id" \
 		>> $testroot/stdout.expected
 	echo "refs/remotes/origin/master: $commit_id" \
@@ -552,6 +574,8 @@ function test_fetch_update_tag {
 	echo "HEAD: refs/heads/master" > $testroot/stdout.expected
 	echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
 	echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
+	echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
+		>> $testroot/stdout.expected
 	echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
 	echo "refs/remotes/origin/master: $commit_id2" \
 		>> $testroot/stdout.expected
@@ -591,6 +615,8 @@ function test_fetch_update_tag {
 	echo "HEAD: refs/heads/master" > $testroot/stdout.expected
 	echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
 	echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
+	echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
+		>> $testroot/stdout.expected
 	echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
 	echo "refs/remotes/origin/master: $commit_id2" \
 		>> $testroot/stdout.expected
@@ -628,6 +654,8 @@ function test_fetch_update_tag {
 	echo "HEAD: refs/heads/master" > $testroot/stdout.expected
 	echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
 	echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
+	echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
+		>> $testroot/stdout.expected
 	echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
 	echo "refs/remotes/origin/master: $commit_id2" \
 		>> $testroot/stdout.expected
@@ -713,6 +741,8 @@ function test_fetch_reference {
 
 	echo "HEAD: refs/heads/master" > $testroot/stdout.expected
 	echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
+	echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
+		>> $testroot/stdout.expected
 	echo "refs/remotes/origin/hoo/boo/zoo: $commit_id" \
 		>> $testroot/stdout.expected
 	echo "refs/remotes/origin/master: $commit_id2" \