fix import-orig twice issue
authorZhang Qiang <qiang.z.zhang@intel.com>
Thu, 22 Mar 2012 03:38:17 +0000 (11:38 +0800)
committerZhang Qiang <qiang.z.zhang@intel.com>
Thu, 22 Mar 2012 03:38:17 +0000 (11:38 +0800)
without this patch, all the commits and files would be removed
unexpectlly.

gitbuildsys/cmd_import_orig.py
gitbuildsys/git.py

index 535636c..f4c2912 100644 (file)
@@ -1,4 +1,4 @@
-#!/usr/bin/python -tt
+/!/usr/bin/python -tt
 # vim: ai ts=4 sts=4 et sw=4
 #
 # Copyright (c) 2012 Intel, Inc.
@@ -58,7 +58,6 @@ def do(opts, args):
     (pkgname, pkgversion) = upstream.guess_version() or ('', '')
 
     try:
-        import pdb;pdb.set_trace()
         upstream.unpack(tardir)
     except errors.UnpackError:
         msger.error('Unpacking %s fail' % tarball)
@@ -88,6 +87,9 @@ def do(opts, args):
         msger.info('create tag named: %s' % tag)
         repo.create_tag(tag, msg, commit)
 
+    if commit is None:
+        msger.info('dont need import, already in version %s' % tag)
+
     repo.checkout_branch('master')
     
     if commit and not opts.no_merge:
index 02c321d..e1359ec 100644 (file)
@@ -122,7 +122,8 @@ class Git:
 
         gitsts = self.status()
         if 'M ' in gitsts or ' M' in gitsts or \
-           'A ' in gitsts or ' A ' in gitsts:
+           'A ' in gitsts or ' A' in gitsts or \
+           'D ' in gitsts or ' D' in gitsts:
             return False
         else:
             return True
@@ -176,11 +177,10 @@ class Git:
         options = ['.', '-f']
         self._exec_git("add", options)
 
-        if self.is_clean():
-            return None
-
-        options = ['--quiet','-a', '-m %s' % msg,]
-        self._exec_git("commit", options)
+        changed = not self.is_clean()
+        if changed:
+            options = ['--quiet','-a', '-m %s' % msg,]
+            self._exec_git("commit", options)
 
         commit_id = self._exec_git('log', ['--oneline', '-1']).split()[0]
 
@@ -194,7 +194,7 @@ class Git:
 
         self._exec_git('reset', ['--hard', commit_id])
 
-        return commit_id
+        return commit_id if changed else None
 
     def find_tag(self, tag):
         """find the specify version from the repository"""
@@ -213,7 +213,7 @@ class Git:
 
     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):
+        if self.rev_parse(commit) is None and not self.find_tag(commit):
             raise errors.GitError('%s is invalid commit ID or tag' % commit)
 
         options = [commit]