@@ -58,6 +58,52 @@ func createSSHUrl(gitPath string, u *url.URL) *url.URL {
5858 return & u2
5959}
6060
61+ // gitAddChangesDeprecated marks local changes to be ready for commit.
62+ // Deprecated: use "git fast-import" instead for better performance and more control over the commit creation.
63+ func gitAddChangesDeprecated (ctx context.Context , repoPath string , all bool , files ... string ) error {
64+ cmd := gitcmd .NewCommand ().AddArguments ("add" )
65+ if all {
66+ cmd .AddArguments ("--all" )
67+ }
68+ cmd .AddDashesAndList (files ... )
69+ _ , _ , err := cmd .WithDir (repoPath ).RunStdString (ctx )
70+ return err
71+ }
72+
73+ // CommitChangesOptions the options when a commit created
74+ type gitCommitChangesOptions struct {
75+ Committer * git.Signature
76+ Author * git.Signature
77+ Message string
78+ }
79+
80+ // gitCommitChangesDeprecated commits local changes with given committer, author and message.
81+ // If author is nil, it will be the same as committer.
82+ // Deprecated: use "git fast-import" instead for better performance and more control over the commit creation.
83+ func gitCommitChangesDeprecated (ctx context.Context , repoPath string , opts gitCommitChangesOptions ) error {
84+ cmd := gitcmd .NewCommand ()
85+ if opts .Committer != nil {
86+ cmd .AddOptionValues ("-c" , "user.name=" + opts .Committer .Name )
87+ cmd .AddOptionValues ("-c" , "user.email=" + opts .Committer .Email )
88+ }
89+ cmd .AddArguments ("commit" )
90+
91+ if opts .Author == nil {
92+ opts .Author = opts .Committer
93+ }
94+ if opts .Author != nil {
95+ cmd .AddOptionFormat ("--author='%s <%s>'" , opts .Author .Name , opts .Author .Email )
96+ }
97+ cmd .AddOptionFormat ("--message=%s" , opts .Message )
98+
99+ _ , _ , err := cmd .WithDir (repoPath ).RunStdString (ctx )
100+ // No stderr but exit status 1 means nothing to commit.
101+ if gitcmd .IsErrorExitCode (err , 1 ) {
102+ return nil
103+ }
104+ return err
105+ }
106+
61107func onGiteaRun [T testing.TB ](t T , callback func (T , * url.URL )) {
62108 defer tests .PrepareTestEnv (t , 1 )()
63109 s := http.Server {
@@ -128,13 +174,13 @@ func doGitInitTestRepository(dstPath string) func(*testing.T) {
128174 RunStdString (t .Context ())
129175 assert .NoError (t , err )
130176 assert .NoError (t , os .WriteFile (filepath .Join (dstPath , "README.md" ), []byte ("# Testing Repository\n \n Originally created in: " + dstPath ), 0o644 ))
131- assert .NoError (t , git . AddChanges (t .Context (), dstPath , true ))
177+ assert .NoError (t , gitAddChangesDeprecated (t .Context (), dstPath , true ))
132178 signature := git.Signature {
133179 Email : "test@example.com" ,
134180 Name : "test" ,
135181 When : time .Now (),
136182 }
137- assert .NoError (t , git . CommitChanges (t .Context (), dstPath , git. CommitChangesOptions {
183+ assert .NoError (t , gitCommitChangesDeprecated (t .Context (), dstPath , gitCommitChangesOptions {
138184 Committer : & signature ,
139185 Author : & signature ,
140186 Message : "Initial Commit" ,
@@ -181,12 +227,12 @@ func doGitCheckoutWriteFileCommit(opts localGitAddCommitOptions) func(*testing.T
181227 doGitCheckoutBranch (opts .LocalRepoPath , opts .CheckoutBranch )(t )
182228 localFilePath := filepath .Join (opts .LocalRepoPath , opts .TreeFilePath )
183229 require .NoError (t , os .WriteFile (localFilePath , []byte (opts .TreeFileContent ), 0o644 ))
184- require .NoError (t , git . AddChanges (t .Context (), opts .LocalRepoPath , true ))
230+ require .NoError (t , gitAddChangesDeprecated (t .Context (), opts .LocalRepoPath , true ))
185231 signature := git.Signature {
186232 Email : "test@test.test" ,
187233 Name : "test" ,
188234 }
189- require .NoError (t , git . CommitChanges (t .Context (), opts .LocalRepoPath , git. CommitChangesOptions {
235+ require .NoError (t , gitCommitChangesDeprecated (t .Context (), opts .LocalRepoPath , gitCommitChangesOptions {
190236 Committer : & signature ,
191237 Author : & signature ,
192238 Message : fmt .Sprintf ("update %s @ %s" , opts .TreeFilePath , opts .CheckoutBranch ),
0 commit comments