{"thread":{"id":"40636","subject":"fetch unshallow fails to honor dry-run","startedAt":"2015-10-25T09:16:00Z","lastAt":"2015-11-14T18:19:11Z","messageCount":3,"participants":["Tim Janik","Jeff King","Duy Nguyen"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"272185","messageId":"562C9DD0.5040109@gnu.org","threadId":"40636","inReplyTo":null,"subject":"fetch unshallow fails to honor dry-run","fromName":"Tim Janik","fromEmail":"timj@gnu.org","sentAt":"2015-10-25T09:16:00Z","receivedAt":"2015-10-25T09:16:00Z","isPatch":false,"sender":{"key":"timj@gnu.org","avatar":"https://gravatar.com/avatar/39101f5de4621a229041610bafefba04998848e7817d7152acfddfc8c5ea0058?d=mp&s=160"},"body":"Hey all,\n\ngit fetch --dry-run modifies the repository if --unshallow is passed:\n\n$ git --version\ngit version 2.1.4\n$ git fetch --dry-run --unshallow\nremote: Counting objects: 30603, done.\nremote: Compressing objects: 100% (6843/6843), done.\nremote: Total 30603 (delta 24564), reused 29164 (delta 23386)\nReceiving objects: 100% (30603/30603), 5.42 MiB | 0 bytes/s, done.\nResolving deltas: 100% (24564/24564), completed with 317 local objects.\nremote: Counting objects: 7, done.\nremote: Compressing objects: 100% (7/7), done.\nremote: Total 7 (delta 0), reused 6 (delta 0)\nUnpacking objects: 100% (7/7), done.\n\nI 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.\nBetter suggestions to find this out are very welcome.\n\n\n-- \nYours sincerely,\nTim Janik\n\nhttps://testbit.eu/timj/\nFree software author and speaker.\n"},{"id":"273106","messageId":"20151109192400.GA31715@sigill.intra.peff.net","threadId":"40636","inReplyTo":"562C9DD0.5040109@gnu.org","subject":"Re: fetch unshallow fails to honor dry-run","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2015-11-09T19:24:00Z","receivedAt":"2015-11-09T19:24:00Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"[+cc Duy for shallow expertise]\n\nOn Sun, Oct 25, 2015 at 10:16:00AM +0100, Tim Janik wrote:\n\n> git fetch --dry-run modifies the repository if --unshallow is passed:\n> \n> $ git --version\n> git version 2.1.4\n> $ git fetch --dry-run --unshallow\n> remote: Counting objects: 30603, done.\n> remote: Compressing objects: 100% (6843/6843), done.\n> remote: Total 30603 (delta 24564), reused 29164 (delta 23386)\n> Receiving objects: 100% (30603/30603), 5.42 MiB | 0 bytes/s, done.\n> Resolving deltas: 100% (24564/24564), completed with 317 local objects.\n> remote: Counting objects: 7, done.\n> remote: Compressing objects: 100% (7/7), done.\n> remote: Total 7 (delta 0), reused 6 (delta 0)\n> Unpacking objects: 100% (7/7), done.\n\nHmm. I think that is because --dry-run is effectively \"transfer the\nobjects, but do not update refs\". So by fetching the objects, we've\neffectively deepened the repository, whether we update the refs or not.\n\nThat being said, I suspect nobody has really thought hard about the\ninteraction of these two flags. And while obviously we update the\nobject database with a dry-run fetch, I can see the reasoning that we\nshould not touch the .git/shallow file, even if we have the objects.\n\nNaively, something like this patch might help, but I have no idea if it\ncauses other problems.\n\ndiff --git a/builtin/fetch.c b/builtin/fetch.c\nindex 4ce4fa0..24aa331 100644\n--- a/builtin/fetch.c\n+++ b/builtin/fetch.c\n@@ -870,7 +870,7 @@ static struct transport *prepare_transport(struct remote *remote)\n \t\tset_option(transport, TRANS_OPT_KEEP, \"yes\");\n \tif (depth)\n \t\tset_option(transport, TRANS_OPT_DEPTH, depth);\n-\tif (update_shallow)\n+\tif (update_shallow && !dry_run)\n \t\tset_option(transport, TRANS_OPT_UPDATE_SHALLOW, \"yes\");\n \treturn transport;\n }\n\n> I actually tried --dry-run --unshallow in order to find a way to\n> detect in a script if the current git repository is shallow or not.\n> Better suggestions to find this out are very welcome.\n\nYou can look for .git/shallow. I don't know if we've documented that\nanywhere as a public interface, but I think it should be safe to rely\non.\n\n-Peff\n"},{"id":"273335","messageId":"CACsJy8ALXN+BiAF497KcbhSM8_gMEt2L4y+6o0DOdU6ZS=BdCQ@mail.gmail.com","threadId":"40636","inReplyTo":"20151109192400.GA31715@sigill.intra.peff.net","subject":"Re: fetch unshallow fails to honor dry-run","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2015-11-14T18:19:11Z","receivedAt":"2015-11-14T18:19:11Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Thanks for including me. I thought I marked this for reply later but I did not..\n\nOn Mon, Nov 9, 2015 at 8:24 PM, Jeff King <peff@peff.net> wrote:\n> [+cc Duy for shallow expertise]\n>\n> On Sun, Oct 25, 2015 at 10:16:00AM +0100, Tim Janik wrote:\n>\n>> git fetch --dry-run modifies the repository if --unshallow is passed:\n>>\n>> $ git --version\n>> git version 2.1.4\n>> $ git fetch --dry-run --unshallow\n>> remote: Counting objects: 30603, done.\n>> remote: Compressing objects: 100% (6843/6843), done.\n>> remote: Total 30603 (delta 24564), reused 29164 (delta 23386)\n>> Receiving objects: 100% (30603/30603), 5.42 MiB | 0 bytes/s, done.\n>> Resolving deltas: 100% (24564/24564), completed with 317 local objects.\n>> remote: Counting objects: 7, done.\n>> remote: Compressing objects: 100% (7/7), done.\n>> remote: Total 7 (delta 0), reused 6 (delta 0)\n>> Unpacking objects: 100% (7/7), done.\n>\n> Hmm. I think that is because --dry-run is effectively \"transfer the\n> objects, but do not update refs\". So by fetching the objects, we've\n> effectively deepened the repository, whether we update the refs or not.\n>\n> That being said, I suspect nobody has really thought hard about the\n> interaction of these two flags. And while obviously we update the\n> object database with a dry-run fetch, I can see the reasoning that we\n> should not touch the .git/shallow file, even if we have the objects.\n>\n> Naively, something like this patch might help, but I have no idea if it\n> causes other problems.\n>\n> diff --git a/builtin/fetch.c b/builtin/fetch.c\n> index 4ce4fa0..24aa331 100644\n> --- a/builtin/fetch.c\n> +++ b/builtin/fetch.c\n> @@ -870,7 +870,7 @@ static struct transport *prepare_transport(struct remote *remote)\n>                 set_option(transport, TRANS_OPT_KEEP, \"yes\");\n>         if (depth)\n>                 set_option(transport, TRANS_OPT_DEPTH, depth);\n> -       if (update_shallow)\n> +       if (update_shallow && !dry_run)\n>                 set_option(transport, TRANS_OPT_UPDATE_SHALLOW, \"yes\");\n>         return transport;\n>  }\n\nThe key is not let shallow.c:update_shallow() do anything to\n.git/shallow. --depth (or --unshallow) does not check this\nUPDATE_SHALLOW flag and can still change .git/shallow. Other than\nthat, I don't think it can cause and bad effects. It's probably best\nto pass this dry-run flag to transport.c\n-- \nDuy\n"}]}