# Does cloning a shallow repo require special setting in the cloned one?

8 messages from 2009-02-26 to 2009-02-27. Participants: roylee17, Teemu Likonen, Roy Lee, Jeff King, Johannes Schindelin, Jakub Narebski.
Thread: https://gitlist.dev/t/18025

## roylee17, 2009-02-26 03:49

Subject: Does cloning a shallow repo require special setting in the cloned one?
Message-ID: <1235620146513-2387799.post@n2.nabble.com>
URL: https://gitlist.dev/e/1235620146513-2387799.post%40n2.nabble.com

```

Hi,

I have a question about cloning shallow repo.

$ git clone --depth 1 git://git2.kernel.org/pub/scm/git/git.git git-shallow
ok, 'git log' gives a 2-revision history.

$ git clone git://git2.kernel.org/pub/scm/git/git.git git-full
'git log' gives a full history

$ git clone --depth 1 git-full git-shallow2
'git log' still gives a full history

Why can't I clone a shallow repo from the git-full?
Does it requires some settings in the git-full repo?

Regards,
Roy
Roy
-- 
View this message in context: http://n2.nabble.com/Does-cloning-a-shallow-repo-require-special-setting-in-the-cloned-one--tp2387799p2387799.html
Sent from the git mailing list archive at Nabble.com.

```

## Teemu Likonen, 2009-02-26 06:34

Subject: Re: Does cloning a shallow repo require special setting in the cloned one?
Message-ID: <87tz6hn1tg.fsf@iki.fi>
URL: https://gitlist.dev/e/87tz6hn1tg.fsf%40iki.fi
In-Reply-To: <1235620146513-2387799.post@n2.nabble.com>

```
On 2009-02-25 19:49 (-0800), roylee17 wrote:

> $ git clone --depth 1 git-full git-shallow2
> 'git log' still gives a full history
>
> Why can't I clone a shallow repo from the git-full?
> Does it requires some settings in the git-full repo?

I don't know the "why" part but using file:// URL should work:

    git clone --depth 1 file:///path/to/git-full git-shallow2

```

## Roy Lee, 2009-02-26 07:33

Subject: Re: Does cloning a shallow repo require special setting in the cloned one?
Message-ID: <6eac7f470902252333x6326419bq305da3436cff3aa7@mail.gmail.com>
URL: https://gitlist.dev/e/6eac7f470902252333x6326419bq305da3436cff3aa7%40mail.gmail.com
In-Reply-To: <87tz6hn1tg.fsf@iki.fi>

```
On Thu, Feb 26, 2009 at 2:34 PM, Teemu Likonen <tlikonen@iki.fi> wrote:
> On 2009-02-25 19:49 (-0800), roylee17 wrote:
>
>> $ git clone --depth 1 git-full git-shallow2
>> 'git log' still gives a full history
>>
>> Why can't I clone a shallow repo from the git-full?
>> Does it requires some settings in the git-full repo?
>
> I don't know the "why" part but using file:// URL should work:
>
>    git clone --depth 1 file:///path/to/git-full git-shallow2
>

Thanks, Teemu. file:///path/to/git-full works.

```

## Jeff King, 2009-02-26 10:46

Subject: Re: Does cloning a shallow repo require special setting in the cloned one?
Message-ID: <20090226104657.GB4226@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20090226104657.GB4226%40coredump.intra.peff.net
In-Reply-To: <87tz6hn1tg.fsf@iki.fi>

```
On Thu, Feb 26, 2009 at 08:34:51AM +0200, Teemu Likonen wrote:

> On 2009-02-25 19:49 (-0800), roylee17 wrote:
> 
> > $ git clone --depth 1 git-full git-shallow2
> > 'git log' still gives a full history
> >
> > Why can't I clone a shallow repo from the git-full?
> > Does it requires some settings in the git-full repo?
> 
> I don't know the "why" part but using file:// URL should work:
> 
>     git clone --depth 1 file:///path/to/git-full git-shallow2

I don't think the behavior is intentional, but a side effect of the
fact that git takes some shortcuts when cloning locally. In particular,
it will try to copy or hardlink the object database rather than
transmitting over the git protocol locally. Using file:// has always
been the way to suppress that shortcut.

Perhaps to avoid surprise, that optimization should be turned off for
options which cause it to behave differently (like --depth). But I have
to wonder what the point of --depth is locally; if you are worried about
space, hardlinks (the default) or alternates ("clone -s") are a better
solution.

-Peff

```

