repository: add create_tree.
authorwanchao-xu <wanchao.xu@samsung.com>
Fri, 19 Apr 2024 06:32:50 +0000 (14:32 +0800)
committerwanchao-xu <wanchao.xu@samsung.com>
Fri, 19 Apr 2024 06:32:50 +0000 (14:32 +0800)
Change-Id: I41d85944f325858233efd27700eefca6baa1466d
Signed-off-by: wanchao-xu <wanchao.xu@samsung.com>
gbp/git/repository.py

index edbdfe9f2ddd8a18a6e887313b0db8501c959b62..e7f98cfa4f0519b0a00e1cd0c4b38970af4db3a2 100644 (file)
@@ -1514,6 +1514,24 @@ class GitRepository(object):
             files = [files]
         self._commit(msg=msg, args=files, author_info=author_info)
 
+    def create_tree(self, unpack_dir):
+        """
+        Create a tree object out of a directory content
+
+        @param unpack_dir: content to add
+        @type unpack_dir: C{str}
+        @return: the tree object hash
+        @rtype: C{str}
+        """
+        git_index_file = os.path.join(self.path, self._git_dir, 'gbp_index')
+        try:
+            os.unlink(git_index_file)
+        except OSError:
+            pass
+        self.add_files('.', force=True, index_file=git_index_file,
+                       work_tree=unpack_dir)
+        return self.write_tree(git_index_file)
+
     def commit_dir(self, unpack_dir, msg, branch, other_parents=None,
                    author={}, committer={}, create_missing_branch=False):
         """
@@ -1536,15 +1554,7 @@ class GitRepository(object):
             doesn't already exist.
         @type create_missing_branch: C{bool}
         """
-
-        git_index_file = os.path.join(self.path, self._git_dir, 'gbp_index')
-        try:
-            os.unlink(git_index_file)
-        except OSError:
-            pass
-        self.add_files('.', force=True, index_file=git_index_file,
-                       work_tree=unpack_dir)
-        tree = self.write_tree(git_index_file)
+        tree = self.create_tree(unpack_dir)
 
         if branch:
             try: