From ec31ee1c1cd028dc59292e19d4b1c9dd954ba364 Mon Sep 17 00:00:00 2001
From: Mura Li <typeless@users.noreply.github.com>
Date: Thu, 24 Jan 2019 15:43:37 +0800
Subject: Make sure .git/info is created before generating
 .git/info/sparse-cheā€¦ (#5825)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* Make sure .git/info is created before generating .git/info/sparse-checkout

* fix permissions
---
 models/pull.go | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

(limited to 'models')

diff --git a/models/pull.go b/models/pull.go
index e1a69ad2fc..b2cf4b1f44 100644
--- a/models/pull.go
+++ b/models/pull.go
@@ -447,7 +447,11 @@ func (pr *PullRequest) Merge(doer *User, baseGitRepo *git.Repository, mergeStyle
 		return fmt.Errorf("getDiffTree: %v", err)
 	}
 
-	sparseCheckoutListPath := filepath.Join(tmpBasePath, ".git", "info", "sparse-checkout")
+	infoPath := filepath.Join(tmpBasePath, ".git", "info")
+	if err := os.MkdirAll(infoPath, 0700); err != nil {
+		return fmt.Errorf("creating directory failed [%s]: %v", infoPath, err)
+	}
+	sparseCheckoutListPath := filepath.Join(infoPath, "sparse-checkout")
 	if err := ioutil.WriteFile(sparseCheckoutListPath, []byte(sparseCheckoutList), 0600); err != nil {
 		return fmt.Errorf("Writing sparse-checkout file to %s: %v", sparseCheckoutListPath, err)
 	}
-- 
cgit v1.2.3