From 9cfb3643cc3c2ecbf619165caac3017325ef8821 Mon Sep 17 00:00:00 2001 From: Noah Massey Date: Tue, 7 Jun 2022 08:39:11 -0400 Subject: [PATCH] Update conans/test/unittests/tools/scm/test_git_get_commit.py - Test that submodules work as subfolders --- .../tools/scm/test_git_get_commit.py | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/conans/test/unittests/tools/scm/test_git_get_commit.py b/conans/test/unittests/tools/scm/test_git_get_commit.py index cc1b632a2ab..5e12bc91882 100644 --- a/conans/test/unittests/tools/scm/test_git_get_commit.py +++ b/conans/test/unittests/tools/scm/test_git_get_commit.py @@ -165,3 +165,53 @@ def _chdir(new_path): c.run_command("git rev-parse HEAD --full-history -- lib_a") commit_real_libA = str(c.out).splitlines()[0] assert commit_real_libA == commit_libA + +def test_submodule_repo(): + def _chdir(new_path): + old_path = os.getcwd() + os.chdir(new_path) + try: + yield + finally: + os.chdir(old_path) + + c = TestClient() + conanfile = MockConanfile({}) + c.save({"conanfile.py": ""}) + c.run_command("git init .") + c.run_command('git config user.name myname') + c.run_command('git config user.email myname@mycompany.com') + c.run_command("git add .") + c.run_command('git commit -m "Initial commit"') + c.run_command('git clone . source_subfolder') + c.run_command('git submodule add ../ source_subfolder') + c.run_command('git commit -m "submodule commit"') + c.save({"root_change": ""}) + c.run_command("git add .") + c.run_command('git commit -m "root change"') + + with _chdir(c.current_folder): + # default case + git = Git(conanfile) + commit_root = git.get_commit() + + # Relative paths + git = Git(conanfile, folder="source_subfolder") + commit_relA = git.get_commit() + + git = Git(conanfile, folder="./source_subfolder") + commit_relB = git.get_commit() + + # Full path + git = Git(conanfile, folder=os.path.join(c.current_folder, "source_subfolder")) + commit_full = git.get_commit() + + assert commit_relA == commit_relB + assert commit_relA == commit_full + assert commit_root != commit_full + + # This is the commit which modified the tree in the containing repo + # not the commit which the submodule is at + c.run_command("git rev-parse HEAD --full-history -- source_subfolder") + commit_submodule = str(c.out).splitlines()[0] + assert commit_submodule != commit_full