*/
package org.eclipse.jgit.api;
+import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
}
@Test
- public void testCloneRepository_refLogForLocalRefs()
+ public void testCloneRepositoryNoCheckout()
throws IOException, JGitInternalException, GitAPIException {
- File directory = createTempDirectory("testCloneRepository");
+ File directory = createTempDirectory("testCloneRepositoryNoCheckout");
+ CloneCommand command = Git.cloneRepository();
+ command.setDirectory(directory);
+ command.setURI(fileUri());
+ command.setNoCheckout(true);
+ try (Git git2 = command.call()) {
+ Repository clonedRepo = git2.getRepository();
+ Ref main = clonedRepo.exactRef(Constants.R_HEADS + "test");
+ assertNotNull(main);
+ ObjectId id = main.getObjectId();
+ assertNotNull(id);
+ assertNotEquals(id, ObjectId.zeroId());
+ ObjectId headId = clonedRepo.resolve(Constants.HEAD);
+ assertEquals(id, headId);
+ assertArrayEquals(new String[] { Constants.DOT_GIT },
+ directory.list());
+ }
+ }
+
+ @Test
+ public void testCloneRepositoryRefLogForLocalRefs()
+ throws IOException, JGitInternalException, GitAPIException {
+ File directory = createTempDirectory(
+ "testCloneRepositoryRefLogForLocalRefs");
CloneCommand command = Git.cloneRepository();
command.setDirectory(directory);
command.setURI(fileUri());
allRefNames(git2.branchList().setListMode(ListMode.ALL).call()));
// Same thing, but now without checkout
- directory = createTempDirectory("testCloneRepositoryWithBranch_bare");
+ directory = createTempDirectory(
+ "testCloneRepositoryWithBranch_noCheckout");
command = Git.cloneRepository();
command.setBranch("refs/heads/master");
command.setDirectory(directory);
addRepoToClose(git2.getRepository());
assertEquals(git2.getRepository().getFullBranch(), "refs/heads/master");
- assertEquals("refs/remotes/origin/master, refs/remotes/origin/test",
+ assertEquals(
+ "refs/heads/master, refs/remotes/origin/master, refs/remotes/origin/test",
allRefNames(git2.branchList().setListMode(ListMode.ALL).call()));
// Same thing, but now test with bare repo
// ignore - the VM is already shutting down
}
}
- if (!noCheckout) {
- try {
- checkout(repository, fetchResult);
- } catch (IOException ioe) {
- repository.close();
- throw new JGitInternalException(ioe.getMessage(), ioe);
- } catch (GitAPIException | RuntimeException e) {
- repository.close();
- throw e;
- }
+ try {
+ checkout(repository, fetchResult);
+ } catch (IOException ioe) {
+ repository.close();
+ throw new JGitInternalException(ioe.getMessage(), ioe);
+ } catch (GitAPIException | RuntimeException e) {
+ repository.close();
+ throw e;
}
return new Git(repository, true);
}
u.setNewObjectId(commit.getId());
u.forceUpdate();
- if (!bare) {
+ if (!bare && !noCheckout) {
DirCache dc = clonedRepo.lockDirCache();
DirCacheCheckout co = new DirCacheCheckout(clonedRepo, dc,
commit.getTree());