[Python-modules-commits] [dulwich] 11/19: Silently ignore directories passed to Repo.stage(). Fixes #564

Jelmer Vernooij jelmer at moszumanska.debian.org
Sun Oct 29 17:22:28 UTC 2017


This is an automated email from the git hooks/post-receive script.

jelmer pushed a commit to branch master
in repository dulwich.

commit 2a6d5bb489d51fe5632002476bac3612c5f1030b
Author: Jelmer Vernooij <jelmer at debian.org>
Date:   Wed Oct 18 23:41:27 2017 +0100

    Silently ignore directories passed to Repo.stage(). Fixes #564
---
 NEWS                             |  5 +++++
 dulwich/repo.py                  | 12 +++++++++---
 dulwich/tests/test_repository.py |  6 ++++++
 3 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/NEWS b/NEWS
index d6f0d8d..53715aa 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,11 @@
   * Fix setting of origin in config when non-standard origin is passed into
     ``Repo.clone``. (Kenneth Lareau, #565)
 
+ IMPROVEMENTS
+
+  * Silently ignored directories in ``Repo.stage``.
+    (Jelmer Vernooij, #564)
+
  API CHANGES
 
   * GitFile now raises ``FileLocked`` when encountering a lock
diff --git a/dulwich/repo.py b/dulwich/repo.py
index b2b79e3..2ca70f9 100644
--- a/dulwich/repo.py
+++ b/dulwich/repo.py
@@ -869,9 +869,15 @@ class Repo(BaseRepo):
                 except KeyError:
                     pass  # already removed
             else:
-                blob = blob_from_path_and_stat(full_path, st)
-                self.object_store.add_object(blob)
-                index[tree_path] = index_entry_from_stat(st, blob.id, 0)
+                if not stat.S_ISDIR(st.st_mode):
+                    blob = blob_from_path_and_stat(full_path, st)
+                    self.object_store.add_object(blob)
+                    index[tree_path] = index_entry_from_stat(st, blob.id, 0)
+                else:
+                    try:
+                        del index[tree_path]
+                    except KeyError:
+                        pass
         index.write()
 
     def clone(self, target_path, mkdir=True, bare=False,
diff --git a/dulwich/tests/test_repository.py b/dulwich/tests/test_repository.py
index 314e4a8..6ef9516 100644
--- a/dulwich/tests/test_repository.py
+++ b/dulwich/tests/test_repository.py
@@ -880,6 +880,12 @@ class BuildRepoRootTests(TestCase):
         r.stage(['a'])
         r.stage(['a'])  # double-stage a deleted path
 
+    def test_stage_directory(self):
+        r = self._repo
+        os.mkdir(os.path.join(r.path, 'c'))
+        r.stage(['c'])
+        self.assertEqual(['a'], list(r.open_index()))
+
     @skipIf(sys.platform == 'win32' and sys.version_info[:2] >= (3, 6),
             'tries to implicitly decode as utf8')
     def test_commit_no_encode_decode(self):

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/dulwich.git



More information about the Python-modules-commits mailing list