import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException;
-import org.eclipse.jgit.dircache.DirCacheCheckout;
-import org.eclipse.jgit.lib.Constants;
-import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.RepositoryTestCase;
import org.eclipse.jgit.revwalk.RevCommit;
-import org.eclipse.jgit.revwalk.RevWalk;
import org.junit.Test;
/**
assertEquals("create a", history.next().getFullMessage());
assertFalse(history.hasNext());
}
-
- private void checkoutBranch(String branchName)
- throws IllegalStateException, IOException {
- RevWalk walk = new RevWalk(db);
- RevCommit head = walk.parseCommit(db.resolve(Constants.HEAD));
- RevCommit branch = walk.parseCommit(db.resolve(branchName));
- DirCacheCheckout dco = new DirCacheCheckout(db, head.getTree().getId(),
- db.lockDirCache(), branch.getTree().getId());
- dco.setFailOnConflict(true);
- dco.checkout();
- walk.release();
- // update the HEAD
- RefUpdate refUpdate = db.updateRef(Constants.HEAD);
- refUpdate.link(branchName);
- }
-
}
import static org.junit.Assert.fail;
import java.io.File;
-import java.io.IOException;
import java.util.Iterator;
import org.eclipse.jgit.api.MergeResult.MergeStatus;
import org.eclipse.jgit.api.errors.InvalidMergeHeadsException;
-import org.eclipse.jgit.dircache.DirCacheCheckout;
import org.eclipse.jgit.lib.Constants;
-import org.eclipse.jgit.lib.ObjectId;
-import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.RepositoryState;
import org.eclipse.jgit.lib.RepositoryTestCase;
import org.eclipse.jgit.merge.MergeStrategy;
import org.eclipse.jgit.revwalk.RevCommit;
-import org.eclipse.jgit.revwalk.RevWalk;
import org.junit.Test;
public class MergeCommandTest extends RepositoryTestCase {
}
}
-
@Test
public void testContentMerge() throws Exception {
Git git = new Git(db);
assertEquals(null, result.getConflicts());
assertEquals(RepositoryState.SAFE, db.getRepositoryState());
}
-
- private void createBranch(ObjectId objectId, String branchName) throws IOException {
- RefUpdate updateRef = db.updateRef(branchName);
- updateRef.setNewObjectId(objectId);
- updateRef.update();
- }
-
- private void checkoutBranch(String branchName) throws IllegalStateException, IOException {
- RevWalk walk = new RevWalk(db);
- RevCommit head = walk.parseCommit(db.resolve(Constants.HEAD));
- RevCommit branch = walk.parseCommit(db.resolve(branchName));
- DirCacheCheckout dco = new DirCacheCheckout(db,
- head.getTree().getId(), db.lockDirCache(),
- branch.getTree().getId());
- dco.setFailOnConflict(true);
- dco.checkout();
- walk.release();
- // update the HEAD
- RefUpdate refUpdate = db.updateRef(Constants.HEAD);
- refUpdate.link(branchName);
- }
}
this.git = new Git(db);
}
- private void createBranch(ObjectId objectId, String branchName)
- throws IOException {
- RefUpdate updateRef = db.updateRef(branchName);
- updateRef.setNewObjectId(objectId);
- updateRef.update();
- }
-
- private void checkoutBranch(String branchName)
- throws IllegalStateException, IOException {
- RevWalk walk = new RevWalk(db);
- RevCommit head = walk.parseCommit(db.resolve(Constants.HEAD));
- RevCommit branch = walk.parseCommit(db.resolve(branchName));
- DirCacheCheckout dco = new DirCacheCheckout(db, head.getTree().getId(),
- db.lockDirCache(), branch.getTree().getId());
- dco.setFailOnConflict(true);
- dco.checkout();
- walk.release();
- // update the HEAD
- RefUpdate refUpdate = db.updateRef(Constants.HEAD);
- refUpdate.link(branchName);
- }
-
private void checkoutCommit(RevCommit commit) throws IllegalStateException,
IOException {
RevWalk walk = new RevWalk(db);
import org.eclipse.jgit.dircache.DirCacheCheckout;
import org.eclipse.jgit.errors.CorruptObjectException;
import org.eclipse.jgit.errors.NoWorkTreeException;
-import org.eclipse.jgit.lib.RefUpdate.Result;
import org.eclipse.jgit.revwalk.RevCommit;
-import org.eclipse.jgit.revwalk.RevWalk;
import org.junit.Test;
public class DirCacheCheckoutTest extends ReadTreeTest {
assertTrue(dc.checkout());
return dc;
}
-
- private void checkoutBranch(String branchName)
- throws IllegalStateException, IOException {
- RevWalk walk = new RevWalk(db);
- RevCommit head = walk.parseCommit(db.resolve(Constants.HEAD));
- RevCommit branch = walk.parseCommit(db.resolve(branchName));
- DirCacheCheckout dco = new DirCacheCheckout(db, head.getTree(),
- db.lockDirCache(), branch.getTree());
- dco.setFailOnConflict(true);
- assertTrue(dco.checkout());
- walk.release();
- // update the HEAD
- RefUpdate refUpdate = db.updateRef(Constants.HEAD);
- assertEquals(Result.FORCED, refUpdate.link(branchName));
- }
-
}
import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.dircache.DirCacheBuilder;
+import org.eclipse.jgit.dircache.DirCacheCheckout;
import org.eclipse.jgit.dircache.DirCacheEntry;
import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.storage.file.FileRepository;
import org.eclipse.jgit.treewalk.FileTreeIterator;
import org.eclipse.jgit.util.FileUtils;
FileUtils.delete(tmp);
}
}
+
+ protected void createBranch(ObjectId objectId, String branchName)
+ throws IOException {
+ RefUpdate updateRef = db.updateRef(branchName);
+ updateRef.setNewObjectId(objectId);
+ updateRef.update();
+ }
+
+ protected void checkoutBranch(String branchName)
+ throws IllegalStateException, IOException {
+ RevWalk walk = new RevWalk(db);
+ RevCommit head = walk.parseCommit(db.resolve(Constants.HEAD));
+ RevCommit branch = walk.parseCommit(db.resolve(branchName));
+ DirCacheCheckout dco = new DirCacheCheckout(db, head.getTree().getId(),
+ db.lockDirCache(), branch.getTree().getId());
+ dco.setFailOnConflict(true);
+ dco.checkout();
+ walk.release();
+ // update the HEAD
+ RefUpdate refUpdate = db.updateRef(Constants.HEAD);
+ refUpdate.link(branchName);
+ }
}