Skip to content

Commit

Permalink
✨ replace barebone git with GitPython. fixed #169
Browse files Browse the repository at this point in the history
  • Loading branch information
chfw committed Jan 28, 2019
1 parent 41aa53a commit 2b62d8c
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 22 deletions.
1 change: 1 addition & 0 deletions .moban.cd/moban.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ dependencies:
- lml>=0.0.9
- appdirs==1.4.3
- crayons
- GitPython==2.1.11
description: Yet another jinja2 cli command for static text generation
scm_host: github.com
5 changes: 2 additions & 3 deletions moban/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,9 @@ def git_clone(repos, submodule=False):
repo.git.submodule('update')
else:
reporter.report_git_clone(repo_name)
repo = Repo.clone_from(repo, moban_home)
repo = Repo.clone_from(repo, local_repo_folder)
if submodule:
output = repo.git.submodule('update', '--init')
reporter.report_info_message(output)
repo.git.submodule('update', '--init')


def get_template_path(template_dirs, template):
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ jinja2>=2.7.1
lml>=0.0.9
appdirs==1.4.3
crayons
GitPython==2.1.11
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
'lml>=0.0.9',
'appdirs==1.4.3',
'crayons',
'GitPython==2.1.11',
]
SETUP_COMMANDS = {}

Expand Down
61 changes: 42 additions & 19 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,44 +139,67 @@ def test_pip_install(fake_check_all):


@patch('os.path.exists', return_value=True)
@patch('appdirs.user_cache_dir', return_value='root')
@patch('moban.utils.mkdir_p')
@patch('git.Repo', autospec=True)
def test_git_clone(fake_repo, _):
def test_git_update(fake_repo, fake_make_dir, *_):
from moban.utils import git_clone

repos = ["https://github.com/my/repo", "https://gitlab.com/my/repo"]
repos = ["https://github.com/my/repoA"]
git_clone(repos)
fake_repo.assert_called_with(
repos[1]
os.path.join('root', 'repos', 'repoA')
)
repo = fake_repo.return_value
repo.git.submodule.assert_called_with('update')
eq_(repo.git.pull.called, True)


@patch("git.Repo", autospec=True)
def test_git_clone_with_submodules(fake_repo):
@patch('os.path.exists', return_value=True)
@patch('appdirs.user_cache_dir', return_value='root')
@patch('moban.utils.mkdir_p')
@patch('git.Repo', autospec=True)
def test_git_update_with_submodules(fake_repo, fake_make_dir, *_):
from moban.utils import git_clone

repos = ["https://github.com/my/repoA"]
git_clone(repos, submodule=True)
fake_repo.assert_called_with(
os.path.join('root', 'repos', 'repoA')
)
repo = fake_repo.return_value
repo.git.submodule.assert_called_with('update')


git_clone(
["https://github.com/my/repo", "https://gitlab.com/my/repo"],
submodule=True,
@patch('os.path.exists', return_value=False)
@patch('appdirs.user_cache_dir', return_value='root')
@patch('moban.utils.mkdir_p')
@patch('git.Repo', autospec=True)
def test_git_checkout_new(fake_repo, fake_make_dir, *_):
from moban.utils import git_clone

repos = ["https://github.com/my/repoA"]
git_clone(repos)
fake_repo.clone_from.assert_called_with(
repos[0], os.path.join('root', 'repos', 'repoA')
)
#fake_check_all.assert_called_with(["git", "submodule", "update"])

repo = fake_repo.return_value
eq_(repo.git.submodule.called, False)


@patch("os.path.exists", return_value=True)
@patch("os.chdir")
@patch("subprocess.check_call")
def test_git_clone_with_existing_repo(fake_check_all, _, __):
@patch('os.path.exists', return_value=False)
@patch('appdirs.user_cache_dir', return_value='root')
@patch('moban.utils.mkdir_p')
@patch('git.Repo', autospec=True)
def test_git_checkout_new_with_submodules(fake_repo, *_):
from moban.utils import git_clone

git_clone(
["https://github.com/my/repo", "https://gitlab.com/my/repo"],
submodule=True,
repos = ["https://github.com/my/repoA"]
git_clone(repos, submodule=True)
fake_repo.clone_from.assert_called_with(
repos[0], os.path.join('root', 'repos', 'repoA')
)
fake_check_all.assert_called_with(["git", "submodule", "update"])
repo = fake_repo.clone_from.return_value
repo.git.submodule.assert_called_with('update', '--init')


def test_get_repo_name():
Expand Down

0 comments on commit 2b62d8c

Please sign in to comment.