## Johannes Schindelin, 2009-02-26 11:17

Subject: Re: Does cloning a shallow repo require special setting in the cloned one?
Message-ID: <alpine.DEB.1.00.0902261216110.6258@intel-tinevez-2-302>
URL: https://gitlist.dev/e/alpine.DEB.1.00.0902261216110.6258%40intel-tinevez-2-302
In-Reply-To: <20090226104657.GB4226@coredump.intra.peff.net>

```
Hi,

On Thu, 26 Feb 2009, Jeff King wrote:

> On Thu, Feb 26, 2009 at 08:34:51AM +0200, Teemu Likonen wrote:
> 
> > On 2009-02-25 19:49 (-0800), roylee17 wrote:
> > 
> > > $ git clone --depth 1 git-full git-shallow2
> > > 'git log' still gives a full history
> > >
> > > Why can't I clone a shallow repo from the git-full?
> > > Does it requires some settings in the git-full repo?
> > 
> > I don't know the "why" part but using file:// URL should work:
> > 
> >     git clone --depth 1 file:///path/to/git-full git-shallow2
> 
> I don't think the behavior is intentional, but a side effect of the
> fact that git takes some shortcuts when cloning locally. In particular,
> it will try to copy or hardlink the object database rather than
> transmitting over the git protocol locally. Using file:// has always
> been the way to suppress that shortcut.
> 
> Perhaps to avoid surprise, that optimization should be turned off for
> options which cause it to behave differently (like --depth). But I have
> to wonder what the point of --depth is locally; if you are worried about
> space, hardlinks (the default) or alternates ("clone -s") are a better
> solution.

I think it is way better to warn, since "--depth" is usually passed out of 
concerns about disk space.  And --shared should shut that concern up 
rather nicely.

diff --git a/builtin-clone.c b/builtin-clone.c
index c338910..5831034 100644
--- a/builtin-clone.c
+++ b/builtin-clone.c
@@ -511,8 +511,11 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 	refspec.src = src_ref_prefix;
 	refspec.dst = branch_top.buf;
 
-	if (path && !is_bundle)
+	if (path && !is_bundle) {
+		if (option_depth)
+			warning("Ignoring --depth for local clone");
 		refs = clone_local(path, git_dir);
+	}
 	else {
 		struct remote *remote = remote_get(argv[0]);
 		transport = transport_get(remote, remote->url[0]);

Lacks tests,
Dscho

```

## Roy Lee, 2009-02-26 13:01

Subject: Re: Does cloning a shallow repo require special setting in the cloned one?
Message-ID: <6eac7f470902260501v6d826af7rbc5afd1df7b214a3@mail.gmail.com>
URL: https://gitlist.dev/e/6eac7f470902260501v6d826af7rbc5afd1df7b214a3%40mail.gmail.com
In-Reply-To: <20090226104657.GB4226@coredump.intra.peff.net>

```
On Thu, Feb 26, 2009 at 6:46 PM, Jeff King <peff@peff.net> wrote:
> On Thu, Feb 26, 2009 at 08:34:51AM +0200, Teemu Likonen wrote:
>
>> On 2009-02-25 19:49 (-0800), roylee17 wrote:
>>
>> > $ git clone --depth 1 git-full git-shallow2
>> > 'git log' still gives a full history
>> >
>> > Why can't I clone a shallow repo from the git-full?
>> > Does it requires some settings in the git-full repo?
>>
>> I don't know the "why" part but using file:// URL should work:
>>
>>     git clone --depth 1 file:///path/to/git-full git-shallow2
>
> I don't think the behavior is intentional, but a side effect of the
> fact that git takes some shortcuts when cloning locally. In particular,
> it will try to copy or hardlink the object database rather than
> transmitting over the git protocol locally. Using file:// has always
> been the way to suppress that shortcut.
>
> Perhaps to avoid surprise, that optimization should be turned off for
> options which cause it to behave differently (like --depth). But I have
> to wonder what the point of --depth is locally; if you are worried about
> space, hardlinks (the default) or alternates ("clone -s") are a better
> solution.
>
> -Peff
>

Actully, the original intention was to find a quick way to checkout and
build several projects regularly. The first thing came to me was cloning
shallow repos for saving some time. So I tried it with my local repo first.

Later, one of my co-works suggested me to try git archive, and that did
reallly fit my needs.

Thanks for clarifying my confusion.

Roy

```

