From d741316aaeecbafb82434fa9e57ab54e79cbb09d Mon Sep 17 00:00:00 2001
From: Lunny Xiao <xiaolunwen@gmail.com>
Date: Sat, 29 Jun 2019 19:46:25 +0800
Subject: [PATCH] add commitgraph support global default true when git version
 >= 2.18 (#7313)

---
 modules/git/git.go | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/modules/git/git.go b/modules/git/git.go
index bda39da918..fda6f45251 100644
--- a/modules/git/git.go
+++ b/modules/git/git.go
@@ -114,6 +114,18 @@ func Init() error {
 		GitExecutable, "config", "--global", "core.quotepath", "false"); err != nil {
 		return fmt.Errorf("Failed to execute 'git config --global core.quotepath false': %s", stderr)
 	}
+
+	if version.Compare(gitVersion, "2.18", ">=") {
+		if _, stderr, err := process.GetManager().Exec("git.Init(git config --global core.commitGraph true)",
+			GitExecutable, "config", "--global", "core.commitGraph", "true"); err != nil {
+			return fmt.Errorf("Failed to execute 'git config --global core.commitGraph true': %s", stderr)
+		}
+
+		if _, stderr, err := process.GetManager().Exec("git.Init(git config --global gc.writeCommitGraph true)",
+			GitExecutable, "config", "--global", "gc.writeCommitGraph", "true"); err != nil {
+			return fmt.Errorf("Failed to execute 'git config --global gc.writeCommitGraph true': %s", stderr)
+		}
+	}
 	return nil
 }