Skip to content

Commit ef26916

Browse files
committed
Merge branch 'master' of https://github.com/scm4j/scm4j-vcs-git
2 parents 9f6bdbd + a8642fb commit ef26916

File tree

2 files changed

+27
-31
lines changed

2 files changed

+27
-31
lines changed

src/main/java/org/scm4j/vcs/GitVCS.java

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.scm4j.vcs.api.exceptions.*;
2525
import org.scm4j.vcs.api.workingcopy.IVCSLockedWorkingCopy;
2626
import org.scm4j.vcs.api.workingcopy.IVCSRepositoryWorkspace;
27-
import org.scm4j.vcs.api.workingcopy.IVCSWorkspace;
2827

2928
import java.io.*;
3029
import java.net.*;
@@ -48,15 +47,15 @@ public GitVCS(IVCSRepositoryWorkspace repo) {
4847
this.repo = repo;
4948
}
5049

51-
public void setCredentials(CredentialsProvider credentials) {
50+
private void setCredentials(CredentialsProvider credentials) {
5251
this.credentials = credentials;
5352
}
5453

5554
private String getRealBranchName(String branchName) {
5655
return branchName == null ? MASTER_BRANCH_NAME : branchName;
5756
}
5857

59-
protected Git getLocalGit(String folder) throws Exception {
58+
Git getLocalGit(String folder) throws Exception {
6059
Repository gitRepo = new FileRepositoryBuilder()
6160
.setGitDir(new File(folder, ".git"))
6261
.build();
@@ -75,7 +74,7 @@ protected Git getLocalGit(String folder) throws Exception {
7574
return new Git(gitRepo);
7675
}
7776

78-
protected Git getLocalGit(IVCSLockedWorkingCopy wc) throws Exception {
77+
Git getLocalGit(IVCSLockedWorkingCopy wc) throws Exception {
7978
return getLocalGit(wc.getFolder().getPath());
8079
}
8180

@@ -143,7 +142,7 @@ public void createBranch(String srcBranchName, String newBranchName, String comm
143142

144143
push(git, refSpec);
145144
} catch (RefAlreadyExistsException e) {
146-
throw new EVCSBranchExists (e);
145+
throw new EVCSBranchExists(newBranchName);
147146
} catch (GitAPIException e) {
148147
throw new EVCSException(e);
149148
} catch (Exception e) {
@@ -176,7 +175,7 @@ public void deleteBranch(String branchName, String commitMessage) {
176175
}
177176

178177
private void push(Git git, RefSpec refSpec) throws GitAPIException {
179-
PushCommand cmd = git
178+
PushCommand cmd = git
180179
.push();
181180
if (refSpec != null) {
182181
cmd.setRefSpecs(refSpec);
@@ -295,7 +294,7 @@ public String getFileContent(String branchName, String fileRelativePath, String
295294
.setCredentialsProvider(credentials)
296295
.call();
297296

298-
ObjectId revisionCommitId = gitRepo.resolve(revision == null ? "refs/heads/" + getRealBranchName(branchName) : revision);
297+
ObjectId revisionCommitId = gitRepo.resolve(revision == null ? "refs/heads/" + getRealBranchName(branchName) : revision);
299298
if (revision == null && revisionCommitId == null) {
300299
throw new EVCSBranchNotFound(getRepoUrl(), getRealBranchName(branchName));
301300
}
@@ -313,7 +312,9 @@ public String getFileContent(String branchName, String fileRelativePath, String
313312
ObjectLoader loader = gitRepo.open(objectId);
314313
InputStream in = loader.openStream();
315314
String res = IOUtils.toString(in, StandardCharsets.UTF_8);
315+
316316
if (revision != null) {
317+
// need to prevent "checkout conflict with files" exception on scm4j-releaser testTagExistsOnExecute() test
317318
git
318319
.reset()
319320
.setMode(ResetType.HARD)
@@ -409,7 +410,7 @@ public VCSCommit setFileContent(String branchName, String filePath, String conte
409410
}
410411
}
411412

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 {
413414
String bn = getRealBranchName(branchName);
414415
CheckoutCommand cmd = git.checkout();
415416
git
@@ -537,10 +538,10 @@ public List<VCSCommit> log(String branchName, int limit) {
537538
log.setMaxCount(limit);
538539
}
539540

540-
Iterable<RevCommit> logs = log.call();
541+
Iterable<RevCommit> commits = log.call();
541542

542543
List<VCSCommit> res = new ArrayList<>();
543-
for (RevCommit commit : logs) {
544+
for (RevCommit commit : commits) {
544545
res.add(getVCSCommit(commit));
545546
}
546547

@@ -586,11 +587,11 @@ public VCSCommit removeFile(String branchName, String filePath, String commitMes
586587
}
587588
}
588589

589-
protected VCSCommit getVCSCommit(RevCommit revCommit) {
590+
private VCSCommit getVCSCommit(RevCommit revCommit) {
590591
return new VCSCommit(revCommit.getName(), revCommit.getFullMessage(), revCommit.getAuthorIdent().getName());
591592
}
592593

593-
public List<VCSCommit> getCommitsRange(String branchName, String afterCommitId, String untilCommitId) {
594+
public List<VCSCommit> getCommitsRange(String branchName, String startRevision, String endRevision) {
594595
try (IVCSLockedWorkingCopy wc = repo.getVCSLockedWorkingCopy();
595596
Git git = getLocalGit(wc);
596597
Repository gitRepo = git.getRepository()) {
@@ -599,18 +600,18 @@ public List<VCSCommit> getCommitsRange(String branchName, String afterCommitId,
599600

600601
String bn = getRealBranchName(branchName);
601602

602-
ObjectId sinceCommit = afterCommitId == null ?
603+
ObjectId startCommit = startRevision == null ?
603604
getInitialCommit(gitRepo, bn).getId() :
604-
ObjectId.fromString(afterCommitId);
605+
ObjectId.fromString(startRevision);
605606

606-
ObjectId untilCommit = untilCommitId == null ?
607+
ObjectId endCommit = endRevision == null ?
607608
gitRepo.exactRef("refs/heads/" + bn).getObjectId() :
608-
ObjectId.fromString(untilCommitId);
609+
ObjectId.fromString(endRevision);
609610

610611
Iterable<RevCommit> commits;
611612
commits = git
612613
.log()
613-
.addRange(sinceCommit, untilCommit)
614+
.addRange(startCommit, endCommit)
614615
.call();
615616

616617
List<VCSCommit> res = new ArrayList<>();
@@ -640,13 +641,8 @@ private RevCommit getInitialCommit(Repository gitRepo, String branchName) throws
640641
}
641642

642643
@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) {
650646
try (IVCSLockedWorkingCopy wc = repo.getVCSLockedWorkingCopy();
651647
Git git = getLocalGit(wc);
652648
Repository gitRepo = git.getRepository();
@@ -661,15 +657,15 @@ public List<VCSCommit> getCommitsRange(String branchName, String startFromCommit
661657
if (direction == WalkDirection.ASC) {
662658
ObjectId headCommitId = gitRepo.exactRef("refs/remotes/origin/" + bn).getObjectId();
663659
startCommit = rw.parseCommit( headCommitId );
664-
ObjectId sinceCommit = startFromCommitId == null ?
660+
ObjectId startCommitObjectId = startRevision == null ?
665661
getInitialCommit(gitRepo, bn).getId() :
666-
ObjectId.fromString(startFromCommitId);
667-
endCommit = rw.parseCommit(sinceCommit);
662+
ObjectId.fromString(startRevision);
663+
endCommit = rw.parseCommit(startCommitObjectId);
668664
} else {
669-
ObjectId sinceCommit = startFromCommitId == null ?
665+
ObjectId endCommitObjectId = startRevision == null ?
670666
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 );
673669
endCommit = getInitialCommit(gitRepo, bn);
674670
}
675671

version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
13.0-SNAPSHOT
1+
16.0-SNAPSHOT

0 commit comments

Comments
 (0)