Skip to content

Commit 32e30cf

Browse files
committed
unnecessary getWorkspace() removed
sinceCommit and untilCommit -> startRevision and endRevision EVCSBranchExists throwing fixed
1 parent 78fb8b8 commit 32e30cf

File tree

1 file changed

+21
-25
lines changed

1 file changed

+21
-25
lines changed

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

+21-25
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.*;
@@ -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)
@@ -496,10 +497,10 @@ public List<VCSCommit> log(String branchName, int limit) {
496497
log.setMaxCount(limit);
497498
}
498499

499-
Iterable<RevCommit> logs = log.call();
500+
Iterable<RevCommit> commits = log.call();
500501

501502
List<VCSCommit> res = new ArrayList<>();
502-
for (RevCommit commit : logs) {
503+
for (RevCommit commit : commits) {
503504
res.add(getVCSCommit(commit));
504505
}
505506

@@ -549,7 +550,7 @@ private VCSCommit getVCSCommit(RevCommit revCommit) {
549550
return new VCSCommit(revCommit.getName(), revCommit.getFullMessage(), revCommit.getAuthorIdent().getName());
550551
}
551552

552-
public List<VCSCommit> getCommitsRange(String branchName, String afterCommitId, String untilCommitId) {
553+
public List<VCSCommit> getCommitsRange(String branchName, String startRevision, String endRevision) {
553554
try (IVCSLockedWorkingCopy wc = repo.getVCSLockedWorkingCopy();
554555
Git git = getLocalGit(wc);
555556
Repository gitRepo = git.getRepository()) {
@@ -558,18 +559,18 @@ public List<VCSCommit> getCommitsRange(String branchName, String afterCommitId,
558559

559560
String bn = getRealBranchName(branchName);
560561

561-
ObjectId sinceCommit = afterCommitId == null ?
562+
ObjectId startCommit = startRevision == null ?
562563
getInitialCommit(gitRepo, bn).getId() :
563-
ObjectId.fromString(afterCommitId);
564+
ObjectId.fromString(startRevision);
564565

565-
ObjectId untilCommit = untilCommitId == null ?
566+
ObjectId endCommit = endRevision == null ?
566567
gitRepo.exactRef("refs/heads/" + bn).getObjectId() :
567-
ObjectId.fromString(untilCommitId);
568+
ObjectId.fromString(endRevision);
568569

569570
Iterable<RevCommit> commits;
570571
commits = git
571572
.log()
572-
.addRange(sinceCommit, untilCommit)
573+
.addRange(startCommit, endCommit)
573574
.call();
574575

575576
List<VCSCommit> res = new ArrayList<>();
@@ -599,13 +600,8 @@ private RevCommit getInitialCommit(Repository gitRepo, String branchName) throws
599600
}
600601

601602
@Override
602-
public IVCSWorkspace getWorkspace() {
603-
return repo.getWorkspace();
604-
}
605-
606-
@Override
607-
public List<VCSCommit> getCommitsRange(String branchName, String startFromCommitId, WalkDirection direction,
608-
int limit) {
603+
public List<VCSCommit> getCommitsRange(String branchName, String startRevision, WalkDirection direction,
604+
int limit) {
609605
try (IVCSLockedWorkingCopy wc = repo.getVCSLockedWorkingCopy();
610606
Git git = getLocalGit(wc);
611607
Repository gitRepo = git.getRepository();
@@ -620,15 +616,15 @@ public List<VCSCommit> getCommitsRange(String branchName, String startFromCommit
620616
if (direction == WalkDirection.ASC) {
621617
ObjectId headCommitId = gitRepo.exactRef("refs/remotes/origin/" + bn).getObjectId();
622618
startCommit = rw.parseCommit( headCommitId );
623-
ObjectId sinceCommit = startFromCommitId == null ?
619+
ObjectId startCommitObjectId = startRevision == null ?
624620
getInitialCommit(gitRepo, bn).getId() :
625-
ObjectId.fromString(startFromCommitId);
626-
endCommit = rw.parseCommit(sinceCommit);
621+
ObjectId.fromString(startRevision);
622+
endCommit = rw.parseCommit(startCommitObjectId);
627623
} else {
628-
ObjectId sinceCommit = startFromCommitId == null ?
624+
ObjectId endCommitObjectId = startRevision == null ?
629625
gitRepo.exactRef("refs/remotes/origin/" + bn).getObjectId() :
630-
ObjectId.fromString(startFromCommitId);
631-
startCommit = rw.parseCommit( sinceCommit );
626+
ObjectId.fromString(startRevision);
627+
startCommit = rw.parseCommit( endCommitObjectId );
632628
endCommit = getInitialCommit(gitRepo, bn);
633629
}
634630

0 commit comments

Comments
 (0)