Skip to content

Commit 32e4bad

Browse files
committed
fixed getHeadRevCommit()
1 parent f2fd82f commit 32e4bad

File tree

2 files changed

+38
-24
lines changed

2 files changed

+38
-24
lines changed

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

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -345,12 +345,12 @@ public VCSCommit setFileContent(String branchName, String filePath, String conte
345345
Git git = getLocalGit(wc);
346346
Repository gitRepo = git.getRepository()) {
347347
String bn = getRealBranchName(branchName);
348-
348+
349349
git
350350
.pull()
351351
.setCredentialsProvider(credentials)
352352
.call();
353-
353+
354354
git
355355
.checkout()
356356
.setCreateBranch(gitRepo.exactRef("refs/heads/" + bn) == null)
@@ -485,7 +485,7 @@ public List<String> getCommitMessages(String branchName, Integer limit) {
485485

486486
Iterable<RevCommit> logs = git
487487
.log()
488-
.add(gitRepo.resolve("remotes/origin/" + getRealBranchName(branchName)))
488+
.add(gitRepo.resolve("refs/remotes/origin/" + getRealBranchName(branchName)))
489489
.setMaxCount(limit)
490490
.call();
491491

@@ -513,6 +513,7 @@ public VCSCommit removeFile(String branchName, String filePath, String commitMes
513513
Repository gitRepo = git.getRepository()) {
514514

515515
String bn = getRealBranchName(branchName);
516+
516517
git
517518
.pull()
518519
.setCredentialsProvider(credentials)
@@ -678,12 +679,8 @@ private RevCommit getHeadRevCommit (String branchName) {
678679
RevWalk rw = new RevWalk(gitRepo)) {
679680

680681
String bn = getRealBranchName(branchName);
681-
git
682-
.checkout()
683-
.setCreateBranch(gitRepo.exactRef("refs/heads/" + bn) == null)
684-
.setName(bn)
685-
.call();
686-
Ref ref = gitRepo.exactRef("refs/heads/" + bn);
682+
683+
Ref ref = gitRepo.exactRef("refs/remotes/origin/" + bn);
687684
ObjectId commitId = ref.getObjectId();
688685
return rw.parseCommit( commitId );
689686
} catch (GitAPIException e) {
@@ -763,7 +760,18 @@ public List<VCSTag> getTags() {
763760
try (IVCSLockedWorkingCopy wc = repo.getVCSLockedWorkingCopy();
764761
Git git = getLocalGit(wc);
765762
Repository gitRepo = git.getRepository();
766-
RevWalk rw = new RevWalk(gitRepo) ) {
763+
RevWalk rw = new RevWalk(gitRepo)) {
764+
git
765+
.checkout()
766+
.setCreateBranch(gitRepo.exactRef("refs/heads/" + MASTER_BRANCH_NAME) == null)
767+
.setName(MASTER_BRANCH_NAME)
768+
.call();
769+
770+
git
771+
.pull()
772+
.setCredentialsProvider(credentials)
773+
.call();
774+
767775
List<Ref> refs = git
768776
.tagList()
769777
.call();

src/test/java/org/scm4j/vcs/GitVCSTest.java

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
package org.scm4j.vcs;
22

3+
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertTrue;
5+
import static org.junit.Assert.fail;
6+
7+
import java.io.File;
8+
import java.io.IOException;
9+
import java.lang.reflect.InvocationTargetException;
10+
import java.lang.reflect.Method;
11+
import java.net.Authenticator;
12+
import java.net.InetAddress;
13+
import java.net.InetSocketAddress;
14+
import java.net.PasswordAuthentication;
15+
import java.net.Proxy;
16+
import java.net.ProxySelector;
17+
import java.net.SocketAddress;
18+
import java.net.URI;
19+
import java.net.URISyntaxException;
20+
import java.nio.charset.IllegalCharsetNameException;
21+
import java.util.List;
22+
323
import org.apache.commons.io.FileUtils;
424
import org.eclipse.jgit.api.Git;
525
import org.eclipse.jgit.api.errors.GitAPIException;
@@ -15,16 +35,6 @@
1535
import org.scm4j.vcs.api.abstracttest.VCSAbstractTest;
1636
import org.scm4j.vcs.api.workingcopy.IVCSRepositoryWorkspace;
1737

18-
import java.io.File;
19-
import java.io.IOException;
20-
import java.lang.reflect.InvocationTargetException;
21-
import java.lang.reflect.Method;
22-
import java.net.*;
23-
import java.nio.charset.IllegalCharsetNameException;
24-
import java.util.List;
25-
26-
import static org.junit.Assert.*;
27-
2838
public class GitVCSTest extends VCSAbstractTest {
2939

3040
private Repository localGitRepo;
@@ -36,10 +46,6 @@ public void setUp() throws Exception {
3646
super.setUp();
3747
Git git = GitVCSUtils.createRepository(new File(localVCSWorkspace.getHomeFolder(), repoName));
3848
localGitRepo = git.getRepository();
39-
git
40-
.commit()
41-
.setMessage("Initial commit")
42-
.call();
4349
proxySelectorBackup = ProxySelector.getDefault();
4450
ProxySelector.setDefault(null);
4551
}

0 commit comments

Comments
 (0)