Skip to content

Commit

Permalink
fix to allow submodule name different from path
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve Goldhaber committed Sep 14, 2020
1 parent 5b5e1c2 commit b32c6fc
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
18 changes: 15 additions & 3 deletions manic/externals_description.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,21 @@ def read_gitmodules_file(root_dir, file_name):
ExternalsDescription.REPO_URL, url)
externals_description.set(sec_name,
ExternalsDescription.REQUIRED, 'True')
git_hash = submods[sec_name]['hash']
externals_description.set(sec_name,
ExternalsDescription.HASH, git_hash)
if sec_name in submods:
submod_name = sec_name
else:
# The section name does not have to match the path
submod_name = path

if submod_name in submods:
git_hash = submods[submod_name]['hash']
externals_description.set(sec_name,
ExternalsDescription.HASH,
git_hash)
else:
emsg = "submodule status has no section, '{}'"
emsg += "\nCheck section names in externals config file"
fatal_error(emsg.format(submod_name))

# Required items
externals_description.add_section(DESCRIPTION_SECTION)
Expand Down
29 changes: 23 additions & 6 deletions test/test_sys_checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import os
import os.path
import shutil
import sys
import unittest

from manic.externals_description import ExternalsDescription
Expand Down Expand Up @@ -535,12 +536,26 @@ def setUp(self):

self._test_id = self.id().split('.')[-1]

# find root
if os.path.exists(os.path.join(os.getcwd(), 'checkout_externals')):
root_dir = os.path.abspath(os.getcwd())
else:
# maybe we are in a subdir, search up
root_dir = os.path.abspath(os.path.join(os.getcwd(), os.pardir))
while os.path.basename(root_dir):
if os.path.exists(os.path.join(root_dir, 'checkout_externals')):
break
root_dir = os.path.dirname(root_dir)

if not os.path.exists(os.path.join(root_dir, 'checkout_externals')):
raise RuntimeError('Cannot find checkout_externals')

# path to the executable
self._checkout = os.path.join('../checkout_externals')
self._checkout = os.path.abspath(self._checkout)
self._checkout = os.path.join(root_dir, 'checkout_externals')

# directory where we have test repositories
self._bare_root = os.path.join(os.getcwd(), BARE_REPO_ROOT_NAME)
test_dir = os.path.join(root_dir, 'test')
self._bare_root = os.path.join(test_dir, BARE_REPO_ROOT_NAME)
self._bare_root = os.path.abspath(self._bare_root)

# set into the environment so var will be expanded in externals files
Expand Down Expand Up @@ -1610,8 +1625,9 @@ def setUp(self):
cwd = os.getcwd()
fork_repo_dir = os.path.join(self._bare_root, SIMPLE_FORK_NAME)
simple_repo_dir = os.path.join(self._bare_root, SIMPLE_REPO_NAME)
self._simple_ext_fork_name = SIMPLE_FORK_NAME.split('.')[0]
self._simple_ext_name = SIMPLE_REPO_NAME.split('.')[0]
self._simple_ext_fork_name = os.path.splitext(SIMPLE_FORK_NAME)[0]
self._simple_ext_name = os.path.join('sourc',
os.path.splitext(SIMPLE_REPO_NAME)[0])
os.chdir(self._repo_dir)
# Add a branch with a subrepo
cmd = ['git', 'branch', self._bare_branch_name, 'master']
Expand All @@ -1632,7 +1648,8 @@ def setUp(self):
execute_subprocess(cmd)
cmd = ['git', 'checkout', self._config_branch_name]
execute_subprocess(cmd)
cmd = ['git', 'submodule', 'add', simple_repo_dir]
cmd = ['git', 'submodule', 'add', '--name', SIMPLE_REPO_NAME,
simple_repo_dir, self._simple_ext_name]
execute_subprocess(cmd)
# Checkout feature2
os.chdir(self._simple_ext_name)
Expand Down

0 comments on commit b32c6fc

Please sign in to comment.