@@ -328,6 +328,47 @@ public String getFileContent(String branchName, String fileRelativePath, String
328
328
throw new RuntimeException (e );
329
329
}
330
330
}
331
+
332
+ public VCSCommit setFilesContent (String branchName , List <String > filePathes , List <String > contents , String commitMessage ) {
333
+ try (IVCSLockedWorkingCopy wc = repo .getVCSLockedWorkingCopy ();
334
+ Git git = getLocalGit (wc );
335
+ Repository gitRepo = git .getRepository ()) {
336
+
337
+ checkout (git , gitRepo , branchName , null );
338
+ CommitCommand commitCommand = git .commit ();
339
+ int contentId = 0 ;
340
+ for (int filePathId = 0 ; filePathId <= filePathes .size (); filePathId ++) {
341
+ String filePath = filePathes .get (filePathId );
342
+ File file = new File (wc .getFolder (), filePath );
343
+ if (!file .exists ()) {
344
+ FileUtils .forceMkdir (file .getParentFile ());
345
+ file .createNewFile ();
346
+ git
347
+ .add ()
348
+ .addFilepattern (filePath )
349
+ .call ();
350
+ }
351
+
352
+ try (FileWriter fw = new FileWriter (file , false )) {
353
+ fw .write (contents .get (contentId ));
354
+ }
355
+ contentId ++;
356
+ commitCommand .setOnly (filePath );
357
+ }
358
+ RevCommit newCommit = commitCommand
359
+ .setMessage (commitMessage )
360
+ .call ();
361
+
362
+ String bn = getRealBranchName (branchName );
363
+ RefSpec refSpec = new RefSpec (bn + ":" + bn );
364
+ push (git , refSpec );
365
+ return getVCSCommit (newCommit );
366
+ } catch (GitAPIException e ) {
367
+ throw new EVCSException (e );
368
+ } catch (Exception e ) {
369
+ throw new RuntimeException (e );
370
+ }
371
+ }
331
372
332
373
@ Override
333
374
public VCSCommit setFileContent (String branchName , String filePath , String content , String commitMessage ) {
0 commit comments