Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
9 changes: 6 additions & 3 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ Changed

* Triggertypes API now sorts by trigger ref by default. ``st2 trigger list`` will now show a sorted
list. (#4348)
* Speed up pack registration through the ``/v1/packs/register`` API endpoint. (improvement) #4342

Changed
~~~~~~~
Fixed
~~~~~

* Speed up pack registration through the ``/v1/packs/register`` API endpoint. (improvement) #4342
* Update ``st2-pack-install`` and ``st2 pack install`` command so it works with local git repos
(``file://<path to local git repo>``) which are in a detached head state (e.g. specific revision
is checked out). (improvement) #4366

2.9.0 - September 16, 2018
--------------------------
Expand Down
22 changes: 22 additions & 0 deletions contrib/packs/tests/test_action_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def setUp(self):
self.repo_base = tempfile.mkdtemp()

self.repo_instance = mock.MagicMock()
type(self.repo_instance).active_branch = mock.Mock()

def side_effect(url, to_path, **kwargs):
# Since we have no way to pass pack name here, we would have to derive it from repo url
Expand All @@ -113,6 +114,10 @@ def test_run_pack_download(self):
os.path.join(os.path.expanduser('~'), temp_dir))
self.assertTrue(os.path.isfile(os.path.join(self.repo_base, 'test/pack.yaml')))

self.repo_instance.git.checkout.assert_called()
self.repo_instance.git.branch.assert_called()
self.repo_instance.git.checkout.assert_called()

def test_run_pack_download_existing_pack(self):
action = self.get_action_instance()
action.run(packs=['test'], abs_repo_base=self.repo_base)
Expand Down Expand Up @@ -295,6 +300,9 @@ def test_resolve_urls(self):
url = eval_repo_url("file:///home/vagrant/stackstorm-test")
self.assertEqual(url, "file:///home/vagrant/stackstorm-test")

url = eval_repo_url("file://localhost/home/vagrant/stackstorm-test")
self.assertEqual(url, "file://localhost/home/vagrant/stackstorm-test")

url = eval_repo_url('ssh://<user@host>/AutomationStackStorm')
self.assertEqual(url, 'ssh://<user@host>/AutomationStackStorm')

Expand Down Expand Up @@ -363,3 +371,17 @@ def fake_commit(arg_ref):

result = action.run(packs=packs, abs_repo_base=self.repo_base)
self.assertEqual(result, {'test': 'Success.'})

def test_run_pack_dowload_local_git_repo_detached_head_state(self):
action = self.get_action_instance()

type(self.repo_instance).active_branch = \
mock.PropertyMock(side_effect=TypeError('detached head'))

result = action.run(packs=['file:///stackstorm-test'], abs_repo_base=self.repo_base)
self.assertEqual(result, {'test': 'Success.'})

# Verify function has bailed out early
self.repo_instance.git.checkout.assert_not_called()
self.repo_instance.git.branch.assert_not_called()
self.repo_instance.git.checkout.assert_not_called()
17 changes: 16 additions & 1 deletion st2common/st2common/util/pack_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,22 @@ def clone_repo(temp_dir, repo_url, verify_ssl=True, ref='master'):
# because we want the user to work with the repo in the
# future.
repo = Repo.clone_from(repo_url, temp_dir)
active_branch = repo.active_branch

is_local_repo = repo_url.startswith('file://')

try:
active_branch = repo.active_branch
except TypeError as e:
if is_local_repo:
active_branch = None
else:
raise e

# Special case for local git repos - we allow users to install from repos which are checked out
# at a specific commit (aka detached HEAD)
if is_local_repo and not active_branch and not ref:
LOG.debug('Installing pack from git repo on disk, skipping branch checkout')
return temp_dir

use_branch = False

Expand Down