@@ -91,26 +91,30 @@ func init() {
91
91
if version .Compare (gitVersion , GitVersionRequired , "<" ) {
92
92
panic (fmt .Sprintf ("Git version not supported. Requires version > %v" , GitVersionRequired ))
93
93
}
94
+ }
94
95
96
+ // Init initializes git module
97
+ func Init () error {
95
98
// Git requires setting user.name and user.email in order to commit changes.
96
99
for configKey ,
defaultValue := range map [
string ]
string {
"user.name" :
"Gitea" ,
"user.email" :
"[email protected] " } {
97
100
if stdout , stderr , err := process .GetManager ().Exec ("git.Init(get setting)" , GitExecutable , "config" , "--get" , configKey ); err != nil || strings .TrimSpace (stdout ) == "" {
98
101
// ExitError indicates this config is not set
99
102
if _ , ok := err .(* exec.ExitError ); ok || strings .TrimSpace (stdout ) == "" {
100
103
if _ , stderr , gerr := process .GetManager ().Exec ("git.Init(set " + configKey + ")" , "git" , "config" , "--global" , configKey , defaultValue ); gerr != nil {
101
- panic ( fmt .Sprintf ("Failed to set git %s(%s): %s" , configKey , gerr , stderr ) )
104
+ return fmt .Errorf ("Failed to set git %s(%s): %s" , configKey , gerr , stderr )
102
105
}
103
106
} else {
104
- panic ( fmt .Sprintf ("Failed to get git %s(%s): %s" , configKey , err , stderr ) )
107
+ return fmt .Errorf ("Failed to get git %s(%s): %s" , configKey , err , stderr )
105
108
}
106
109
}
107
110
}
108
111
109
112
// Set git some configurations.
110
113
if _ , stderr , err := process .GetManager ().Exec ("git.Init(git config --global core.quotepath false)" ,
111
114
GitExecutable , "config" , "--global" , "core.quotepath" , "false" ); err != nil {
112
- panic ( fmt .Sprintf ("Failed to execute 'git config --global core.quotepath false': %s" , stderr ) )
115
+ return fmt .Errorf ("Failed to execute 'git config --global core.quotepath false': %s" , stderr )
113
116
}
117
+ return nil
114
118
}
115
119
116
120
// Fsck verifies the connectivity and validity of the objects in the database
0 commit comments