Skip to content

Commit

Permalink
✨ initial prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
chfw committed Jan 28, 2019
1 parent ab77657 commit 41aa53a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
18 changes: 7 additions & 11 deletions moban/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,30 +133,26 @@ def pip_install(packages):


def git_clone(repos, submodule=False):
import subprocess
from git import Repo

moban_home = get_moban_home()
mkdir_p(moban_home)

for repo in repos:
repo_name = get_repo_name(repo)
local_repo_folder = os.path.join(moban_home, repo_name)
current_working_dir = os.getcwd()
if os.path.exists(local_repo_folder):
reporter.report_git_pull(repo_name)
os.chdir(local_repo_folder)
subprocess.check_call(["git", "pull"])
repo = Repo(local_repo_folder)
repo.git.pull()
if submodule:
subprocess.check_call(["git", "submodule", "update"])
repo.git.submodule('update')
else:
reporter.report_git_clone(repo_name)
os.chdir(moban_home)
subprocess.check_call(["git", "clone", repo, repo_name])
repo = Repo.clone_from(repo, moban_home)
if submodule:
os.chdir(os.path.join(moban_home, repo_name))
subprocess.check_call(["git", "submodule", "init"])
subprocess.check_call(["git", "submodule", "update"])
os.chdir(current_working_dir)
output = repo.git.submodule('update', '--init')
reporter.report_info_message(output)


def get_template_path(template_dirs, template):
Expand Down
24 changes: 15 additions & 9 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,26 +138,32 @@ def test_pip_install(fake_check_all):
)


@patch("subprocess.check_call")
def test_git_clone(fake_check_all):
@patch('os.path.exists', return_value=True)
@patch('git.Repo', autospec=True)
def test_git_clone(fake_repo, _):
from moban.utils import git_clone

git_clone(["https://github.com/my/repo", "https://gitlab.com/my/repo"])
fake_check_all.assert_called_with(
["git", "clone", "https://gitlab.com/my/repo", "repo"]
repos = ["https://github.com/my/repo", "https://gitlab.com/my/repo"]
git_clone(repos)
fake_repo.assert_called_with(
repos[1]
)
repo = fake_repo.return_value
repo.git.submodule.assert_called_with('update')


@patch("os.chdir")
@patch("subprocess.check_call")
def test_git_clone_with_submodules(fake_check_all, _):
@patch("git.Repo", autospec=True)
def test_git_clone_with_submodules(fake_repo):
from moban.utils import git_clone

repo = fake_repo.return_value

git_clone(
["https://github.com/my/repo", "https://gitlab.com/my/repo"],
submodule=True,
)
fake_check_all.assert_called_with(["git", "submodule", "update"])
#fake_check_all.assert_called_with(["git", "submodule", "update"])



@patch("os.path.exists", return_value=True)
Expand Down

0 comments on commit 41aa53a

Please sign in to comment.