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

Re: cannot clone --single-commit instead of --single-branch

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Aug 2, 2019, 02:57 UTC
Message-ID
<20190802025728.GD54514@google.com>
In-Reply-To
<CA+KyZp6mYx4C22syAu=W2Okf7tDwtQ+7vVUBaQ-2D70PTS+GaA@mail.gmail.com>

(cc: Duy, who might enjoy this walk through history) Hi,

Alexander Mills wrote:
> git clone --single-branch=<sha>
>
> doesn't seem to work?

I've occasionally wanted something like this (actually, I've wanted to pass a refname like "refs/meta/config"). builtin/clone.c contains

	static struct ref *find_remote_branch(const struct ref *refs, const char *branch)
	{
		struct ref *ref;
		struct strbuf head = STRBUF_INIT;
		strbuf_addstr(&head, "refs/heads/");
		strbuf_addstr(&head, branch);
		ref = find_ref_by_name(refs, head.buf);
		strbuf_release(&head);
		if (ref)
			return ref;
So far, what one would expect.
		strbuf_addstr(&head, "refs/tags/");
		strbuf_addstr(&head, branch);
		ref = find_ref_by_name(refs, head.buf);
		strbuf_release(&head);

Wait a second: a tag isn't a branch, so why do we accept it as a value for --branch? So this is stretching definitions a little already.

"git log -L:find_remote_branch:builtin/clone.c" tells me this is from v1.7.10-rc0~125^2~3 (clone: allow --branch to take a tag, 2012-01-16):

	Because a tag ref cannot be put to HEAD, HEAD will become detached.
	This is consistent with "git checkout <tag>".

I think ideally we could first check for a sha1 and then try the full set of patterns from ref_rev_parse_rules. What do you think? Would you be interested in taking a stab at it?

Thanks, Jonathan

Previous: Mike Hommey
Message 5 of 5 in “cannot clone --single-commit instead of --single-branch”
  1. Alexander MillsAug 1, 2019
  2. Bryan TurnerAug 1, 2019
  3. Jonathan NiederAug 2, 2019
  4. Mike HommeyAug 2, 2019
  5. Jonathan NiederAug 2, 2019

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.