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

Re: What's cooking in git.git (Jan 2009, #07; Wed, 28)

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 12, 2009, 06:42 UTC
Message-ID
<7v3aekqhpo.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<7vr62j0wpc.fsf@gitster.siamese.dyndns.org>
Junio C Hamano <gitster@pobox.com> writes:
Show 14 quoted lines
> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
>
>> How about installing
>>
>> 	[branch "master"]
>> 		remote = origin
>> 		merge = refs/heads/master
>>
>> by default?  It is a safe bet that this will be the case for 99% of all 
>> users that want to clone an empty repository (especially if they are 
>> putting their public repositories on something like repo.or.cz, where you 
>> cannot change the default branch from "master" to something else).
>
> I think this is a reasonable thing to do.

So I've been sort of waiting for a trivial patch to materialize, and then almost forgot about it like everybody else did. Before all of us forget, here is my attempt to do the above.

We seem to have acquired a bad habit of discussing and agreeing on a potential improvement and then not following through, forgetting it altogether.

Exciting new features we can count on original submitters to stick to them and push them forward whether we go into a release freeze, but the more boring kind of patches that we already know what we want to see by the next release are actually the more important to the overall project; sadly, they tend to get lost somewhere in the crack. I wonder if we can do anything about it.

And no, a bug tracker is not the answer, even though it could be a (small) part of the solution.

-- >8 --
Subject: Install the default "master" branch configuration after cloning a void

After "cloning from an empty repository", we have a configuration to describe the remote's URL and the default ref mappings, but we lack the branch configuration for the default branch we create on our end, "master".

It is likely that the empty repository we cloned from will point the default "master" branch with its HEAD, so prepare the local configuration to match.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 builtin-clone.c |   22 +++++++++++++++++-----
 1 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/builtin-clone.c b/builtin-clone.c
index f73029e..431c136 100644
--- a/builtin-clone.c
+++ b/builtin-clone.c
@@ -350,6 +350,18 @@ static struct ref *write_remote_refs(const struct ref *refs,
 	return local_refs;
 }
 
+static void install_branch_config(const char *origin, const char *local,
+				  const char *remote)
+{
+	struct strbuf key = STRBUF_INIT;
+	strbuf_addf(&key, "branch.%s.remote", local);
+	git_config_set(key.buf, origin);
+	strbuf_reset(&key);
+	strbuf_addf(&key, "branch.%s.merge", local);
+	git_config_set(key.buf, remote);
+	strbuf_release(&key);
+}
+
 int cmd_clone(int argc, const char **argv, const char *prefix)
 {
 	int use_local_hardlinks = 1;
@@ -539,6 +551,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 		head_points_at = NULL;
 		remote_head = NULL;
 		option_no_checkout = 1;
+		if (!option_bare)
+			install_branch_config(option_origin, "master",
+					      "refs/heads/master");
 	}
 
 	if (head_points_at) {
@@ -567,11 +582,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 				      head_points_at->peer_ref->name,
 				      reflog_msg.buf);
 
-			strbuf_addf(&key, "branch.%s.remote", head);
-			git_config_set(key.buf, option_origin);
-			strbuf_reset(&key);
-			strbuf_addf(&key, "branch.%s.merge", head);
-			git_config_set(key.buf, head_points_at->name);
+			install_branch_config(option_origin, head,
+					      head_points_at->name);
 		}
 	} else if (remote_head) {
 		/* Source had detached HEAD pointing somewhere. */
Previous: Junio C HamanoNext: Sverre Rabbelier
Message 16 of 30 in “What's cooking in git.git (Jan 2009, #07; Wed, 28)”
  1. Junio C HamanoJan 29, 2009
  2. Jeff KingJan 29, 2009
  3. Jeff KingJan 29, 2009
  4. Jeff KingJan 29, 2009
  5. Junio C HamanoJan 29, 2009
  6. Sverre RabbelierJan 29, 2009
  7. Jeff KingJan 29, 2009
  8. Pieter de BieJan 29, 2009
  9. Sverre RabbelierJan 29, 2009
  10. Jeff KingJan 29, 2009
  11. Sverre RabbelierJan 29, 2009
  12. Jeff KingJan 30, 2009
  13. Johannes SchindelinJan 30, 2009
  14. Jeff KingJan 30, 2009
  15. Junio C HamanoFeb 1, 2009
  16. Junio C HamanoFeb 12, 2009
  17. Sverre RabbelierFeb 12, 2009
  18. Johannes SchindelinFeb 12, 2009
  19. Junio C HamanoFeb 12, 2009
  20. Johannes SchindelinFeb 12, 2009
  21. Jeff KingFeb 12, 2009
  22. Jeff KingJan 29, 2009
  23. Nico -telmich- SchotteliusJan 29, 2009
  24. Jeff KingJan 30, 2009
  25. Charles BaileyJan 29, 2009
  26. Junio C HamanoJan 29, 2009
  27. Charles BaileyJan 29, 2009
  28. Charles BaileyJan 30, 2009
  29. Kirill SmelkovFeb 1, 2009
  30. Junio C HamanoFeb 1, 2009

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.