Skip to content

Commit 13a2f62

Browse files
jonathantanmygitster
authored andcommitted
submodule: pass repo to check_has_commit()
Pass the repo explicitly when calling check_has_commit() to avoid relying on add_submodule_odb(). With this commit and the parent commit, the last remaining tests no longer rely on add_submodule_odb(), so mark these tests accordingly. Signed-off-by: Jonathan Tan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent eef7190 commit 13a2f62

6 files changed

+28
-3
lines changed

submodule.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -928,23 +928,33 @@ struct has_commit_data {
928928
static int check_has_commit(const struct object_id *oid, void *data)
929929
{
930930
struct has_commit_data *cb = data;
931+
struct repository subrepo;
932+
enum object_type type;
931933

932-
enum object_type type = oid_object_info(cb->repo, oid, NULL);
934+
if (repo_submodule_init(&subrepo, cb->repo, cb->path, null_oid())) {
935+
cb->result = 0;
936+
goto cleanup;
937+
}
938+
939+
type = oid_object_info(&subrepo, oid, NULL);
933940

934941
switch (type) {
935942
case OBJ_COMMIT:
936-
return 0;
943+
goto cleanup;
937944
case OBJ_BAD:
938945
/*
939946
* Object is missing or invalid. If invalid, an error message
940947
* has already been printed.
941948
*/
942949
cb->result = 0;
943-
return 0;
950+
goto cleanup;
944951
default:
945952
die(_("submodule entry '%s' (%s) is a %s, not a commit"),
946953
cb->path, oid_to_hex(oid), type_name(type));
947954
}
955+
cleanup:
956+
repo_clear(&subrepo);
957+
return 0;
948958
}
949959

950960
static int submodule_has_commits(struct repository *r,

t/t5526-fetch-submodules.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ test_description='Recursive "git fetch" for submodules'
66
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master
77
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
88

9+
GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB=1
10+
export GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB
11+
912
. ./test-lib.sh
1013

1114
pwd=$(pwd)

t/t5531-deep-submodule-push.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ test_description='test push with submodules'
55
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
66
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
77

8+
GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB=1
9+
export GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB
10+
811
. ./test-lib.sh
912

1013
test_expect_success setup '

t/t5545-push-options.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ test_description='pushing to a repository using push options'
55
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
66
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
77

8+
GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB=1
9+
export GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB
10+
811
. ./test-lib.sh
912

1013
mk_repo_pair () {

t/t5572-pull-submodule.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
test_description='pull can handle submodules'
44

5+
GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB=1
6+
export GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB
7+
58
. ./test-lib.sh
69
. "$TEST_DIRECTORY"/lib-submodule-update.sh
710

t/t7418-submodule-sparse-gitmodules.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ The test setup uses a sparse checkout, however the same scenario can be set up
1212
also by committing .gitmodules and then just removing it from the filesystem.
1313
'
1414

15+
GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB=1
16+
export GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB
17+
1518
. ./test-lib.sh
1619

1720
test_expect_success 'sparse checkout setup which hides .gitmodules' '

0 commit comments

Comments
 (0)