@@ -331,54 +331,56 @@ public String getFileContent(String branchName, String fileRelativePath, String
331
331
throw new RuntimeException (e );
332
332
}
333
333
}
334
-
335
- public VCSCommit setFilesContent (String branchName , List <String > filePathes , List <String > contents , String commitMessage ) {
336
- if (filePathes .isEmpty ()) {
334
+
335
+ @ Override
336
+ public VCSCommit setFileContent (String branchName , List <VCSChangeListNode > vcsChangeList ) {
337
+ if (vcsChangeList .isEmpty ()) {
337
338
return null ;
338
339
}
339
340
try (IVCSLockedWorkingCopy wc = repo .getVCSLockedWorkingCopy ();
340
341
Git git = getLocalGit (wc );
341
342
Repository gitRepo = git .getRepository ()) {
342
343
343
- checkout (git , gitRepo , branchName , null );
344
- CommitCommand commitCommand = git .commit ();
345
- int contentId = 0 ;
346
- for (int filePathId = 0 ; filePathId < filePathes .size (); filePathId ++) {
347
- String filePath = filePathes .get (filePathId );
348
- File file = new File (wc .getFolder (), filePath );
349
- if (!file .exists ()) {
350
- FileUtils .forceMkdir (file .getParentFile ());
351
- file .createNewFile ();
352
- git
353
- .add ()
354
- .addFilepattern (filePath )
355
- .call ();
356
- }
357
-
358
- try (FileWriter fw = new FileWriter (file , false )) {
359
- fw .write (contents .get (contentId ));
360
- }
361
- contentId ++;
362
- commitCommand .setOnly (filePath );
344
+ checkout (git , gitRepo , branchName , null );
345
+ CommitCommand commitCommand = git .commit ();
346
+ StringBuilder commitMessageSB = new StringBuilder ();
347
+ for (VCSChangeListNode vcsChangeListNode : vcsChangeList ) {
348
+ String filePath = vcsChangeListNode .getFilePath ();
349
+ File file = new File (wc .getFolder (), filePath );
350
+ if (!file .exists ()) {
351
+ FileUtils .forceMkdir (file .getParentFile ());
352
+ file .createNewFile ();
353
+ git
354
+ .add ()
355
+ .addFilepattern (filePath )
356
+ .call ();
363
357
}
364
- RevCommit newCommit = commitCommand
365
- .setMessage (commitMessage )
366
- .call ();
367
358
368
- String bn = getRealBranchName (branchName );
369
- RefSpec refSpec = new RefSpec (bn + ":" + bn );
370
- push (git , refSpec );
371
- return getVCSCommit (newCommit );
372
- } catch (GitAPIException e ) {
373
- throw new EVCSException (e );
374
- } catch (Exception e ) {
375
- throw new RuntimeException (e );
359
+ try (FileWriter fw = new FileWriter (file , false )) {
360
+ fw .write (vcsChangeListNode .getContent ());
361
+ }
362
+ commitCommand .setOnly (filePath );
363
+ commitMessageSB .append (vcsChangeListNode .getLogMessage () + VCSChangeListNode .COMMIT_MESSAGES_SEPARATOR );
376
364
}
365
+ commitMessageSB .setLength (commitMessageSB .length () - VCSChangeListNode .COMMIT_MESSAGES_SEPARATOR .length ());
366
+ RevCommit newCommit = commitCommand
367
+ .setMessage (commitMessageSB .toString ())
368
+ .call ();
369
+
370
+ String bn = getRealBranchName (branchName );
371
+ RefSpec refSpec = new RefSpec (bn + ":" + bn );
372
+ push (git , refSpec );
373
+ return getVCSCommit (newCommit );
374
+ } catch (GitAPIException e ) {
375
+ throw new EVCSException (e );
376
+ } catch (Exception e ) {
377
+ throw new RuntimeException (e );
378
+ }
377
379
}
378
380
379
381
@ Override
380
382
public VCSCommit setFileContent (String branchName , String filePath , String content , String commitMessage ) {
381
- return setFilesContent (branchName , Collections .singletonList (filePath ), Collections . singletonList ( content ) , commitMessage );
383
+ return setFileContent (branchName , Collections .singletonList (new VCSChangeListNode ( filePath , content , commitMessage )) );
382
384
}
383
385
384
386
private void checkout (Git git , Repository gitRepo , String branchName , String revision ) throws Exception {
@@ -389,7 +391,6 @@ private void checkout(Git git, Repository gitRepo, String branchName, String rev
389
391
.setCredentialsProvider (credentials )
390
392
.call ();
391
393
if (revision == null ) {
392
-
393
394
cmd
394
395
.setStartPoint ("origin/" + bn )
395
396
.setCreateBranch (gitRepo .exactRef ("refs/heads/" + bn ) == null )
0 commit comments