@@ -17,7 +17,6 @@ import (
1717	repo_model "code.gitea.io/gitea/models/repo" 
1818	user_model "code.gitea.io/gitea/models/user" 
1919	"code.gitea.io/gitea/modules/git" 
20- 	"code.gitea.io/gitea/modules/git/gitcmd" 
2120	"code.gitea.io/gitea/modules/gitrepo" 
2221	"code.gitea.io/gitea/modules/log" 
2322	"code.gitea.io/gitea/modules/process" 
@@ -109,54 +108,9 @@ func IsErrWontSign(err error) bool {
109108	return  ok 
110109}
111110
112- // SigningKey returns the KeyID and git Signature for the repo 
113- func  SigningKey (ctx  context.Context , repoPath  string ) (* git.SigningKey , * git.Signature ) {
114- 	if  setting .Repository .Signing .SigningKey  ==  "none"  {
115- 		return  nil , nil 
116- 	}
117- 
118- 	if  setting .Repository .Signing .SigningKey  ==  "default"  ||  setting .Repository .Signing .SigningKey  ==  ""  {
119- 		// Can ignore the error here as it means that commit.gpgsign is not set 
120- 		value , _ , _  :=  gitcmd .NewCommand ("config" , "--get" , "commit.gpgsign" ).RunStdString (ctx , & gitcmd.RunOpts {Dir : repoPath })
121- 		sign , valid  :=  git .ParseBool (strings .TrimSpace (value ))
122- 		if  ! sign  ||  ! valid  {
123- 			return  nil , nil 
124- 		}
125- 
126- 		format , _ , _  :=  gitcmd .NewCommand ("config" , "--default" , git .SigningKeyFormatOpenPGP , "--get" , "gpg.format" ).RunStdString (ctx , & gitcmd.RunOpts {Dir : repoPath })
127- 		signingKey , _ , _  :=  gitcmd .NewCommand ("config" , "--get" , "user.signingkey" ).RunStdString (ctx , & gitcmd.RunOpts {Dir : repoPath })
128- 		signingName , _ , _  :=  gitcmd .NewCommand ("config" , "--get" , "user.name" ).RunStdString (ctx , & gitcmd.RunOpts {Dir : repoPath })
129- 		signingEmail , _ , _  :=  gitcmd .NewCommand ("config" , "--get" , "user.email" ).RunStdString (ctx , & gitcmd.RunOpts {Dir : repoPath })
130- 
131- 		if  strings .TrimSpace (signingKey ) ==  ""  {
132- 			return  nil , nil 
133- 		}
134- 
135- 		return  & git.SigningKey {
136- 				KeyID :  strings .TrimSpace (signingKey ),
137- 				Format : strings .TrimSpace (format ),
138- 			}, & git.Signature {
139- 				Name :  strings .TrimSpace (signingName ),
140- 				Email : strings .TrimSpace (signingEmail ),
141- 			}
142- 	}
143- 
144- 	if  setting .Repository .Signing .SigningKey  ==  ""  {
145- 		return  nil , nil 
146- 	}
147- 
148- 	return  & git.SigningKey {
149- 			KeyID :  setting .Repository .Signing .SigningKey ,
150- 			Format : setting .Repository .Signing .SigningFormat ,
151- 		}, & git.Signature {
152- 			Name :  setting .Repository .Signing .SigningName ,
153- 			Email : setting .Repository .Signing .SigningEmail ,
154- 		}
155- }
156- 
157111// PublicSigningKey gets the public signing key within a provided repository directory 
158112func  PublicSigningKey (ctx  context.Context , repoPath  string ) (content , format  string , err  error ) {
159- 	signingKey , _  :=  SigningKey (ctx , repoPath )
113+ 	signingKey , _  :=  git . GetSigningKey (ctx , repoPath )
160114	if  signingKey  ==  nil  {
161115		return  "" , "" , nil 
162116	}
@@ -181,7 +135,7 @@ func PublicSigningKey(ctx context.Context, repoPath string) (content, format str
181135// SignInitialCommit determines if we should sign the initial commit to this repository 
182136func  SignInitialCommit (ctx  context.Context , repoPath  string , u  * user_model.User ) (bool , * git.SigningKey , * git.Signature , error ) {
183137	rules  :=  signingModeFromStrings (setting .Repository .Signing .InitialCommit )
184- 	signingKey , sig  :=  SigningKey (ctx , repoPath )
138+ 	signingKey , sig  :=  git . GetSigningKey (ctx , repoPath )
185139	if  signingKey  ==  nil  {
186140		return  false , nil , nil , & ErrWontSign {noKey }
187141	}
@@ -216,9 +170,8 @@ Loop:
216170
217171// SignWikiCommit determines if we should sign the commits to this repository wiki 
218172func  SignWikiCommit (ctx  context.Context , repo  * repo_model.Repository , u  * user_model.User ) (bool , * git.SigningKey , * git.Signature , error ) {
219- 	repoWikiPath  :=  repo .WikiPath ()
220173	rules  :=  signingModeFromStrings (setting .Repository .Signing .Wiki )
221- 	signingKey , sig  :=  SigningKey (ctx , repoWikiPath )
174+ 	signingKey , sig  :=  gitrepo . GetSigningKey (ctx , repo . WikiStorageRepo () )
222175	if  signingKey  ==  nil  {
223176		return  false , nil , nil , & ErrWontSign {noKey }
224177	}
@@ -271,7 +224,7 @@ Loop:
271224// SignCRUDAction determines if we should sign a CRUD commit to this repository 
272225func  SignCRUDAction (ctx  context.Context , repoPath  string , u  * user_model.User , tmpBasePath , parentCommit  string ) (bool , * git.SigningKey , * git.Signature , error ) {
273226	rules  :=  signingModeFromStrings (setting .Repository .Signing .CRUDActions )
274- 	signingKey , sig  :=  SigningKey (ctx , repoPath )
227+ 	signingKey , sig  :=  git . GetSigningKey (ctx , repoPath )
275228	if  signingKey  ==  nil  {
276229		return  false , nil , nil , & ErrWontSign {noKey }
277230	}
@@ -335,7 +288,7 @@ func SignMerge(ctx context.Context, pr *issues_model.PullRequest, u *user_model.
335288	}
336289	repo  :=  pr .BaseRepo 
337290
338- 	signingKey , signer  :=  SigningKey (ctx , repo . RepoPath () )
291+ 	signingKey , signer  :=  gitrepo . GetSigningKey (ctx , repo )
339292	if  signingKey  ==  nil  {
340293		return  false , nil , nil , & ErrWontSign {noKey }
341294	}
0 commit comments