drop --include-untracked and print more friendly info
authorZhang Qiang <qiang.z.zhang@intel.com>
Fri, 13 Jul 2012 05:29:33 +0000 (13:29 +0800)
committerZhang Qiang <qiang.z.zhang@intel.com>
Fri, 13 Jul 2012 05:29:33 +0000 (13:29 +0800)
--commit can't be specified together with --include-uncommited.
give warning if no --include-uncommited specified and current git
tree is not clean, and print changed and untracked files.

gitbuildsys/cmd_build.py
gitbuildsys/cmd_export.py
gitbuildsys/cmd_remotebuild.py
tools/gbs

index 00f1e2d..82ab376 100644 (file)
@@ -233,10 +233,38 @@ def do(opts, args):
     if len(args) == 1:
         workdir = os.path.abspath(args[0])
 
+    if opts.commit and opts.include_uncommited:
+        raise errors.Usage('--commit can\'t be specified together with '\
+                           '--include-uncommited')
+
     try:
         repo = RpmGitRepository(workdir)
         if opts.commit:
             repo.rev_parse(opts.commit)
+        is_clean, out = repo.is_clean()
+        status = repo.status()
+        untracked_files = status['??']
+        uncommitted_files = []
+        for stat in status:
+            if stat == '??':
+                continue
+            uncommitted_files.extend(status[stat])
+        if not is_clean and not opts.include_uncommited:
+            if untracked_files:
+                msger.warning('the following untracked files would be not be '\
+                           'included:\n   %s' % '\n   '.join(untracked_files))
+            if uncommitted_files:
+                msger.warning('the following uncommited changes would not be '\
+                           'included:\n   %s' % '\n   '.join(uncommitted_files))
+            msger.warning('you can specify \'--include-uncommited\' option to '\
+                          'include these uncommited and untracked files.')
+        if opts.include_uncommited:
+            if untracked_files:
+                msger.info('the following untracked files would be included'  \
+                           ':\n   %s' % '\n   '.join(untracked_files))
+            if uncommitted_files:
+                msger.info('the following uncommited changes would be included'\
+                           ':\n   %s' % '\n   '.join(uncommitted_files))
     except GitRepositoryError, err:
         msger.error(str(err))
 
@@ -379,8 +407,6 @@ def do(opts, args):
         if opts.commit:
             commit = opts.commit
         elif opts.include_uncommited:
-            commit = 'WC.TRACKED'
-        elif opts.include_untracked:
             commit = 'WC.UNTRACKED'
         else:
             commit = 'HEAD'
index 8acf6bf..5576a6c 100644 (file)
@@ -56,10 +56,38 @@ def do(opts, args):
     if len(args) == 1:
         workdir = os.path.abspath(args[0])
 
+    if opts.commit and opts.include_uncommited:
+        raise errors.Usage('--commit can\'t be specified together with '\
+                           '--include-uncommited')
+
     try:
         repo = RpmGitRepository(workdir)
         if opts.commit:
             repo.rev_parse(opts.commit)
+        is_clean, out = repo.is_clean()
+        status = repo.status()
+        untracked_files = status['??']
+        uncommitted_files = []
+        for stat in status:
+            if stat == '??':
+                continue
+            uncommitted_files.extend(status[stat])
+        if not is_clean and not opts.include_uncommited:
+            if untracked_files:
+                msger.warning('the following untracked files would be not be '\
+                           'included:\n   %s' % '\n   '.join(untracked_files))
+            if uncommitted_files:
+                msger.warning('the following uncommited changes would not be '\
+                           'included:\n   %s' % '\n   '.join(uncommitted_files))
+            msger.warning('you can specify \'--include-uncommited\' option to '\
+                          'include these uncommited and untracked files.')
+        if opts.include_uncommited:
+            if untracked_files:
+                msger.info('the following untracked files would be included'  \
+                           ':\n   %s' % '\n   '.join(untracked_files))
+            if uncommitted_files:
+                msger.info('the following uncommited changes would be included'\
+                           ':\n   %s' % '\n   '.join(uncommitted_files))
     except GitRepositoryError, err:
         msger.error(str(err))
 
