GitRepository/add_files: add new option 'untracked'
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Fri, 6 Jul 2012 12:55:19 +0000 (15:55 +0300)
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Fri, 14 Nov 2014 12:22:10 +0000 (14:22 +0200)
With this option you can either only update already tracked files to
index the (untracked=False) or add new files, too.

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
gbp/git/repository.py
tests/test_GitRepository.py

index e7687bd..b6a05e2 100644 (file)
@@ -1323,7 +1323,7 @@ class GitRepository(object):
 
 #{ Files
 
-    def add_files(self, paths, force=False, index_file=None, work_tree=None):
+    def add_files(self, paths, force=False, untracked=True, index_file=None, work_tree=None):
         """
         Add files to a the repository
 
@@ -1331,6 +1331,8 @@ class GitRepository(object):
         @type paths: list or C{str}
         @param force: add files even if they would be ignored by .gitignore
         @type force: C{bool}
+        @param untracked: add also previously untracked files
+        @type untracked: C{bool}
         @param index_file: alternative index file to use
         @param work_tree: alternative working tree to use
         """
@@ -1338,7 +1340,7 @@ class GitRepository(object):
 
         args = GitArgs()
         args.add_true(force, '-f')
-        args.add('-A')
+        args.add_cond(untracked, '-A', '-u')
         args.add(paths)
 
         if index_file:
index f3a83ff..b1a1432 100644 (file)
@@ -68,6 +68,7 @@ def test_add_files():
          - L{gbp.git.GitRepository.add_files}
          - L{gbp.git.GitRepository.commit_all}
          - L{gbp.git.GitRepository.is_clean}
+         - L{gbp.git.GitRepository.status}
 
     Properties tested:
          - L{gbp.git.GitRepository.head}
@@ -80,7 +81,12 @@ def test_add_files():
     False
     >>> repo.is_clean(ignore_untracked=True)[0]
     True
+    >>> repo.add_files('testfile', force=True, untracked=False)
+    >>> repo.status().items()
+    [('??', ['testfile'])]
     >>> repo.add_files(repo.path, force=True)
+    >>> repo.status().items()
+    [('A ', ['testfile'])]
     >>> repo.commit_all(msg="foo")
     >>> repo.is_clean()[0]
     True