Skip to content

Commit be4b7a3

Browse files
committed
continue
1 parent 2f785b2 commit be4b7a3

File tree

2 files changed

+35
-21
lines changed

2 files changed

+35
-21
lines changed

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

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -326,15 +326,8 @@ void checkout(Git git, Repository gitRepo, String branchName) throws Exception {
326326
.pull()
327327
.setCredentialsProvider(credentials)
328328
.call();
329-
CheckoutCommand cmd = git
330-
.checkout();
331-
Ref ref = gitRepo.exactRef("refs/heads/" + bn);
332-
if (ref == null) {
333-
cmd = cmd
334-
.setCreateBranch(true)
335-
.setStartPoint("origin/" + bn);
336-
}
337-
cmd
329+
git
330+
.checkout()
338331
.setName(bn)
339332
.call();
340333
}
@@ -688,18 +681,22 @@ public List<VCSTag> getTags() {
688681
} catch (Exception e) {
689682
throw new RuntimeException(e);
690683
}
691-
692684
}
693685

694686
List<Ref> getTagRefs() throws Exception {
695-
return new ArrayList<>(Git
696-
.lsRemoteRepository()
697-
.setTags(true)
698-
.setHeads(false)
699-
.setRemote(repo.getRepoUrl())
700-
.setCredentialsProvider(credentials)
701-
.call());
687+
try (IVCSLockedWorkingCopy wc = repo.getVCSLockedWorkingCopy();
688+
Git git = getLocalGit(wc);
689+
Repository gitRepo = git.getRepository()) {
690+
691+
checkout(git, gitRepo, MASTER_BRANCH_NAME);
692+
693+
List<Ref> refs = git
694+
.tagList()
695+
.call();
696+
697+
return refs;
702698
}
699+
}
703700

704701
@Override
705702
public VCSTag getLastTag() {
@@ -719,11 +716,12 @@ public VCSTag getLastTag() {
719716

720717
Collections.sort(tagRefs, new Comparator<Ref>() {
721718
public int compare(Ref o1, Ref o2) {
722-
try {
719+
try (Repository gitRepo = git.getRepository();
720+
RevWalk rw = new RevWalk(gitRepo)) { // for exception rethrow test only
723721
Date d1 = rw.parseTag(o1.getObjectId()).getTaggerIdent().getWhen();
724722
Date d2 = rw.parseTag(o2.getObjectId()).getTaggerIdent().getWhen();
725723
return d1.compareTo(d2);
726-
} catch (IOException e) {
724+
} catch (Exception e) {
727725
throw new RuntimeException(e);
728726
}
729727
}
@@ -757,8 +755,8 @@ public void removeTag(String tagName) {
757755
.tagDelete()
758756
.setTags(tagName)
759757
.call();
760-
761-
push(git, null);
758+
759+
push(git, new RefSpec(":refs/tags/" + tagName));
762760

763761
} catch (GitAPIException e) {
764762
throw new EVCSException(e);

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.net.*;
2828
import java.nio.charset.IllegalCharsetNameException;
2929
import java.util.ArrayList;
30+
import java.util.Arrays;
3031
import java.util.List;
3132

3233
import static org.junit.Assert.*;
@@ -260,6 +261,21 @@ public void testGetLastTagEmptyTagRefsList() throws Exception {
260261
Mockito.doReturn(new ArrayList<Ref>()).when(git).getTagRefs();
261262
assertNull(vcs.getLastTag());
262263
}
264+
265+
@Test
266+
public void testGetLastTagSortingFailed() throws Exception {
267+
vcs.createTag(null, TAG_NAME_1, TAG_MESSAGE_1);
268+
Ref ref1 = Mockito.mock(Ref.class);
269+
Ref ref2 = Mockito.mock(Ref.class);
270+
List<Ref> refs = Arrays.asList(ref1, ref2);
271+
Mockito.doReturn(refs).when(git).getTagRefs();
272+
try {
273+
vcs.getLastTag();
274+
fail();
275+
} catch (RuntimeException e) {
276+
assertTrue(e.getCause().getCause() instanceof NullPointerException);
277+
}
278+
}
263279

264280
@Test
265281
public void testGetLastTagUnannotatedTag() throws Exception {

0 commit comments

Comments
 (0)