summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2018-04-26 21:14:39 +0300
committerLars Wirzenius <liw@liw.fi>2018-04-27 13:43:46 +0300
commit10edd0e04571842c0991e2d9cbf83cb26b3960f6 (patch)
tree5f9f6f83311a37fa27df5f3e1ddcc95a2a14e5cf
parent36036ada8cdcb3a1222c31e8ce8076a624a09701 (diff)
downloadick2-10edd0e04571842c0991e2d9cbf83cb26b3960f6.tar.gz
Add: action: git
-rw-r--r--NEWS1
-rw-r--r--ick2/__init__.py1
-rw-r--r--ick2/actions.py66
-rw-r--r--ick2/actions_tests.py10
4 files changed, 65 insertions, 13 deletions
diff --git a/NEWS b/NEWS
index d2d0991..9a522b7 100644
--- a/NEWS
+++ b/NEWS
@@ -20,6 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
Version 0.47+git, not yet released
----------------------------------
+* New action to do `git clone` or `git remote update`.
Version 0.47, released 2018-04-25
----------------------------------
diff --git a/ick2/__init__.py b/ick2/__init__.py
index e350753..f212946 100644
--- a/ick2/__init__.py
+++ b/ick2/__init__.py
@@ -78,4 +78,5 @@ from .actions import (
CreateWorkspaceAction,
ArchiveWorkspaceAction,
PopulateSystreeAction,
+ GitAction,
)
diff --git a/ick2/actions.py b/ick2/actions.py
index 37ebd32..96382ef 100644
--- a/ick2/actions.py
+++ b/ick2/actions.py
@@ -85,18 +85,28 @@ class ActionFactory:
return action
def _create_action_object(self, env, spec):
- if 'shell' in spec:
- return ShellAction(env)
- if 'python' in spec:
- return PythonAction(env)
- if 'debootstrap' in spec:
- return DebootstrapAction(env)
- if 'archive' in spec:
- return ArchiveWorkspaceAction(env)
- if spec.get('action') == 'populate_systree':
- return PopulateSystreeAction(env)
- if spec.get('action') == 'create_workspace':
- return CreateWorkspaceAction(env)
+ rules = [
+ ('shell', ShellAction),
+ ('python', PythonAction),
+ ('debootstrap', DebootstrapAction),
+ ('archive', ArchiveWorkspaceAction),
+ ]
+
+ for key, klass in rules:
+ if key in spec:
+ return klass(env)
+
+ if 'action' in spec:
+ rules2 = {
+ 'populate_systree': PopulateSystreeAction,
+ 'create_workspace': CreateWorkspaceAction,
+ 'git': GitAction,
+ }
+ kind = spec['action']
+ klass = rules2.get(kind)
+ if klass:
+ return klass(env)
+
raise UnknownStepError('Unknown action %r' % spec)
@@ -290,6 +300,38 @@ class PopulateSystreeAction(Action): # pragma: no cover
return exit_code
+class GitAction(Action): # pragma: no cover
+
+ def encode_parameters(self, params):
+ pass
+
+ def execute(self, params, step):
+ env = self.get_env()
+ workspace = env.get_workspace_directory()
+
+ git_dir = params.get('git_dir')
+ if git_dir is None:
+ env.report(1, 'git_dir not provided\n')
+ if git_dir.startswith('/') or '..' in git_dir:
+ env.report(1, 'git_dir not acceptable\n')
+
+ git_url = params.get('git_url')
+ if git_url is None:
+ env.report(1, 'git_url not provided\n')
+
+ pathname = os.path.join(workspace, git_dir)
+ if os.path.exists(pathname):
+ argv = ['git', 'remote', '-v', 'update', '--prune']
+ cwd = pathname
+ else:
+ argv = ['git', 'clone', '-v', git_url, git_dir]
+ cwd = workspace
+
+ exit_code = env.host_runcmd(argv, cwd=cwd)
+ env.report(exit_code, 'git finished (exit code %d)\n' % exit_code)
+ return exit_code
+
+
def make_directory_empty(env, dirname):
return env.runcmd(
['sudo', 'find', dirname, '-mindepth', '1', '-delete'])
diff --git a/ick2/actions_tests.py b/ick2/actions_tests.py
index 8220fe2..06c07f5 100644
--- a/ick2/actions_tests.py
+++ b/ick2/actions_tests.py
@@ -123,7 +123,7 @@ class ActionFactoryTests(unittest.TestCase):
self.assertTrue(isinstance(action, ick2.ArchiveWorkspaceAction))
self.assertTrue(isinstance(action.get_env(), ick2.HostEnvironment))
- def test_creates_populate_sysgtre_action_on_host(self):
+ def test_creates_populate_systree_action_on_host(self):
spec = {
'action': 'populate_systree',
}
@@ -131,6 +131,14 @@ class ActionFactoryTests(unittest.TestCase):
self.assertTrue(isinstance(action, ick2.PopulateSystreeAction))
self.assertTrue(isinstance(action.get_env(), ick2.HostEnvironment))
+ def test_creates_git_action_on_host(self):
+ spec = {
+ 'action': 'git',
+ }
+ action = self.af.create_action(spec, self.project)
+ self.assertTrue(isinstance(action, ick2.GitAction))
+ self.assertTrue(isinstance(action.get_env(), ick2.HostEnvironment))
+
def test_raises_exception_for_unknown_step(self):
with self.assertRaises(ick2.UnknownStepError):
self.af.create_action({}, self.project)