add find_tag and merge interface, and create upstream branch
authorZhang Qiang <qiang.z.zhang@intel.com>
Fri, 16 Mar 2012 03:22:45 +0000 (11:22 +0800)
committerZhang Qiang <qiang.z.zhang@intel.com>
Fri, 16 Mar 2012 03:22:45 +0000 (11:22 +0800)
gitbuildsys/cmd_import.py
gitbuildsys/git.py

index f60873d..8f04a75 100644 (file)
@@ -95,6 +95,8 @@ def do(opts, args):
                             )
     msger.info('create tag named: %s' % tag)
     repo.create_tag(tag, msg, commit)
+    msger.info('create upstream branch')
+    repo.create_branch('upstream', commit)
 
     packagingdir = '%s/packaging' % upstream.unpacked
     if not os.path.exists(packagingdir):
index d89194d..194b347 100644 (file)
@@ -17,6 +17,7 @@
 # Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
 import os
+import re
 
 # internal modules
 import runner
@@ -174,6 +175,14 @@ class Git:
 
         return commit_id
 
+    def find_tag(self, tag):
+        """find the specify version from the repository"""
+        args = ['-l', tag]
+        ret = self._exec_git('tag', args)
+        if ret:
+            return True
+        return False
+
     def create_tag(self, name, msg, commit):
         """Creat a tag with name at commit""" 
         if self.rev_parse(commit) is None:
@@ -181,6 +190,14 @@ class Git:
         options = [name, '-m %s' % msg, commit]
         self._exec_git('tag', options)
 
+    def merge(self, commit):
+        """ merge the git tree specified by commit to current branch"""
+        if self.rev_parse(commit) is None or not self.find_tag(commit):
+            raise errors.GitError('%s is invalid commit ID or tag' % commit)
+
+        options = [commit]
+        self._exec_git('merge', options)
+
     def archive(self, prefix, tarfname, treeish='HEAD'):
         """Archive git tree from 'treeish', detect archive type
         from the extname of output filename.