Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nested submodules #36

Merged
merged 3 commits into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/git-evtag-compute-py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
Expand All @@ -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)

Expand Down
5 changes: 4 additions & 1 deletion src/git-evtag.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
13 changes: 13 additions & 0 deletions tests/libtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 22 additions & 1 deletion tests/test-basic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ set -e
set -x
set -o pipefail

echo "1..1"
echo "1..7"

. $(dirname $0)/libtest.sh

Expand Down Expand Up @@ -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"