[PATCH] Support .gitignore
authorPaolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Fri, 2 Sep 2005 09:25:17 +0000 (11:25 +0200)
committerCatalin Marinas <catalin.marinas@gmail.com>
Fri, 2 Sep 2005 16:17:32 +0000 (17:17 +0100)
Add support in stgit for .git/exclude like cogito does. Additionally, add
-x option to avoid excluding any file from listing, as in cogito.

Signed-off-by: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
stgit/commands/status.py
stgit/git.py

index 15fbcf3..c0b1a8e 100644 (file)
@@ -54,6 +54,9 @@ options = [make_option('-m', '--modified',
                        action = 'store_true'),
            make_option('-u', '--unknown',
                        help = 'show unknown files only',
+                       action = 'store_true'),
+           make_option('-x', '--noexclude',
+                       help = 'do not exclude any files from listing',
                        action = 'store_true')]
 
 
@@ -61,4 +64,4 @@ def func(parser, options, args):
     """Show the tree status
     """
     git.status(args, options.modified, options.new, options.deleted,
-               options.conflict, options.unknown)
+               options.conflict, options.unknown, options.noexclude)
index 5abe902..c8339e0 100644 (file)
@@ -155,7 +155,7 @@ def __run(cmd, args=None):
 def __check_base_dir():
     return os.path.isdir(base_dir)
 
-def __tree_status(files = [], tree_id = 'HEAD', unknown = False):
+def __tree_status(files = [], tree_id = 'HEAD', unknown = False, noexclude = True):
     """Returns a list of pairs - [status, filename]
     """
     os.system('git-update-cache --refresh > /dev/null')
@@ -165,13 +165,16 @@ def __tree_status(files = [], tree_id = 'HEAD', unknown = False):
     # unknown files
     if unknown:
         exclude_file = os.path.join(base_dir, 'exclude')
+        base_exclude = [ '--exclude=*.[ao]', '--exclude=.*' '--exclude=TAGS',
+                        '--exclude=tags', '--exclude=*~', '--exclude=#*',
+                        '--exclude-per-directory=.gitignore' ]
         extra_exclude = []
         if os.path.exists(exclude_file):
             extra_exclude.append('--exclude-from=%s' % exclude_file)
-        lines = _output_lines(['git-ls-files', '--others',
-                        '--exclude=*.[ao]', '--exclude=.*'
-                        '--exclude=TAGS', '--exclude=tags', '--exclude=*~',
-                        '--exclude=#*'] + extra_exclude)
+        if noexclude:
+            extra_exclude = base_exclude = []
+        lines = _output_lines(['git-ls-files', '--others' ] + base_exclude
+                        + extra_exclude)
         cache_files += [('?', line.strip()) for line in lines]
 
     # conflicted files
@@ -343,10 +346,10 @@ def merge(base, head1, head2):
         raise GitException, 'git-merge-cache failed (possible conflicts)'
 
 def status(files = [], modified = False, new = False, deleted = False,
-           conflict = False, unknown = False):
+           conflict = False, unknown = False, noexclude = False):
     """Show the tree status
     """
-    cache_files = __tree_status(files, unknown = True)
+    cache_files = __tree_status(files, unknown = True, noexclude = noexclude)
     all = not (modified or new or deleted or conflict or unknown)
 
     if not all: