@@ -6,22 +6,18 @@ package repository
6
6
import (
7
7
"context"
8
8
"fmt"
9
- "os"
10
9
"path/filepath"
11
10
"sort"
12
11
"strings"
13
- "time"
14
12
15
13
issues_model "code.gitea.io/gitea/models/issues"
16
14
repo_model "code.gitea.io/gitea/models/repo"
17
- user_model "code.gitea.io/gitea/models/user"
18
15
"code.gitea.io/gitea/modules/git"
19
16
"code.gitea.io/gitea/modules/label"
20
17
"code.gitea.io/gitea/modules/log"
21
18
"code.gitea.io/gitea/modules/options"
22
19
"code.gitea.io/gitea/modules/setting"
23
20
"code.gitea.io/gitea/modules/util"
24
- asymkey_service "code.gitea.io/gitea/services/asymkey"
25
21
)
26
22
27
23
type OptionFile struct {
@@ -124,70 +120,6 @@ func LoadRepoConfig() error {
124
120
return nil
125
121
}
126
122
127
- // InitRepoCommit temporarily changes with work directory.
128
- func InitRepoCommit (ctx context.Context , tmpPath string , repo * repo_model.Repository , u * user_model.User , defaultBranch string ) (err error ) {
129
- commitTimeStr := time .Now ().Format (time .RFC3339 )
130
-
131
- sig := u .NewGitSig ()
132
- // Because this may call hooks we should pass in the environment
133
- env := append (os .Environ (),
134
- "GIT_AUTHOR_NAME=" + sig .Name ,
135
- "GIT_AUTHOR_EMAIL=" + sig .Email ,
136
- "GIT_AUTHOR_DATE=" + commitTimeStr ,
137
- "GIT_COMMITTER_DATE=" + commitTimeStr ,
138
- )
139
- committerName := sig .Name
140
- committerEmail := sig .Email
141
-
142
- if stdout , _ , err := git .NewCommand (ctx , "add" , "--all" ).
143
- SetDescription (fmt .Sprintf ("initRepoCommit (git add): %s" , tmpPath )).
144
- RunStdString (& git.RunOpts {Dir : tmpPath }); err != nil {
145
- log .Error ("git add --all failed: Stdout: %s\n Error: %v" , stdout , err )
146
- return fmt .Errorf ("git add --all: %w" , err )
147
- }
148
-
149
- cmd := git .NewCommand (ctx , "commit" , "--message=Initial commit" ).
150
- AddOptionFormat ("--author='%s <%s>'" , sig .Name , sig .Email )
151
-
152
- sign , keyID , signer , _ := asymkey_service .SignInitialCommit (ctx , tmpPath , u )
153
- if sign {
154
- cmd .AddOptionFormat ("-S%s" , keyID )
155
-
156
- if repo .GetTrustModel () == repo_model .CommitterTrustModel || repo .GetTrustModel () == repo_model .CollaboratorCommitterTrustModel {
157
- // need to set the committer to the KeyID owner
158
- committerName = signer .Name
159
- committerEmail = signer .Email
160
- }
161
- } else {
162
- cmd .AddArguments ("--no-gpg-sign" )
163
- }
164
-
165
- env = append (env ,
166
- "GIT_COMMITTER_NAME=" + committerName ,
167
- "GIT_COMMITTER_EMAIL=" + committerEmail ,
168
- )
169
-
170
- if stdout , _ , err := cmd .
171
- SetDescription (fmt .Sprintf ("initRepoCommit (git commit): %s" , tmpPath )).
172
- RunStdString (& git.RunOpts {Dir : tmpPath , Env : env }); err != nil {
173
- log .Error ("Failed to commit: %v: Stdout: %s\n Error: %v" , cmd .String (), stdout , err )
174
- return fmt .Errorf ("git commit: %w" , err )
175
- }
176
-
177
- if len (defaultBranch ) == 0 {
178
- defaultBranch = setting .Repository .DefaultBranch
179
- }
180
-
181
- if stdout , _ , err := git .NewCommand (ctx , "push" , "origin" ).AddDynamicArguments ("HEAD:" + defaultBranch ).
182
- SetDescription (fmt .Sprintf ("initRepoCommit (git push): %s" , tmpPath )).
183
- RunStdString (& git.RunOpts {Dir : tmpPath , Env : InternalPushingEnvironment (u , repo )}); err != nil {
184
- log .Error ("Failed to push back to HEAD: Stdout: %s\n Error: %v" , stdout , err )
185
- return fmt .Errorf ("git push: %w" , err )
186
- }
187
-
188
- return nil
189
- }
190
-
191
123
func CheckInitRepository (ctx context.Context , owner , name , objectFormatName string ) (err error ) {
192
124
// Somehow the directory could exist.
193
125
repoPath := repo_model .RepoPath (owner , name )
0 commit comments