rev-parse: rev-parse: add --is-shallow-repository
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>
Øystein Walle committed
Sep 18, 2017 at 19:04 UTC
417abfde3534ad51a1a47e00ed799e40e3f7b4ae
3 files changed
+23
Documentation/git-rev-parse.txt
+3
@@ -235,6 +235,9 @@ print a message to stderr and exit with nonzero status.
235
--is-bare-repository::
236
When the repository is bare print "true", otherwise "false".
237
238
+--is-shallow-repository::
239
+ When the repository is shallow print "true", otherwise "false".
240
+
241
--resolve-git-dir <path>::
242
Check if <path> is a valid repository or a gitfile that
243
points at a valid repository, and print the location of the
builtin/rev-parse.c
+5
@@ -868,6 +868,11 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
868
: "false");
869
continue;
870
}
871
+ if (!strcmp(arg, "--is-shallow-repository")) {
872
+ printf("%s\n", is_repository_shallow() ? "true"
873
+ : "false");
874
+ continue;
875
+ }
876
if (!strcmp(arg, "--shared-index-path")) {
877
if (read_cache() < 0)
878
die(_("Could not read the index"));
t/t1500-rev-parse.sh
+15
@@ -116,6 +116,21 @@ test_expect_success 'git-path inside sub-dir' '
116
test_cmp expect actual
117
'
118
119
+test_expect_success 'rev-parse --is-shallow-repository in shallow repo' '
120
+ test_commit test_commit &&
121
+ echo true >expect &&
122
+ git clone --depth 1 --no-local . shallow &&
123
+ test_when_finished "rm -rf shallow" &&
124
+ git -C shallow rev-parse --is-shallow-repository >actual &&
125
+ test_cmp expect actual
126
+'
127
+
128
+test_expect_success 'rev-parse --is-shallow-repository in non-shallow repo' '
129
+ echo false >expect &&
130
+ git rev-parse --is-shallow-repository >actual &&
131
+ test_cmp expect actual
132
+'
133
+
134
test_expect_success 'showing the superproject correctly' '
135
git rev-parse --show-superproject-working-tree >out &&
136
test_must_be_empty out &&