Skip to contentSkip to conversation

git-clone.txt: remove the restriction on pushing from a shallow clone

PATCH In review Nguyễn Thái Ngọc Duy 3 participants 11 messages Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 git-clone.txt: remove the restriction on pushing from a shallow clone

The document says one cannot push from a shallow clone. But that is not true (maybe it was at some point in the past). The client does not stop such a push nor does it give any indication to the receiver that this is a shallow push. If the receiver accepts it, it's in.

Since 52fed6e (receive-pack: check connectivity before concluding "git push" - 2011-09-02), receive-pack is prepared to deal with broken push, a shallow push can't cause any corruption. Update the document to reflect that.

---
 Documentation/git-clone.txt | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
Documentation/git-clone.txt +7 -5
index 450f158..85769b8 100644
@@ -182,11 +182,13 @@ objects from the source repository into a pack in the cloned repository.
 --depth <depth>::
 	Create a 'shallow' clone with a history truncated to the
 	specified number of revisions.  A shallow repository has a
-	number of limitations (you cannot clone or fetch from
-	it, nor push from nor into it), but is adequate if you
-	are only interested in the recent history of a large project
-	with a long history, and would want to send in fixes
-	as patches.
+	number of limitations (you cannot clone or fetch from it, nor
+	push into it), but is adequate if you are only interested in
+	the recent history of a large project with a long history.
++
+Pushing from a shallow clone should be avoided if the git version on
+the receiver end is older than v1.7.10, or any other git
+implementation that does not perform connectivity check.
 
 --[no-]single-branch::
 	Clone only the history leading to the tip of a single branch,
Signature · 1 line
1.8.2.82.gc24b958
#1 lore raw
Quoted 9 lines · Nguyễn Thái Ngọc Duy

The document says one cannot push from a shallow clone. But that is not true (maybe it was at some point in the past). The client does not stop such a push nor does it give any indication to the receiver that this is a shallow push. If the receiver accepts it, it's in.

Since 52fed6e (receive-pack: check connectivity before concluding "git push" - 2011-09-02), receive-pack is prepared to deal with broken push, a shallow push can't cause any corruption. Update the document to reflect that.

