]> git.ipfire.org Git - thirdparty/git.git/commitdiff
rev-parse: rev-parse: add --is-shallow-repository
authorØystein Walle <oystwa@gmail.com>
Mon, 18 Sep 2017 17:04:29 +0000 (19:04 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 19 Sep 2017 03:16:28 +0000 (12:16 +0900)
Running `git fetch --unshallow` on a repo that is not in fact shallow
produces a fatal error message. Add a helper to rev-parse that scripters
can use to determine whether a repo is shallow or not.

Signed-off-by: Øystein Walle <oystwa@gmail.com>
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-rev-parse.txt
builtin/rev-parse.c
t/t1500-rev-parse.sh

index b1293f24bb46f71238f3dee4700340a79b90fca8..0917b8207b9d6e6c88dc611cf40a81ab17481a2e 100644 (file)
@@ -235,6 +235,9 @@ print a message to stderr and exit with nonzero status.
 --is-bare-repository::
        When the repository is bare print "true", otherwise "false".
 
+--is-shallow-repository::
+       When the repository is shallow print "true", otherwise "false".
+
 --resolve-git-dir <path>::
        Check if <path> is a valid repository or a gitfile that
        points at a valid repository, and print the location of the
index c78b7b33d6604bb38a16e30d64cfabee0fd67f40..44e9a48e02363db902ac7358251c0098f396ce6e 100644 (file)
@@ -868,6 +868,11 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
                                                : "false");
                                continue;
                        }
+                       if (!strcmp(arg, "--is-shallow-repository")) {
+                               printf("%s\n", is_repository_shallow() ? "true"
+                                               : "false");
+                               continue;
+                       }
                        if (!strcmp(arg, "--shared-index-path")) {
                                if (read_cache() < 0)
                                        die(_("Could not read the index"));
index 03d3c7f6d65b46bf977adf76a6d68582206768c2..5c715fe2cf6c7afe2c39e6a7197cdd3d33329b8b 100755 (executable)
@@ -116,6 +116,21 @@ test_expect_success 'git-path inside sub-dir' '
        test_cmp expect actual
 '
 
+test_expect_success 'rev-parse --is-shallow-repository in shallow repo' '
+       test_commit test_commit &&
+       echo true >expect &&
+       git clone --depth 1 --no-local . shallow &&
+       test_when_finished "rm -rf shallow" &&
+       git -C shallow rev-parse --is-shallow-repository >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'rev-parse --is-shallow-repository in non-shallow repo' '
+       echo false >expect &&
+       git rev-parse --is-shallow-repository >actual &&
+       test_cmp expect actual
+'
+
 test_expect_success 'showing the superproject correctly' '
        git rev-parse --show-superproject-working-tree >out &&
        test_must_be_empty out &&