git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Add push --set-upstream

From
Jeff King <peff@peff.net>
Date
Jan 15, 2010, 17:42 UTC
Message-ID
<20100115174220.GA15821@coredump.intra.peff.net>
In-Reply-To
<20100115171745.GB2115@coredump.intra.peff.net>
On Fri, Jan 15, 2010 at 12:17:45PM -0500, Jeff King wrote:
> The patch below is squash-able, but note that the final test, "git push
> -u HEAD" is marked as broken. We should probably support that. I suspect
> is is an issue of dereferencing symrefs before doing the
> prefixcmp("refs/heads/", ...) but I haven't checked yet.

The patch below fixes it, but I am not 100% happy with it. Calling resolve_ref means we actually bother to look up the ref again, which is wasted effort. The ref struct has a "symref" field which should contain this information, but for some reason it is not recorded. So we can probably do better by simply recording the information properly when we resolve the ref in the first place.

Unfortunately, I don't have time to look at it anymore right now, so it will have to wait.

diff --git a/t/t5523-push-upstream.sh b/t/t5523-push-upstream.sh
index e977553..d43473f 100755
--- a/t/t5523-push-upstream.sh
+++ b/t/t5523-push-upstream.sh
@@ -39,7 +39,7 @@ test_expect_success 'push -u --all' '
 	check_config all2 upstream refs/heads/all2
 '
 
-test_expect_failure 'push -u HEAD' '
+test_expect_success 'push -u HEAD' '
 	git checkout -b headbranch &&
 	git push -u upstream HEAD &&
 	check_config headbranch upstream refs/heads/headbranch
diff --git a/transport.c b/transport.c
index 956d2ed..01ff364 100644
--- a/transport.c
+++ b/transport.c
@@ -140,6 +140,7 @@ static void set_upstreams(struct transport *trans, struct ref *refs)
 {
 	struct ref *i;
 	for (i = refs; i; i = i->next) {
+		const char *branch;
 		/*
 		 * Check suitability for tracking. Must be successful /
 		 * alreay up-to-date ref create/modify (not delete) and
@@ -152,14 +153,20 @@ static void set_upstreams(struct transport *trans, struct ref *refs)
 			continue;
 		if (!i->new_sha1 || is_null_sha1(i->new_sha1))
 			continue;
-		if (prefixcmp(i->peer_ref->name, "refs/heads/"))
-			continue;
 		if (prefixcmp(i->name, "refs/heads/"))
 			continue;
 
+		if (!prefixcmp(i->peer_ref->name, "refs/heads/"))
+			branch = i->peer_ref->name;
+		else {
+			unsigned char sha1[20];
+			branch = resolve_ref(i->peer_ref->name, sha1, 1, NULL);
+			if (!branch || prefixcmp(branch, "refs/heads/"))
+				continue;
+		}
+
 		install_branch_config(BRANCH_CONFIG_VERBOSE,
-			i->peer_ref->name + 11, trans->remote->name,
-			i->name);
+			branch + 11, trans->remote->name, i->name);
 	}
 }
 
Previous: Jeff KingNext: Ilari Liusvaara
Message 6 of 9 in “Add push --set-upstream”
  1. Add push --set-upstreamIlari Liusvaara, Jan 15, 2010
  2. Matthieu MoyJan 15, 2010
  3. Johannes SchindelinJan 15, 2010
  4. Junio C HamanoJan 15, 2010
  5. Jeff KingJan 15, 2010
  6. Jeff KingJan 15, 2010
  7. Ilari LiusvaaraJan 15, 2010
  8. Jeff KingJan 15, 2010
  9. Junio C HamanoJan 15, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.