git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Tim Janik <timj@gnu.org>
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>, git@vger.kernel.org
Subject: Re: fetch unshallow fails to honor dry-run
Date: Mon, 9 Nov 2015 14:24:00 -0500	[thread overview]
Message-ID: <20151109192400.GA31715@sigill.intra.peff.net> (raw)
In-Reply-To: <562C9DD0.5040109@gnu.org>

[+cc Duy for shallow expertise]

On Sun, Oct 25, 2015 at 10:16:00AM +0100, Tim Janik wrote:

> git fetch --dry-run modifies the repository if --unshallow is passed:
> 
> $ git --version
> git version 2.1.4
> $ git fetch --dry-run --unshallow
> remote: Counting objects: 30603, done.
> remote: Compressing objects: 100% (6843/6843), done.
> remote: Total 30603 (delta 24564), reused 29164 (delta 23386)
> Receiving objects: 100% (30603/30603), 5.42 MiB | 0 bytes/s, done.
> Resolving deltas: 100% (24564/24564), completed with 317 local objects.
> remote: Counting objects: 7, done.
> remote: Compressing objects: 100% (7/7), done.
> remote: Total 7 (delta 0), reused 6 (delta 0)
> Unpacking objects: 100% (7/7), done.

Hmm. I think that is because --dry-run is effectively "transfer the
objects, but do not update refs". So by fetching the objects, we've
effectively deepened the repository, whether we update the refs or not.

That being said, I suspect nobody has really thought hard about the
interaction of these two flags. And while obviously we update the
object database with a dry-run fetch, I can see the reasoning that we
should not touch the .git/shallow file, even if we have the objects.

Naively, something like this patch might help, but I have no idea if it
causes other problems.

diff --git a/builtin/fetch.c b/builtin/fetch.c
index 4ce4fa0..24aa331 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -870,7 +870,7 @@ static struct transport *prepare_transport(struct remote *remote)
 		set_option(transport, TRANS_OPT_KEEP, "yes");
 	if (depth)
 		set_option(transport, TRANS_OPT_DEPTH, depth);
-	if (update_shallow)
+	if (update_shallow && !dry_run)
 		set_option(transport, TRANS_OPT_UPDATE_SHALLOW, "yes");
 	return transport;
 }

> I actually tried --dry-run --unshallow in order to find a way to
> detect in a script if the current git repository is shallow or not.
> Better suggestions to find this out are very welcome.

You can look for .git/shallow. I don't know if we've documented that
anywhere as a public interface, but I think it should be safe to rely
on.

-Peff

  reply	other threads:[~2015-11-09 19:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-25  9:16 fetch unshallow fails to honor dry-run Tim Janik
2015-11-09 19:24 ` Jeff King [this message]
2015-11-14 18:19   ` Duy Nguyen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20151109192400.GA31715@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=pclouds@gmail.com \
    --cc=timj@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).