import org.eclipse.jgit.api.errors.RefAlreadyExistsException;
import org.eclipse.jgit.api.errors.RefNotFoundException;
import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryTestCase;
import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.revwalk.RevTag;
import org.eclipse.jgit.transport.FetchResult;
import org.eclipse.jgit.transport.RefSpec;
import org.eclipse.jgit.transport.RemoteConfig;
assertEquals(newBranch.getTarget().getObjectId(), initialCommit.getId());
}
+ @Test
+ public void testCreateFromLightweightTag() throws Exception {
+ RefUpdate rup = db.updateRef("refs/tags/V10");
+ rup.setNewObjectId(initialCommit);
+ rup.setExpectedOldObjectId(ObjectId.zeroId());
+ rup.update();
+
+ Ref branch = git.branchCreate().setName("FromLightweightTag")
+ .setStartPoint("refs/tags/V10").call();
+ assertEquals(initialCommit.getId(), branch.getObjectId());
+
+ }
+
+ @Test
+ public void testCreateFromAnnotatetdTag() throws Exception {
+ RevTag tag = git.tag().setName("V10").setObjectId(secondCommit).call();
+ Ref branch = git.branchCreate().setName("FromAnnotatedTag")
+ .setStartPoint("refs/tags/V10").call();
+ assertFalse(tag.getId().equals(branch.getObjectId()));
+ assertEquals(secondCommit.getId(), branch.getObjectId());
+ }
+
@Test
public void testDelete() throws Exception {
createBranch(git, "ForDelete", false, "master", null);
RefNotFoundException, InvalidRefNameException {
checkCallable();
processOptions();
+ RevWalk revWalk = new RevWalk(repo);
try {
Ref refToCheck = repo.getRef(name);
boolean exists = refToCheck != null
if (startCommit != null)
baseCommit = startCommit.getShortMessage();
else {
- RevCommit commit = new RevWalk(repo).parseCommit(repo
+ RevCommit commit = revWalk.parseCommit(repo
.resolve(startPoint));
baseCommit = commit.getShortMessage();
}
else
refLogMessage = "branch: Created from branch " + baseBranch;
} else {
+ startAt = revWalk.peel(revWalk.parseAny(startAt));
if (exists)
refLogMessage = "branch: Reset start-point to tag "
+ startPointFullName;
return result;
} catch (IOException ioe) {
throw new JGitInternalException(ioe.getMessage(), ioe);
+ } finally {
+ revWalk.release();
}
}