* Re: cannot clone --single-commit instead of --single-branch
2019-08-01 20:52 cannot clone --single-commit instead of --single-branch Alexander Mills
@ 2019-08-01 22:40 ` Bryan Turner
2019-08-02 2:43 ` Jonathan Nieder
2019-08-02 2:57 ` Jonathan Nieder
1 sibling, 1 reply; 5+ messages in thread
From: Bryan Turner @ 2019-08-01 22:40 UTC (permalink / raw)
To: Alexander Mills; +Cc: Git Users
On Thu, Aug 1, 2019 at 1:52 PM Alexander Mills
<alexander.d.mills@gmail.com> wrote:
>
> Looking for help with this problem:
>
> https://stackoverflow.com/questions/57316783/git-clone-single-branch-does-not-work-for-sha-commit-ids
>
> Essentially looking for:
>
> git clone --single-commit
There's no such option, which will be why it doesn't work. I suspect
the closest feature is a shallow clone, performed using git clone
--depth=1. That's still not going to allow passing an arbitrary SHA-1,
though; it'll only support a branch name, the same as --single-branch,
which --depth implies (unless --no-single-branch is specified, at
which point it fetches the depth for all branches).
Promisor remotes and other in-flight changes might help provide some
of what you're looking for, but I'm not aware of any already-available
solution. Perhaps something like VFS for Git, if whatever hosting
solution you're using supports it.
Hope this helps!
Bryan
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: cannot clone --single-commit instead of --single-branch
2019-08-01 20:52 cannot clone --single-commit instead of --single-branch Alexander Mills
2019-08-01 22:40 ` Bryan Turner
@ 2019-08-02 2:57 ` Jonathan Nieder
1 sibling, 0 replies; 5+ messages in thread
From: Jonathan Nieder @ 2019-08-02 2:57 UTC (permalink / raw)
To: Alexander Mills; +Cc: git, Nguyễn Thái Ngọc Duy, Bryan Turner
(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
^ permalink raw reply [flat|nested] 5+ messages in thread