## Jeff King, 2009-02-26 13:19

Subject: Re: Does cloning a shallow repo require special setting in the cloned one?
Message-ID: <20090226131946.GC7911@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20090226131946.GC7911%40coredump.intra.peff.net
In-Reply-To: <alpine.DEB.1.00.0902261216110.6258@intel-tinevez-2-302>

```
On Thu, Feb 26, 2009 at 12:17:36PM +0100, Johannes Schindelin wrote:

> I think it is way better to warn, since "--depth" is usually passed out of 
> concerns about disk space.  And --shared should shut that concern up 
> rather nicely.
> 
> diff --git a/builtin-clone.c b/builtin-clone.c
> index c338910..5831034 100644
> --- a/builtin-clone.c
> +++ b/builtin-clone.c
> @@ -511,8 +511,11 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
>  	refspec.src = src_ref_prefix;
>  	refspec.dst = branch_top.buf;
>  
> -	if (path && !is_bundle)
> +	if (path && !is_bundle) {
> +		if (option_depth)
> +			warning("Ignoring --depth for local clone");
>  		refs = clone_local(path, git_dir);
> +	}
>  	else {
>  		struct remote *remote = remote_get(argv[0]);
>  		transport = transport_get(remote, remote->url[0]);

That seems reasonable to me.

-Peff

```

## Jakub Narebski, 2009-02-27 00:42

Subject: Re: Does cloning a shallow repo require special setting in the cloned one?
Message-ID: <m3prh4vhdg.fsf@localhost.localdomain>
URL: https://gitlist.dev/e/m3prh4vhdg.fsf%40localhost.localdomain
In-Reply-To: <6eac7f470902260501v6d826af7rbc5afd1df7b214a3@mail.gmail.com>

```
Roy Lee <roylee17@gmail.com> writes:
> On Thu, Feb 26, 2009 at 6:46 PM, Jeff King <peff@peff.net> wrote:
>> On Thu, Feb 26, 2009 at 08:34:51AM +0200, Teemu Likonen wrote:
>>> On 2009-02-25 19:49 (-0800), roylee17 wrote:
>>>
>>>> $ git clone --depth 1 git-full git-shallow2
>>>> 'git log' still gives a full history
>>>>
>>>> Why can't I clone a shallow repo from the git-full?
>>>> Does it requires some settings in the git-full repo?
>>>
>>> I don't know the "why" part but using file:// URL should work:
>>>
>>>     git clone --depth 1 file:///path/to/git-full git-shallow2
>>
>> I don't think the behavior is intentional, but a side effect of the
>> fact that git takes some shortcuts when cloning locally. In particular,
>> it will try to copy or hardlink the object database rather than
>> transmitting over the git protocol locally. Using file:// has always
>> been the way to suppress that shortcut.
>>
>> Perhaps to avoid surprise, that optimization should be turned off for
>> options which cause it to behave differently (like --depth). But I have
>> to wonder what the point of --depth is locally; if you are worried about
>> space, hardlinks (the default) or alternates ("clone -s") are a better
>> solution.
> 
> Actully, the original intention was to find a quick way to checkout and
> build several projects regularly. The first thing came to me was cloning
> shallow repos for saving some time. So I tried it with my local repo first.
> 
> Later, one of my co-works suggested me to try git archive, and that did
> reallly fit my needs.

Perhaps you would be interested then in contrib/workdir/git-new-workdir
script then, which allows for multiple checked out copies from a single
repository?  Be aware that if you work in those copies, and are not
careful, it can lead to confusion; but if all but one of checkouts are
read only it could be the best solution.

-- 
Jakub Narebski
Poland
ShadeHawk on #git

```
