Skip to content

Commit

Permalink
Update conans/test/unittests/tools/scm/test_git_get_commit.py
Browse files Browse the repository at this point in the history
- Test that submodules work as subfolders
  • Loading branch information
nmasseyKM committed Jun 7, 2022
1 parent fbcbb7e commit 9cfb364
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions conans/test/unittests/tools/scm/test_git_get_commit.py
Expand Up @@ -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

0 comments on commit 9cfb364

Please sign in to comment.