From 16b14169f87fe00f410d47bdb5ca32cffab330c9 Mon Sep 17 00:00:00 2001 From: gardlt Date: Fri, 15 Sep 2017 20:55:25 +0000 Subject: [PATCH] feat(source): checkout via reference - provide source tool ability to checkout commit hash Change-Id: Ic3b101a4877fd89516df8c4814802780a15e2461 --- armada/tests/unit/utils/test_source.py | 6 ++++-- armada/utils/source.py | 5 ++++- examples/simple.yaml | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/armada/tests/unit/utils/test_source.py b/armada/tests/unit/utils/test_source.py index ffeb7af9..d3b44a9f 100644 --- a/armada/tests/unit/utils/test_source.py +++ b/armada/tests/unit/utils/test_source.py @@ -23,12 +23,14 @@ class GitTestCase(unittest.TestCase): SOURCE_UTILS_LOCATION = 'armada.utils.source' + @mock.patch('armada.utils.source.Git') @mock.patch('armada.utils.source.tempfile') @mock.patch('armada.utils.source.Repo') - def test_git_clone_good_url(self, mock_git_repo, mock_temp): + def test_git_clone_good_url(self, mock_git_repo, mock_temp, mock_git_lib): mock_temp.mkdtemp.return_value = '/tmp/armada' - mock_git_repo.clone_from.return_value = "Repository" + mock_git_lib.checkout.return_value = "Repository" url = 'http://github.com/att-comdev/armada' + dir = source.git_clone(url) self.assertIsNotNone(dir) diff --git a/armada/utils/source.py b/armada/utils/source.py index 099f6443..87897f76 100644 --- a/armada/utils/source.py +++ b/armada/utils/source.py @@ -20,6 +20,7 @@ import tarfile import tempfile from git import Repo +from git import Git from ..exceptions import source_exceptions @@ -38,7 +39,9 @@ def git_clone(repo_url, branch='master'): _tmp_dir = tempfile.mkdtemp(prefix='armada') try: - Repo.clone_from(repo_url, _tmp_dir, **{'branch': branch}) + repo = Repo.clone_from(repo_url, _tmp_dir, **{'branch': 'master'}) + g = Git(repo.working_dir) + g.checkout(branch) except Exception: raise source_exceptions.GitLocationException(repo_url) diff --git a/examples/simple.yaml b/examples/simple.yaml index e89e180e..4ffcbf88 100644 --- a/examples/simple.yaml +++ b/examples/simple.yaml @@ -13,7 +13,7 @@ data: type: git location: https://github.com/gardlt/hello-world-chart subpath: . - reference: master + reference: 87aad18f7d8c6a1a08f3adc8866efd33bee6aa52 dependencies: [] --- schema: armada/Chart/v1