Fix Command Object
authorFred <fmcell@gmail.com>
Fri, 1 Mar 2013 13:24:50 +0000 (21:24 +0800)
committerFred <fmcell@gmail.com>
Fri, 1 Mar 2013 13:24:50 +0000 (21:24 +0800)
lib/commands/__init__.py
lib/commands/fix.py [new file with mode: 0644]

index 646086b..f78e5e0 100644 (file)
@@ -28,3 +28,4 @@ from backup import BackupCommand
 from behat import BehatCommand
 from config import ConfigCommand
 from create import CreateCommand
+from fix import FixCommand
diff --git a/lib/commands/fix.py b/lib/commands/fix.py
new file mode 100644 (file)
index 0000000..3a98cfa
--- /dev/null
@@ -0,0 +1,82 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+Moodle Development Kit
+
+Copyright (c) 2013 Frédéric Massart - FMCorz.net
+
+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/>.
+
+http://github.com/FMCorz/mdk
+"""
+
+
+from lib.command import Command
+from lib.tools import debug
+
+
+class FixCommand(Command):
+
+    _arguments = [
+        (
+            ['issue'],
+            {
+                'help': 'tracker issue or issue number'
+            }
+        ),
+        (
+            ['suffix'],
+            {
+                'default': '',
+                'help': 'suffix of the branch',
+                'nargs': '?'
+            }
+        ),
+        (
+            ['-n', '--name'],
+            {
+                'default': None,
+                'help': 'name of the instance',
+                'metavar': 'name'
+            }
+        )
+    ]
+    _description = 'Creates a branch associated to an MDL issue'
+
+    def run(self, args):
+
+        # Loading instance
+        M = self.resolve(args.name)
+        if not M:
+            raise Exception('This is not a Moodle instance')
+
+        # Branch name
+        branch = M.generateBranchName(args.issue, suffix=args.suffix)
+
+        # Track
+        track = '%s/%s' % (self.C.get('upstreamRemote'), M.get('stablebranch'))
+
+        # Git repo
+        repo = M.git()
+
+        # Creating and checking out the new branch
+        if not repo.hasBranch(branch):
+            if not repo.createBranch(branch, track):
+                raise Exception('Could not create branch %s' % branch)
+
+        if not repo.checkout(branch):
+            raise Exception('Error while checkout out branch %s' % branch)
+
+        debug('Branch %s checked out' % branch)