24
24
import org .scm4j .vcs .api .exceptions .*;
25
25
import org .scm4j .vcs .api .workingcopy .IVCSLockedWorkingCopy ;
26
26
import org .scm4j .vcs .api .workingcopy .IVCSRepositoryWorkspace ;
27
- import org .scm4j .vcs .api .workingcopy .IVCSWorkspace ;
28
27
29
28
import java .io .*;
30
29
import java .net .*;
@@ -48,15 +47,15 @@ public GitVCS(IVCSRepositoryWorkspace repo) {
48
47
this .repo = repo ;
49
48
}
50
49
51
- public void setCredentials (CredentialsProvider credentials ) {
50
+ private void setCredentials (CredentialsProvider credentials ) {
52
51
this .credentials = credentials ;
53
52
}
54
53
55
54
private String getRealBranchName (String branchName ) {
56
55
return branchName == null ? MASTER_BRANCH_NAME : branchName ;
57
56
}
58
57
59
- protected Git getLocalGit (String folder ) throws Exception {
58
+ Git getLocalGit (String folder ) throws Exception {
60
59
Repository gitRepo = new FileRepositoryBuilder ()
61
60
.setGitDir (new File (folder , ".git" ))
62
61
.build ();
@@ -75,7 +74,7 @@ protected Git getLocalGit(String folder) throws Exception {
75
74
return new Git (gitRepo );
76
75
}
77
76
78
- protected Git getLocalGit (IVCSLockedWorkingCopy wc ) throws Exception {
77
+ Git getLocalGit (IVCSLockedWorkingCopy wc ) throws Exception {
79
78
return getLocalGit (wc .getFolder ().getPath ());
80
79
}
81
80
@@ -143,7 +142,7 @@ public void createBranch(String srcBranchName, String newBranchName, String comm
143
142
144
143
push (git , refSpec );
145
144
} catch (RefAlreadyExistsException e ) {
146
- throw new EVCSBranchExists ( e );
145
+ throw new EVCSBranchExists ( newBranchName );
147
146
} catch (GitAPIException e ) {
148
147
throw new EVCSException (e );
149
148
} catch (Exception e ) {
@@ -176,7 +175,7 @@ public void deleteBranch(String branchName, String commitMessage) {
176
175
}
177
176
178
177
private void push (Git git , RefSpec refSpec ) throws GitAPIException {
179
- PushCommand cmd = git
178
+ PushCommand cmd = git
180
179
.push ();
181
180
if (refSpec != null ) {
182
181
cmd .setRefSpecs (refSpec );
@@ -295,7 +294,7 @@ public String getFileContent(String branchName, String fileRelativePath, String
295
294
.setCredentialsProvider (credentials )
296
295
.call ();
297
296
298
- ObjectId revisionCommitId = gitRepo .resolve (revision == null ? "refs/heads/" + getRealBranchName (branchName ) : revision );
297
+ ObjectId revisionCommitId = gitRepo .resolve (revision == null ? "refs/heads/" + getRealBranchName (branchName ) : revision );
299
298
if (revision == null && revisionCommitId == null ) {
300
299
throw new EVCSBranchNotFound (getRepoUrl (), getRealBranchName (branchName ));
301
300
}
@@ -313,7 +312,9 @@ public String getFileContent(String branchName, String fileRelativePath, String
313
312
ObjectLoader loader = gitRepo .open (objectId );
314
313
InputStream in = loader .openStream ();
315
314
String res = IOUtils .toString (in , StandardCharsets .UTF_8 );
315
+
316
316
if (revision != null ) {
317
+ // need to prevent "checkout conflict with files" exception on scm4j-releaser testTagExistsOnExecute() test
317
318
git
318
319
.reset ()
319
320
.setMode (ResetType .HARD )
@@ -409,7 +410,7 @@ public VCSCommit setFileContent(String branchName, String filePath, String conte
409
410
}
410
411
}
411
412
412
- void checkout (Git git , Repository gitRepo , String branchName , String revision ) throws Exception {
413
+ private void checkout (Git git , Repository gitRepo , String branchName , String revision ) throws Exception {
413
414
String bn = getRealBranchName (branchName );
414
415
CheckoutCommand cmd = git .checkout ();
415
416
git
@@ -537,10 +538,10 @@ public List<VCSCommit> log(String branchName, int limit) {
537
538
log .setMaxCount (limit );
538
539
}
539
540
540
- Iterable <RevCommit > logs = log .call ();
541
+ Iterable <RevCommit > commits = log .call ();
541
542
542
543
List <VCSCommit > res = new ArrayList <>();
543
- for (RevCommit commit : logs ) {
544
+ for (RevCommit commit : commits ) {
544
545
res .add (getVCSCommit (commit ));
545
546
}
546
547
@@ -586,11 +587,11 @@ public VCSCommit removeFile(String branchName, String filePath, String commitMes
586
587
}
587
588
}
588
589
589
- protected VCSCommit getVCSCommit (RevCommit revCommit ) {
590
+ private VCSCommit getVCSCommit (RevCommit revCommit ) {
590
591
return new VCSCommit (revCommit .getName (), revCommit .getFullMessage (), revCommit .getAuthorIdent ().getName ());
591
592
}
592
593
593
- public List <VCSCommit > getCommitsRange (String branchName , String afterCommitId , String untilCommitId ) {
594
+ public List <VCSCommit > getCommitsRange (String branchName , String startRevision , String endRevision ) {
594
595
try (IVCSLockedWorkingCopy wc = repo .getVCSLockedWorkingCopy ();
595
596
Git git = getLocalGit (wc );
596
597
Repository gitRepo = git .getRepository ()) {
@@ -599,18 +600,18 @@ public List<VCSCommit> getCommitsRange(String branchName, String afterCommitId,
599
600
600
601
String bn = getRealBranchName (branchName );
601
602
602
- ObjectId sinceCommit = afterCommitId == null ?
603
+ ObjectId startCommit = startRevision == null ?
603
604
getInitialCommit (gitRepo , bn ).getId () :
604
- ObjectId .fromString (afterCommitId );
605
+ ObjectId .fromString (startRevision );
605
606
606
- ObjectId untilCommit = untilCommitId == null ?
607
+ ObjectId endCommit = endRevision == null ?
607
608
gitRepo .exactRef ("refs/heads/" + bn ).getObjectId () :
608
- ObjectId .fromString (untilCommitId );
609
+ ObjectId .fromString (endRevision );
609
610
610
611
Iterable <RevCommit > commits ;
611
612
commits = git
612
613
.log ()
613
- .addRange (sinceCommit , untilCommit )
614
+ .addRange (startCommit , endCommit )
614
615
.call ();
615
616
616
617
List <VCSCommit > res = new ArrayList <>();
@@ -640,13 +641,8 @@ private RevCommit getInitialCommit(Repository gitRepo, String branchName) throws
640
641
}
641
642
642
643
@ Override
643
- public IVCSWorkspace getWorkspace () {
644
- return repo .getWorkspace ();
645
- }
646
-
647
- @ Override
648
- public List <VCSCommit > getCommitsRange (String branchName , String startFromCommitId , WalkDirection direction ,
649
- int limit ) {
644
+ public List <VCSCommit > getCommitsRange (String branchName , String startRevision , WalkDirection direction ,
645
+ int limit ) {
650
646
try (IVCSLockedWorkingCopy wc = repo .getVCSLockedWorkingCopy ();
651
647
Git git = getLocalGit (wc );
652
648
Repository gitRepo = git .getRepository ();
@@ -661,15 +657,15 @@ public List<VCSCommit> getCommitsRange(String branchName, String startFromCommit
661
657
if (direction == WalkDirection .ASC ) {
662
658
ObjectId headCommitId = gitRepo .exactRef ("refs/remotes/origin/" + bn ).getObjectId ();
663
659
startCommit = rw .parseCommit ( headCommitId );
664
- ObjectId sinceCommit = startFromCommitId == null ?
660
+ ObjectId startCommitObjectId = startRevision == null ?
665
661
getInitialCommit (gitRepo , bn ).getId () :
666
- ObjectId .fromString (startFromCommitId );
667
- endCommit = rw .parseCommit (sinceCommit );
662
+ ObjectId .fromString (startRevision );
663
+ endCommit = rw .parseCommit (startCommitObjectId );
668
664
} else {
669
- ObjectId sinceCommit = startFromCommitId == null ?
665
+ ObjectId endCommitObjectId = startRevision == null ?
670
666
gitRepo .exactRef ("refs/remotes/origin/" + bn ).getObjectId () :
671
- ObjectId .fromString (startFromCommitId );
672
- startCommit = rw .parseCommit ( sinceCommit );
667
+ ObjectId .fromString (startRevision );
668
+ startCommit = rw .parseCommit ( endCommitObjectId );
673
669
endCommit = getInitialCommit (gitRepo , bn );
674
670
}
675
671
0 commit comments