Skip to content

Commit 417abfd

Browse files
Ossegitster
authored andcommitted
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 <[email protected]> Reviewed-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 94c9fd2 commit 417abfd

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

Documentation/git-rev-parse.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,9 @@ print a message to stderr and exit with nonzero status.
235235
--is-bare-repository::
236236
When the repository is bare print "true", otherwise "false".
237237

238+
--is-shallow-repository::
239+
When the repository is shallow print "true", otherwise "false".
240+
238241
--resolve-git-dir <path>::
239242
Check if <path> is a valid repository or a gitfile that
240243
points at a valid repository, and print the location of the

builtin/rev-parse.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,11 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
868868
: "false");
869869
continue;
870870
}
871+
if (!strcmp(arg, "--is-shallow-repository")) {
872+
printf("%s\n", is_repository_shallow() ? "true"
873+
: "false");
874+
continue;
875+
}
871876
if (!strcmp(arg, "--shared-index-path")) {
872877
if (read_cache() < 0)
873878
die(_("Could not read the index"));

t/t1500-rev-parse.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,21 @@ test_expect_success 'git-path inside sub-dir' '
116116
test_cmp expect actual
117117
'
118118

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+
119134
test_expect_success 'showing the superproject correctly' '
120135
git rev-parse --show-superproject-working-tree >out &&
121136
test_must_be_empty out &&

0 commit comments

Comments
 (0)