From a51f26e5142d6c5f40984cd374f0dea7580a4235 Mon Sep 17 00:00:00 2001
From: Lin Jen-Shin <godfat@godfat.org>
Date: Thu, 8 Dec 2016 01:12:49 +0800
Subject: [PATCH] Use commit_file for commit_dir

---
 app/models/repository.rb | 38 ++++++++++++++++++++++++--------------
 1 file changed, 24 insertions(+), 14 deletions(-)

diff --git a/app/models/repository.rb b/app/models/repository.rb
index c05cfb271c7..6246630300c 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -749,22 +749,32 @@ class Repository
     user, path, message, branch,
     author_email: nil, author_name: nil,
     source_branch: nil, source_project: project)
-    GitOperationService.new(user, self).with_branch(
+    if branch_exists?(branch)
+      # tree_entry is private
+      entry = raw_repository.send(:tree_entry, commit(branch), path)
+
+      if entry
+        if entry[:type] == :blob
+          raise Gitlab::Git::Repository::InvalidBlobName.new(
+            "Directory already exists as a file")
+        else
+          raise Gitlab::Git::Repository::InvalidBlobName.new(
+            "Directory already exists")
+        end
+      end
+    end
+
+    commit_file(
+      user,
+      "#{Gitlab::Git::PathHelper.normalize_path(path)}/.gitkeep",
+      '',
+      message,
       branch,
+      false,
+      author_email: author_email,
+      author_name: author_name,
       source_branch: source_branch,
-      source_project: source_project) do |ref|
-      options = {
-        commit: {
-          branch: ref,
-          message: message,
-          update_ref: false
-        }
-      }
-
-      options.merge!(get_committer_and_author(user, email: author_email, name: author_name))
-
-      raw_repository.mkdir(path, options)
-    end
+      source_project: source_project)
   end
   # rubocop:enable Metrics/ParameterLists
 
-- 
GitLab