Skip to content

Init submodules when initializing repository #159

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions gitless/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ def init_repository(url=None):
continue
new_b = repo.create_branch(rb.branch_name, rb.head)
new_b.upstream = rb

# Initialize submodules
git.submodule('update', '--init')
return repo


Expand Down
20 changes: 20 additions & 0 deletions gitless/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -878,12 +878,20 @@ def setUp(self):
"""Creates temporary local Git repo to use as the remote."""
super(TestRemote, self).setUp()

# Create a repo for including in remote as a submodule
self.submodule_repo_path = tempfile.mkdtemp(prefix='gl-remote-test-submodule')
os.chdir(self.submodule_repo_path)
submodule_repo = core.init_repository()
git.commit(allow_empty=True, m='Initialize submodule repository')

# Create a repo to use as the remote
self.remote_path = tempfile.mkdtemp(prefix='gl-remote-test')
os.chdir(self.remote_path)
remote_repo = core.init_repository()
remote_repo.create_branch(
REMOTE_BRANCH, remote_repo.revparse_single('HEAD'))
git.submodule('add', '-f', self.submodule_repo_path)
Copy link
Contributor Author

@embs embs Dec 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The -f tries fixing build failed due to AppVeyor gitignore configuration:

ERROR: test_clone_from_remote
(gitless.tests.test_core.TestInitFromRemote)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\projects\gitless\gitless\tests\test_core.py", line 893, in
setUp
    git.submodule('add', self.submodule_repo_path)
  File "C:\Python27\lib\site-packages\pbs.py", line 456, in __call__
    return RunningCommand(command_ran, process, call_args, actual_stdin)
  File "C:\Python27\lib\site-packages\pbs.py", line 168, in __init__
    self._handle_exit_code(self.process.wait())
  File "C:\Python27\lib\site-packages\pbs.py", line 235, in
_handle_exit_code
    raise get_rc_exc(rc)(self.command_ran, self._stdout, self._stderr)
ErrorReturnCode_1:
Ran: u'git submodule add
c:\\users\\appveyor\\appdata\\local\\temp\\1\\gl-remote-test-submodulest4nzk'
STDOUT:

STDERR:
  The following path is ignored by one of your .gitignore files:
\users\appveyor\appdata\local\temp\1\gl-remote-test-submodulest4nzk
Use -f if you really want to add it.

Update

Still failing:

ERROR: test_clone_from_remote (gitless.tests.test_core.TestInitFromRemote)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\projects\gitless\gitless\tests\test_core.py", line 893, in setUp
    git.submodule('add', '-f', self.submodule_repo_path)
  File "C:\Python27\lib\site-packages\pbs.py", line 456, in __call__
    return RunningCommand(command_ran, process, call_args, actual_stdin)
  File "C:\Python27\lib\site-packages\pbs.py", line 168, in __init__
    self._handle_exit_code(self.process.wait())
  File "C:\Python27\lib\site-packages\pbs.py", line 235, in _handle_exit_code
    raise get_rc_exc(rc)(self.command_ran, self._stdout, self._stderr)
ErrorReturnCode_1: 
Ran: u'git submodule add -f c:\\users\\appveyor\\appdata\\local\\temp\\1\\gl-remote-test-submoduleytduoc'
STDOUT:
  Adding existing repo at '\users\appveyor\appdata\local\temp\1\gl-remote-test-submoduleytduoc' to the index
STDERR:
  fatal: \users\appveyor\appdata\local\temp\1\gl-remote-test-submoduleytduoc: '\users\appveyor\appdata\local\temp\1\gl-remote-test-submoduleytduoc' is outside repository
fatal: \users\appveyor\appdata\l... (230 more, please see e.stderr)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you need to do the git submodule add in the original repo (after the line that does os.chdir(self.path))?

git.commit('-m add submodule')

# Go back to the original repo
os.chdir(self.path)
Expand All @@ -895,6 +903,18 @@ def tearDown(self):
utils_lib.rmtree(self.remote_path)


class TestInitFromRemote(TestRemote):

def test_clone_from_remote(self):
new_repo_path = tempfile.mkdtemp(prefix='gl-init-from-remote-test')
os.chdir(new_repo_path)
new_repo = core.init_repository(url=self.remote_path)
submodule_dir = os.path.basename(self.submodule_repo_path)

self.assertFalse(len(os.listdir(submodule_dir)) == 0,
'Submodules were not initialized')


class TestRemoteCreate(TestRemote):

def test_create_new(self):
Expand Down