Err, what are these lines in builtin/receive-pack.c doing, then?

        int cmd_receive_pack(int argc, const char **argv, const char *prefix)
        {
                ...
                setup_path();

                if (!enter_repo(dir, 0))
                        die("'%s' does not appear to be a git repository", dir);

                if (is_repository_shallow())
                        die("attempt to push into a shallow repository");
                ...
#2 lore raw
In reply to Nguyễn Thái Ngọc Duy

Documentation/git-clone.txt objects from the source repository into a pack in the cloned repository. · line 187

Quoted 3 lines · Nguyễn Thái Ngọc Duy
Documentation/git-clone.txt +3 -0
+	number of limitations (you cannot clone or fetch from it, nor
+	push into it), but is adequate if you are only interested in
+	the recent history of a large project with a long history.

Ahh, sorry for the noise. You still say you cannot push _into_ it.

author
#3 lore raw
Quoted 7 lines · Junio C Hamano

Documentation/git-clone.txt objects from the source repository into a pack in the cloned repository. · line 187

Quoted 3 lines · Nguyễn Thái Ngọc Duy
Documentation/git-clone.txt +3 -0
+     number of limitations (you cannot clone or fetch from it, nor
+     push into it), but is adequate if you are only interested in
+     the recent history of a large project with a long history.

Ahh, sorry for the noise. You still say you cannot push _into_ it.

Yes, I actually removed that check in the first iteration of this patch, reasoning that it can't cause any harm and it mostly works. But "mostly" is not good enough. I will try remove it later if I can make it always work by extending git protocol a bit (I think full clone pushing to shallow one can always work. Shallow pushing to shallow, probably no such guarantee)
--
Duy

Reviewed-by on v1 1/1
#4 lore raw
In reply to Nguyễn Thái Ngọc Duy

Hi,

Quoted 4 lines · Nguyễn Thái Ngọc Duy

Since 52fed6e (receive-pack: check connectivity before concluding "git push" - 2011-09-02), receive-pack is prepared to deal with broken push, a shallow push can't cause any corruption. Update the document to reflect that.

Hmm, what happens when pushing to servers without that commit? Do you think it should be applied to Debian squeeze for server operators that haven't upgraded yet to the current stable release?

[...]

Quoted 8 lines
Documentation/git-clone.txt +0 -2
@@ -182,11 +182,13 @@ objects from the source repository into a pack in the cloned repository.
 --depth <depth>::
 	Create a 'shallow' clone with a history truncated to the
 	specified number of revisions.  A shallow repository has a
-	number of limitations (you cannot clone or fetch from
-	it, nor push from nor into it), but is adequate if you

Documentation/git-clone.txt objects from the source repository into a pack in the cloned repository. · line 191

Quoted 10 lines
Documentation/git-clone.txt +7 -3
-	are only interested in the recent history of a large project
-	with a long history, and would want to send in fixes
-	as patches.
+	number of limitations (you cannot clone or fetch from it, nor
+	push into it), but is adequate if you are only interested in
+	the recent history of a large project with a long history.
++
+Pushing from a shallow clone should be avoided if the git version on
+the receiver end is older than v1.7.10, or any other git
+implementation that does not perform connectivity check.

"git name-rev --tags" tells me 52fed6e was applied during 1.7.8-rc0, so it might make sense to s/1.7.10/1.7.8/ here.

Aside from that nit,

Thanks,
Jonathan

author
#5 lore raw
Quoted 4 lines · Jonathan Nieder

Hi,

Nguyễn Thái Ngọc Duy wrote:

Quoted 8 lines
Quoted 4 lines

Since 52fed6e (receive-pack: check connectivity before concluding "git push" - 2011-09-02), receive-pack is prepared to deal with broken push, a shallow push can't cause any corruption. Update the document to reflect that.

Hmm, what happens when pushing to servers without that commit? Do you think it should be applied to Debian squeeze for server operators that haven't upgraded yet to the current stable release?

This is pushing _from_ a shallow repo, where the sender repo's old objects is a subset of the receiver's. Such a push may be safe even without the above commit, if I don't miss anything. The commit is in case I do miss something.

The situation is different when we push _to_ a shallow repo. The sender in this case may have more old objects than the receiver. The sender may choose to not send such old objects in the push, not knowing that the receiver does not have them due to its shallow nature. So incomplete push and could only be caught be the commit above.

I don't know about Debian porting strategy, but I think that commit should be back ported to the stable release. There are more git clients out there than just C Git and some of them may have bugs. The commit should help protect the server against buggy clients. If you back port it, do d21c463 (fetch/receive: remove over-pessimistic connectivity check - 2012-03-15) too to avoid performance regression in large pushes/fetches.

Quoted 15 lines

[...]

Quoted 13 lines
Documentation/git-clone.txt +2 -5
@@ -182,11 +182,13 @@ objects from the source repository into a pack in the cloned repository.
 --depth <depth>::
      Create a 'shallow' clone with a history truncated to the
      specified number of revisions.  A shallow repository has a
-     number of limitations (you cannot clone or fetch from
-     it, nor push from nor into it), but is adequate if you
-     are only interested in the recent history of a large project
-     with a long history, and would want to send in fixes
-     as patches.
+     number of limitations (you cannot clone or fetch from it, nor
+     push into it), but is adequate if you are only interested in
Quoted 8 lines

Documentation/git-clone.txt objects from the source repository into a pack in the cloned repository. · line 191

Quoted 5 lines
Documentation/git-clone.txt +5 -0
+     the recent history of a large project with a long history.
++
+Pushing from a shallow clone should be avoided if the git version on
+the receiver end is older than v1.7.10, or any other git
+implementation that does not perform connectivity check.

"git name-rev --tags" tells me 52fed6e was applied during 1.7.8-rc0, so it might make sense to s/1.7.10/1.7.8/ here.

Yeah! I thought "git tag --contains" output was sorted and did not read past the first few tags. Need to implement version sort for --tags, or at least commit date sort..

Quoted 5 lines

Aside from that nit,

Thanks,
Jonathan

--
Duy

#6 lore raw
Quoted 10 lines · Duy Nguyen
Quoted 9 lines · Jonathan Nieder

Hi,

Quoted 4 lines · Nguyễn Thái Ngọc Duy

Since 52fed6e (receive-pack: check connectivity before concluding "git push" - 2011-09-02), receive-pack is prepared to deal with broken push, a shallow push can't cause any corruption. Update the document to reflect that.

Quoted 6 lines
Quoted 3 lines

Hmm, what happens when pushing to servers without that commit? Do you think it should be applied to Debian squeeze for server operators that haven't upgraded yet to the current stable release?

This is pushing _from_ a shallow repo, where the sender repo's old objects is a subset of the receiver's.

The "subset" assumption does not necessarily hold, does it? The receiver may have rewound its tips and pruned since then.

Also, the sender may have cloned from the receiver (fully) and then fetched a different history shallowly from elsewhere. The receiver may have no commit on that history, including the shallow-bottom.

author
#7 lore raw
Quoted 19 lines · Junio C Hamano
Quoted 10 lines · Duy Nguyen
Quoted 9 lines · Jonathan Nieder

Hi,

Quoted 4 lines · Nguyễn Thái Ngọc Duy

Since 52fed6e (receive-pack: check connectivity before concluding "git push" - 2011-09-02), receive-pack is prepared to deal with broken push, a shallow push can't cause any corruption. Update the document to reflect that.

Quoted 6 lines
Quoted 3 lines

Hmm, what happens when pushing to servers without that commit? Do you think it should be applied to Debian squeeze for server operators that haven't upgraded yet to the current stable release?

This is pushing _from_ a shallow repo, where the sender repo's old objects is a subset of the receiver's.

Quoted 7 lines

The "subset" assumption does not necessarily hold, does it? The receiver may have rewound its tips and pruned since then.

Also, the sender may have cloned from the receiver (fully) and then fetched a different history shallowly from elsewhere. The receiver may have no commit on that history, including the shallow-bottom.

Hmm.. right. And the receiver needs to setup proper graft to seal the shallow bottom. So it's really not safe to do pushing from a shallow repo without 52fed6e
--
Duy

author
#8 lore raw
Quoted 8 lines · Duy Nguyen
Quoted 4 lines

Also, the sender may have cloned from the receiver (fully) and then fetched a different history shallowly from elsewhere. The receiver may have no commit on that history, including the shallow-bottom.

Hmm.. right. And the receiver needs to setup proper graft to seal the shallow bottom. So it's really not safe to do pushing from a shallow repo without 52fed6e

Because this makes pushing from a shallow repo fall into "mostly works" category, I withdraw this patch.
--
Duy

#9 lore raw

PATCH 1/1 Revert "git-clone.txt: remove the restriction on pushing from a shallow clone"

This reverts commit dacd2bcc414e0b7aac36aaa400da0a743c4741cc.

"It fails reliably without corrupting the receiving repository when it should fail" may be better than the situation before the receiving end was hardened recently, but the fact that sometimes the push does not go through still remains. It is better to advice the users that they cannot push from a shallow repository as a limitation before they decide to use (or not to use) a shallow clone.
---

* Unfortunately I thought the documentation update was a no-brainer and already applied it, so here is a revert.

 Documentation/git-clone.txt | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
Documentation/git-clone.txt +5 -7
index 85769b8..450f158 100644
@@ -182,13 +182,11 @@ objects from the source repository into a pack in the cloned repository.
 --depth <depth>::
 	Create a 'shallow' clone with a history truncated to the
 	specified number of revisions.  A shallow repository has a
-	number of limitations (you cannot clone or fetch from it, nor
-	push into it), but is adequate if you are only interested in
-	the recent history of a large project with a long history.
-+
-Pushing from a shallow clone should be avoided if the git version on
-the receiver end is older than v1.7.10, or any other git
-implementation that does not perform connectivity check.
+	number of limitations (you cannot clone or fetch from
+	it, nor push from nor into it), but is adequate if you
+	are only interested in the recent history of a large project
+	with a long history, and would want to send in fixes
+	as patches.
 
 --[no-]single-branch::
 	Clone only the history leading to the tip of a single branch,
Signature · 1 line
1.8.3.2-941-gda9c3c8
#10 lore raw
In reply to Duy Nguyen
Quoted 6 lines · Duy Nguyen
Quoted 5 lines · Duy Nguyen
Quoted 4 lines

Also, the sender may have cloned from the receiver (fully) and then fetched a different history shallowly from elsewhere. The receiver may have no commit on that history, including the shallow-bottom.

Quoted 6 lines
Quoted 3 lines

Hmm.. right. And the receiver needs to setup proper graft to seal the shallow bottom. So it's really not safe to do pushing from a shallow repo without 52fed6e

Because this makes pushing from a shallow repo fall into "mostly works" category, I withdraw this patch.

Yeah, "reliably fails when it shouldn't" may be safer than before that patch, but the fact that you cannot push from a shallow one still remains, so we probably shouldn't tell the users to use it.