{"thread":{"id":"46782","subject":"[PATCH] rev-parse: rev-parse: add --is-shallow-repository","startedAt":"2017-09-18T17:04:47Z","lastAt":"2017-09-19T18:52:09Z","messageCount":4,"participants":["Øystein Walle","Jonathan Nieder","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"328309","messageId":"20170918170429.8328-1-oystwa@gmail.com","threadId":"46782","inReplyTo":null,"subject":"[PATCH] rev-parse: rev-parse: add --is-shallow-repository","fromName":"Øystein Walle","fromEmail":"oystwa@gmail.com","sentAt":"2017-09-18T17:04:29Z","receivedAt":"2017-09-18T17:04:47Z","isPatch":true,"sender":{"key":"oystwa@gmail.com","avatar":"https://avatars.githubusercontent.com/u/794585?v=4"},"body":"Running `git fetch --unshallow` on a repo that is not in fact shallow\nproduces a fatal error message. Add a helper to rev-parse that scripters\ncan use to determine whether a repo is shallow or not.\n\nSigned-off-by: Øystein Walle <oystwa@gmail.com>\n---\n Documentation/git-rev-parse.txt |  3 +++\n builtin/rev-parse.c             |  5 +++++\n t/t1500-rev-parse.sh            | 15 +++++++++++++++\n 3 files changed, 23 insertions(+)\n\ndiff --git a/Documentation/git-rev-parse.txt b/Documentation/git-rev-parse.txt\nindex b1293f24b..0917b8207 100644\n--- a/Documentation/git-rev-parse.txt\n+++ b/Documentation/git-rev-parse.txt\n@@ -235,6 +235,9 @@ print a message to stderr and exit with nonzero status.\n --is-bare-repository::\n \tWhen the repository is bare print \"true\", otherwise \"false\".\n \n+--is-shallow-repository::\n+\tWhen the repository is shallow print \"true\", otherwise \"false\".\n+\n --resolve-git-dir <path>::\n \tCheck if <path> is a valid repository or a gitfile that\n \tpoints at a valid repository, and print the location of the\ndiff --git a/builtin/rev-parse.c b/builtin/rev-parse.c\nindex 2bd28d3c0..c923207f2 100644\n--- a/builtin/rev-parse.c\n+++ b/builtin/rev-parse.c\n@@ -868,6 +868,11 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n \t\t\t\t\t\t: \"false\");\n \t\t\t\tcontinue;\n \t\t\t}\n+\t\t\tif (!strcmp(arg, \"--is-shallow-repository\")) {\n+\t\t\t\tprintf(\"%s\\n\", is_repository_shallow() ? \"true\"\n+\t\t\t\t\t\t: \"false\");\n+\t\t\t\tcontinue;\n+\t\t\t}\n \t\t\tif (!strcmp(arg, \"--shared-index-path\")) {\n \t\t\t\tif (read_cache() < 0)\n \t\t\t\t\tdie(_(\"Could not read the index\"));\ndiff --git a/t/t1500-rev-parse.sh b/t/t1500-rev-parse.sh\nindex 03d3c7f6d..9d3433a30 100755\n--- a/t/t1500-rev-parse.sh\n+++ b/t/t1500-rev-parse.sh\n@@ -116,6 +116,21 @@ test_expect_success 'git-path inside sub-dir' '\n \ttest_cmp expect actual\n '\n \n+test_expect_success 'git-path shallow repository' '\n+\ttest_commit test_commit &&\n+\techo true >expect &&\n+\tgit clone --depth 1 --no-local . shallow &&\n+\ttest_when_finished \"rm -rf shallow\" &&\n+\tgit -C shallow rev-parse --is-shallow-repository >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'git-path notshallow repository' '\n+\techo false >expect &&\n+\tgit rev-parse --is-shallow-repository >actual &&\n+\ttest_cmp expect actual\n+'\n+\n test_expect_success 'showing the superproject correctly' '\n \tgit rev-parse --show-superproject-working-tree >out &&\n \ttest_must_be_empty out &&\n-- \n2.11.0.485.g4e59582\n\n"},{"id":"328331","messageId":"20170919023349.GA175206@aiede.mtv.corp.google.com","threadId":"46782","inReplyTo":"20170918170429.8328-1-oystwa@gmail.com","subject":"Re: [PATCH] rev-parse: rev-parse: add --is-shallow-repository","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2017-09-19T02:33:49Z","receivedAt":"2017-09-19T02:34:19Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Hi,\n\nØystein Walle wrote:\n\n> Running `git fetch --unshallow` on a repo that is not in fact shallow\n> produces a fatal error message.\n\nHm, can you say more about the context?  From a certain point of view,\nit might make sense for that command to succeed instead: if the repo\nis already unshallow, then why should't \"fetch --unshallow\" complain\ninstead of declaring victory?\n\n>                                 Add a helper to rev-parse that scripters\n> can use to determine whether a repo is shallow or not.\n>\n> Signed-off-by: Øystein Walle <oystwa@gmail.com>\n> ---\n>  Documentation/git-rev-parse.txt |  3 +++\n>  builtin/rev-parse.c             |  5 +++++\n>  t/t1500-rev-parse.sh            | 15 +++++++++++++++\n>  3 files changed, 23 insertions(+)\n\nRegardless, this new rev-parse --is-shallow helper looks like a good\nfeature.\n\n[...]\n> --- a/builtin/rev-parse.c\n> +++ b/builtin/rev-parse.c\n> @@ -868,6 +868,11 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n>  \t\t\t\t\t\t: \"false\");\n>  \t\t\t\tcontinue;\n>  \t\t\t}\n> +\t\t\tif (!strcmp(arg, \"--is-shallow-repository\")) {\n> +\t\t\t\tprintf(\"%s\\n\", is_repository_shallow() ? \"true\"\n> +\t\t\t\t\t\t: \"false\");\n> +\t\t\t\tcontinue;\n> +\t\t\t}\n\nThe implementation is straightforward and correct.\n\n[...]\n> --- a/t/t1500-rev-parse.sh\n> +++ b/t/t1500-rev-parse.sh\n\nThanks for writing tests. \\o/\n\n> @@ -116,6 +116,21 @@ test_expect_success 'git-path inside sub-dir' '\n>  \ttest_cmp expect actual\n>  '\n>  \n> +test_expect_success 'git-path shallow repository' '\n\nWhat does git-path mean here?  I wonder if it's a copy/paste error.\nDid you mean something like\n\n test_expect_success 'rev-parse --is-shallow-repository in shallow repo' '\n\n?\n\n> +\ttest_commit test_commit &&\n> +\techo true >expect &&\n> +\tgit clone --depth 1 --no-local . shallow &&\n> +\ttest_when_finished \"rm -rf shallow\" &&\n> +\tgit -C shallow rev-parse --is-shallow-repository >actual &&\n> +\ttest_cmp expect actual\n> +'\n> +\n> +test_expect_success 'git-path notshallow repository' '\n\nLikewise: should this be\n\n test_expect_success 'rev-parse --is-shallow-repository in non-shallow repo' '\n\n?\n\n> +\techo false >expect &&\n> +\tgit rev-parse --is-shallow-repository >actual &&\n> +\ttest_cmp expect actual\n> +'\n> +\n>  test_expect_success 'showing the superproject correctly' '\n\nWith the two tweaks mentioned above,\nReviewed-by: Jonathan Nieder <jrnieder@gmail.com>\n\nThanks.\n"},{"id":"328340","messageId":"xmqqlglbqstw.fsf@gitster.mtv.corp.google.com","threadId":"46782","inReplyTo":"20170919023349.GA175206@aiede.mtv.corp.google.com","subject":"Re: [PATCH] rev-parse: rev-parse: add --is-shallow-repository","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-09-19T03:18:35Z","receivedAt":"2017-09-19T03:18:41Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jonathan Nieder <jrnieder@gmail.com> writes:\n\n>>  test_expect_success 'showing the superproject correctly' '\n>\n> With the two tweaks mentioned above,\n> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>\n\nI agree with the fixes to the test titles suggested, so I'll queue\nthe patch with the fixes squashed in.  Hearing \"yeah, the titles\nwere copy-pasted without adjusting, thanks for fixing, Jonathan!\"\nsent by Øystein would be super nice.\n\nThanks, both.\n\n\n"},{"id":"328399","messageId":"20170919185156.4285-1-oystwa@gmail.com","threadId":"46782","inReplyTo":"xmqqlglbqstw.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH] rev-parse: rev-parse: add --is-shallow-repository","fromName":"Øystein Walle","fromEmail":"oystwa@gmail.com","sentAt":"2017-09-19T18:51:56Z","receivedAt":"2017-09-19T18:52:09Z","isPatch":true,"sender":{"key":"oystwa@gmail.com","avatar":"https://avatars.githubusercontent.com/u/794585?v=4"},"body":"> Hm, can you say more about the context?  From a certain point of view,\n> it might make sense for that command to succeed instead: if the repo\n> is already unshallow, then why should't \"fetch --unshallow\" complain\n> instead of declaring victory?\n\nA fellow in #git on Freenode was writing a script for automation and\nencountered this error, and asked how to find out whether a repo was\nshallow. My *first instinct* was to check if rev-parse had a flag for\nit; I wouldn't have been surprised if it did.\n\nI agree that treating it as a fatal error is a bit much in the first\nplace, but I also think having a way to check can be useful. I also\nwonder if a lot of the stuff rev-parse is used for now should be moved\nto some sort of `git misc` command, but that's a different can of worms,\nso into rev-parse a new flag went.\n\n> What does git-path mean here?  I wonder if it's a copy/paste error.\n> ...\n> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>\n\nYeah, the titles were copy-pasted without adjusting, thanks for fixing,\nJonathan! ;)\n\n> I agree with the fixes to the test titles suggested, so I'll queue the\n> patch with the fixes squashed in.  Hearing \"yeah, the titles were\n> copy-pasted without adjusting, thanks for fixing, Jonathan!\" sent by\n> =C3=98ystein would be super nice.\n\nSounds good. Thanks for queueing my patch. My fourth!\n\n�sse\n"}]}