Add patch editing command
[stgit] / stgit / git.py
index f315b05..6c55127 100644 (file)
@@ -26,7 +26,6 @@ from stgit.utils import *
 from stgit.out import *
 from stgit.run import *
 from stgit.config import config
-from sets import Set
 
 # git exception class
 class GitException(Exception):
@@ -181,7 +180,8 @@ def tree_status(files = None, tree_id = 'HEAD', unknown = False,
 
     # unknown files
     if unknown:
-        cmd = ['git-ls-files', '-z', '--others', '--directory']
+        cmd = ['git-ls-files', '-z', '--others', '--directory',
+               '--no-empty-directory']
         if not noexclude:
             cmd += ['--exclude=%s' % s for s in
                     ['*.[ao]', '*.pyc', '.*', '*~', '#*', 'TAGS', 'tags']]
@@ -191,7 +191,7 @@ def tree_status(files = None, tree_id = 'HEAD', unknown = False,
                     if os.path.exists(fn)]
 
         lines = GRun(*cmd).raw_output().split('\0')
-        cache_files += [('?', line) for line in lines]
+        cache_files += [('?', line) for line in lines if line]
 
     # conflicted files
     conflicts = get_conflicts()
@@ -628,7 +628,8 @@ def apply_diff(rev1, rev2, check_index = True, files = None):
     diff_str = diff(files, rev1, rev2)
     if diff_str:
         try:
-            GRun('git-apply', *index_opt).raw_input(diff_str).no_output()
+            GRun('git-apply', *index_opt).raw_input(
+                diff_str).discard_stderr().no_output()
         except GitRunException:
             return False
 
@@ -761,9 +762,11 @@ def diff(files = None, rev1 = 'HEAD', rev2 = None, diff_flags = []):
     else:
         return ''
 
+# TODO: take another parameter representing a diff string as we
+# usually invoke git.diff() form the calling functions
 def diffstat(files = None, rev1 = 'HEAD', rev2 = None):
     """Return the diffstat between rev1 and rev2."""
-    return GRun('git-apply', '--stat'
+    return GRun('git-apply', '--stat', '--summary'
                 ).raw_input(diff(files, rev1, rev2)).raw_output()
 
 def files(rev1, rev2, diff_flags = []):
@@ -953,15 +956,14 @@ def __remotes_from_dir(dir):
     if os.path.exists(d):
         return os.listdir(d)
     else:
-        return None
+        return []
 
 def remotes_list():
     """Return the list of remotes in the repository
     """
-
-    return Set(__remotes_from_config()) | \
-           Set(__remotes_from_dir('remotes')) | \
-           Set(__remotes_from_dir('branches'))
+    return (set(__remotes_from_config())
+            | set(__remotes_from_dir('remotes'))
+            | set(__remotes_from_dir('branches')))
 
 def remotes_local_branches(remote):
     """Returns the list of local branches fetched from given remote