@@ -331,14 +331,17 @@ public String getFileContent(String branchName, String fileRelativePath, String
331
331
}
332
332
333
333
public VCSCommit setFilesContent (String branchName , List <String > filePathes , List <String > contents , String commitMessage ) {
334
+ if (filePathes .isEmpty ()) {
335
+ return null ;
336
+ }
334
337
try (IVCSLockedWorkingCopy wc = repo .getVCSLockedWorkingCopy ();
335
338
Git git = getLocalGit (wc );
336
339
Repository gitRepo = git .getRepository ()) {
337
340
338
341
checkout (git , gitRepo , branchName , null );
339
342
CommitCommand commitCommand = git .commit ();
340
343
int contentId = 0 ;
341
- for (int filePathId = 0 ; filePathId <= filePathes .size (); filePathId ++) {
344
+ for (int filePathId = 0 ; filePathId < filePathes .size (); filePathId ++) {
342
345
String filePath = filePathes .get (filePathId );
343
346
File file = new File (wc .getFolder (), filePath );
344
347
if (!file .exists ()) {
@@ -373,41 +376,7 @@ public VCSCommit setFilesContent(String branchName, List<String> filePathes, Lis
373
376
374
377
@ Override
375
378
public VCSCommit setFileContent (String branchName , String filePath , String content , String commitMessage ) {
376
- try (IVCSLockedWorkingCopy wc = repo .getVCSLockedWorkingCopy ();
377
- Git git = getLocalGit (wc );
378
- Repository gitRepo = git .getRepository ()) {
379
-
380
- checkout (git , gitRepo , branchName , null );
381
-
382
- File file = new File (wc .getFolder (), filePath );
383
- if (!file .exists ()) {
384
- FileUtils .forceMkdir (file .getParentFile ());
385
- file .createNewFile ();
386
- git
387
- .add ()
388
- .addFilepattern (filePath )
389
- .call ();
390
- }
391
-
392
- try (FileWriter fw = new FileWriter (file , false )) {
393
- fw .write (content );
394
- }
395
-
396
- RevCommit newCommit = git
397
- .commit ()
398
- .setOnly (filePath )
399
- .setMessage (commitMessage )
400
- .call ();
401
-
402
- String bn = getRealBranchName (branchName );
403
- RefSpec refSpec = new RefSpec (bn + ":" + bn );
404
- push (git , refSpec );
405
- return getVCSCommit (newCommit );
406
- } catch (GitAPIException e ) {
407
- throw new EVCSException (e );
408
- } catch (Exception e ) {
409
- throw new RuntimeException (e );
410
- }
379
+ return setFilesContent (branchName , Collections .singletonList (filePath ), Collections .singletonList (content ), commitMessage );
411
380
}
412
381
413
382
private void checkout (Git git , Repository gitRepo , String branchName , String revision ) throws Exception {
0 commit comments