@@ -84,8 +112,6 @@ def do(opts, args):
         if opts.commit:
             commit = opts.commit
         elif opts.include_uncommited:
-            commit = 'WC.TRACKED'
-        elif opts.include_untracked:
             commit = 'WC.UNTRACKED'
         else:
             commit = 'HEAD'
index a99a374..862334b 100644 (file)
@@ -75,10 +75,39 @@ def do(opts, args):
         msger.error('empty user is not allowed for remotebuild, '\
                     'please add user/passwd to gbs conf, and try again')
 
+    if opts.commit and opts.include_uncommited:
+        raise errors.Usage('--commit can\'t be specified together with '\
+                           '--include-uncommited')
+
     try:
         repo = repository.GitRepository(workdir)
         if opts.commit:
             repo.rev_parse(opts.commit)
+        is_clean, out = repo.is_clean()
+        status = repo.status()
+        untracked_files = status['??']
+        uncommitted_files = []
+        for stat in status:
+            if stat == '??':
+                continue
+            uncommitted_files.extend(status[stat])
+        if not is_clean and not opts.include_uncommited and not \
+           (opts.buildlog or opts.status):
+            if untracked_files:
+                msger.warning('the following untracked files would be not be '\
+                           'included:\n   %s' % '\n   '.join(untracked_files))
+            if uncommitted_files:
+                msger.warning('the following uncommited changes would not be '\
+                           'included:\n   %s' % '\n   '.join(uncommitted_files))
+            msger.warning('you can specify \'--include-uncommited\' option to '\
+                          'include these uncommited and untracked files.')
+        if opts.include_uncommited and not (opts.buildlog or opts.status):
+            if untracked_files:
+                msger.info('the following untracked files would be included'  \
+                           ':\n   %s' % '\n   '.join(untracked_files))
+            if uncommitted_files:
+                msger.info('the following uncommited changes would be included'\
+                           ':\n   %s' % '\n   '.join(uncommitted_files))
     except repository.GitRepositoryError, err:
         msger.error(str(err))
 
@@ -188,8 +217,6 @@ def do(opts, args):
         if opts.commit:
             commit = opts.commit
         elif opts.include_uncommited:
-            commit = 'WC.TRACKED'
-        elif opts.include_untracked:
             commit = 'WC.UNTRACKED'
         else:
             commit = 'HEAD'
index 7865e22..72be3b5 100755 (executable)
--- a/tools/gbs
+++ b/tools/gbs
@@ -134,12 +134,6 @@ class Gbs(cmdln.Cmdln):
                   dest='include_uncommited',
                   help='uncommited changes would be included while '\
                        'generating tar ball')
-    @cmdln.option('--include-untracked',
-                  action='store_true',
-                  default=False,
-                  dest='include_untracked',
-                  help='untracked files would be included while '\
-                       'generating tar ball')
     def do_export(self, _subcmd, opts, *args):
         """${cmd_name}: export files and prepare for build
 
@@ -218,12 +212,6 @@ class Gbs(cmdln.Cmdln):
                   dest='include_uncommited',
                   help='uncommited changes would be included while '\
                        'generating tar ball')
-    @cmdln.option('--include-untracked',
-                  action='store_true',
-                  default=False,
-                  dest='include_untracked',
-                  help='untracked files would be included while '\
-                       'generating tar ball')
     @cmdln.option('--debuginfo',
                   action='store_true',
                   default=False,
@@ -318,12 +306,6 @@ class Gbs(cmdln.Cmdln):
                   dest='include_uncommited',
                   help='uncommited changes would be included while '\
                        'generating tar ball')
-    @cmdln.option('--include-untracked',
-                  action='store_true',
-                  default=False,
-                  dest='include_untracked',
-                  help='untracked files would be included while '\
-                       'generating tar ball')
     def do_remotebuild(self, subcmd, opts, *args):
         """${cmd_name}: remote build package