diff --git a/src/git-evtag-compute-py b/src/git-evtag-compute-py index 0babc5c..861dcca 100755 --- a/src/git-evtag-compute-py +++ b/src/git-evtag-compute-py @@ -76,7 +76,7 @@ def checksum_object(repo, objid): raise subprocess.CalledProcessError(p.returncode, 'git cat-file') return treeobjid -def checksum_tree(repo, objid): +def checksum_tree(repo, path, objid): checksum_object(repo, objid) p = subprocess.Popen(['git', 'ls-tree', objid], stdin=DEVNULL, @@ -89,9 +89,9 @@ def checksum_tree(repo, objid): if otype == 'blob': checksum_object(repo, subid) elif otype == 'tree': - checksum_tree(repo, subid) + checksum_tree(repo, os.path.join(path, fname), subid) elif otype == 'commit': - checksum_repo(os.path.join(repo, fname), subid) + checksum_repo(os.path.join(repo, path, fname), subid) else: assert False p.wait() @@ -100,7 +100,7 @@ def checksum_tree(repo, objid): def checksum_repo(repo, objid): treeid = checksum_object(repo, objid) - checksum_tree(repo, treeid) + checksum_tree(repo, '.', treeid) checksum_repo('.', opts.rev) diff --git a/src/git-evtag.c b/src/git-evtag.c index f8e5639..132b356 100644 --- a/src/git-evtag.c +++ b/src/git-evtag.c @@ -258,7 +258,10 @@ checksum_tree_callback (const char *root, case GIT_OBJ_COMMIT: { git_submodule *submod = NULL; - tmp_r = git_submodule_lookup (&submod, twdata->repo, git_tree_entry_name (entry)); + char *submodule_path = g_build_filename (root, git_tree_entry_name (entry), NULL); + tmp_r = git_submodule_lookup (&submod, twdata->repo, submodule_path); + g_free (submodule_path); + if (!handle_libgit_ret (tmp_r, twdata->error)) goto out; diff --git a/tests/libtest.sh b/tests/libtest.sh index 907c1aa..70643ab 100644 --- a/tests/libtest.sh +++ b/tests/libtest.sh @@ -143,8 +143,21 @@ setup_test_repository () { gitcommit_inctime -a -m 'Add libsub' git push + # Copy coolproject to create another version which has two submodules, + # one which is nested deeper in the repository. + cd ${test_tmpdir} + cp -r repos/coolproject repos/coolproject2 + git clone file://${test_tmpdir}/repos/coolproject2 + cd coolproject2 + mkdir subprojects + git submodule add ../subproject subprojects/subproject + git add subprojects/subproject + gitcommit_inctime -a -m 'Add subprojects/subproject' + git push + cd ${test_tmpdir} rm coolproject -rf + rm coolproject2 -rf rm subproject -rf cd $oldpwd diff --git a/tests/test-basic.sh b/tests/test-basic.sh index e828019..560237c 100755 --- a/tests/test-basic.sh +++ b/tests/test-basic.sh @@ -19,7 +19,7 @@ set -e set -x set -o pipefail -echo "1..1" +echo "1..7" . $(dirname $0)/libtest.sh @@ -111,3 +111,24 @@ git evtag verify --no-signature v2015.1 rm -f tag.txt rm -f verify.out echo "ok checksum-only tag + verify" + +cd ${test_tmpdir} +rm coolproject -rf +git clone repos/coolproject2 +cd coolproject2 +git submodule update --init +with_editor_script git evtag sign -u 472CDAFA v2015.1 +git show refs/tags/v2015.1 > tag.txt +TAG='Git-EVTag-v0-SHA512: d683c087ffee370996b9514f892ec8911451b33e3dfe48ac233a3dca1d63676802236e2d152803f553aa7d05c00f6e30b83f1f73dae9d524378845be02da4b97' +assert_file_has_content tag.txt "${TAG}" +with_editor_script git evtag verify v2015.1 | tee verify.out +assert_file_has_content verify.out "Successfully verified: ${TAG}" +# Also test subdirectory +(cd src && with_editor_script git evtag verify v2015.1 | tee ../verify2.out) +assert_file_has_content verify2.out "Successfully verified: ${TAG}" +${SRCDIR}/git-evtag-compute-py HEAD > tag-py.txt +assert_file_has_content tag-py.txt "${TAG}" + +rm -f tag.txt +rm -f verify.out +echo "ok tag + verify with nested submodules"