summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--distixlib/__init__.py2
-rw-r--r--distixlib/git.py37
-rw-r--r--distixlib/plugins/init_plugin.py16
-rw-r--r--without-tests1
4 files changed, 43 insertions, 13 deletions
diff --git a/distixlib/__init__.py b/distixlib/__init__.py
index bc6326b..a500bff 100644
--- a/distixlib/__init__.py
+++ b/distixlib/__init__.py
@@ -38,6 +38,8 @@ from ticket_store import (
TicketHasNoId,
TicketAlreadyInStoreError,
TicketNotInStoreError)
+from git import Git
+
# Export only the explicitly imported symbols.
__all__ = locals()
diff --git a/distixlib/git.py b/distixlib/git.py
new file mode 100644
index 0000000..beee8dd
--- /dev/null
+++ b/distixlib/git.py
@@ -0,0 +1,37 @@
+# Copyright 2014 Lars Wirzenius
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# =*= License: GPL-3+ =*=
+
+
+import cliapp
+
+
+class Git(object):
+
+ '''An interface to all git operations distix needs.'''
+
+ def __init__(self, dirname):
+ self._dirname = dirname
+
+ def init(self):
+ self._git(['init', self._dirname])
+
+ def add_and_commit(self, filenames, commit_msg):
+ self._git(['add'] + filenames, cwd=self._dirname)
+ self._git(['commit', '-m', commit_msg] + filenames, cwd=self._dirname)
+
+ def _git(self, args, **kwargs):
+ cliapp.runcmd(['git'] + args, stdout=None, stderr=None, **kwargs)
diff --git a/distixlib/plugins/init_plugin.py b/distixlib/plugins/init_plugin.py
index a168234..b2d3ef1 100644
--- a/distixlib/plugins/init_plugin.py
+++ b/distixlib/plugins/init_plugin.py
@@ -43,8 +43,9 @@ class InitPlugin(cliapp.Plugin):
os.mkdir(dirname)
self._create_repo_yaml(dirname, description)
- self._git_init(dirname)
- self._git_add_and_commit_files(dirname)
+ git = distixlib.Git(dirname)
+ git.init()
+ git.add_and_commit(['.'], 'distix initial commit')
def _create_repo_yaml(self, dirname, description):
metadata = distixlib.Metadata()
@@ -53,14 +54,3 @@ class InitPlugin(cliapp.Plugin):
filename = os.path.join(dirname, 'repo.yaml')
saver = distixlib.MetadataSaver()
saver.save_to_file(filename, metadata)
-
- def _git_init(self, dirname):
- cliapp.runcmd(['git', 'init'], cwd=dirname, stdout=None, stderr=None)
-
- def _git_add_and_commit_files(self, dirname):
- cliapp.runcmd(
- ['git', 'add', '.'],
- cwd=dirname, stdout=None, stderr=None)
- cliapp.runcmd(
- ['git', 'commit', '-m', 'distix initial commit'],
- cwd=dirname, stdout=None, stderr=None)
diff --git a/without-tests b/without-tests
index 7abf6e0..09d0055 100644
--- a/without-tests
+++ b/without-tests
@@ -10,3 +10,4 @@ distixlib/plugins/reply_plugin.py
distixlib/plugins/set_plugin.py
distixlib/plugins/show_plugin.py
distixlib/constants.py
+distixlib/git.py