|
|
@@ -45,6 +45,7 @@ package org.eclipse.jgit.api; |
|
|
|
import java.io.File; |
|
|
|
import java.io.FileWriter; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.PrintWriter; |
|
|
|
|
|
|
|
import org.eclipse.jgit.errors.UnmergedPathException; |
|
|
|
import org.eclipse.jgit.lib.Constants; |
|
|
@@ -53,6 +54,7 @@ import org.eclipse.jgit.lib.PersonIdent; |
|
|
|
import org.eclipse.jgit.lib.RefUpdate; |
|
|
|
import org.eclipse.jgit.lib.RepositoryTestCase; |
|
|
|
import org.eclipse.jgit.revwalk.RevCommit; |
|
|
|
import org.eclipse.jgit.treewalk.TreeWalk; |
|
|
|
|
|
|
|
public class CommitAndLogCommandTests extends RepositoryTestCase { |
|
|
|
public void testSomeCommits() throws NoHeadException, NoMessageException, |
|
|
@@ -151,4 +153,36 @@ public class CommitAndLogCommandTests extends RepositoryTestCase { |
|
|
|
assertEquals(parents[1], second); |
|
|
|
assertTrue(parents.length==2); |
|
|
|
} |
|
|
|
|
|
|
|
public void testAddUnstagedChanges() throws IOException, NoHeadException, |
|
|
|
NoMessageException, ConcurrentRefUpdateException, |
|
|
|
JGitInternalException, WrongRepositoryStateException, |
|
|
|
NoFilepatternException { |
|
|
|
File file = new File(db.getWorkTree(), "a.txt"); |
|
|
|
file.createNewFile(); |
|
|
|
PrintWriter writer = new PrintWriter(file); |
|
|
|
writer.print("content"); |
|
|
|
writer.close(); |
|
|
|
|
|
|
|
Git git = new Git(db); |
|
|
|
git.add().addFilepattern("a.txt").call(); |
|
|
|
RevCommit commit = git.commit().setMessage("initial commit").call(); |
|
|
|
TreeWalk tw = TreeWalk.forPath(db, "a.txt", commit.getTree()); |
|
|
|
assertEquals("6b584e8ece562ebffc15d38808cd6b98fc3d97ea", |
|
|
|
tw.getObjectId(0).getName()); |
|
|
|
|
|
|
|
writer = new PrintWriter(file); |
|
|
|
writer.print("content2"); |
|
|
|
writer.close(); |
|
|
|
commit = git.commit().setMessage("second commit").call(); |
|
|
|
tw = TreeWalk.forPath(db, "a.txt", commit.getTree()); |
|
|
|
assertEquals("6b584e8ece562ebffc15d38808cd6b98fc3d97ea", |
|
|
|
tw.getObjectId(0).getName()); |
|
|
|
|
|
|
|
commit = git.commit().setAll(true).setMessage("third commit") |
|
|
|
.setAll(true).call(); |
|
|
|
tw = TreeWalk.forPath(db, "a.txt", commit.getTree()); |
|
|
|
assertEquals("db00fd65b218578127ea51f3dffac701f12f486a", |
|
|
|
tw.getObjectId(0).getName()); |
|
|
|
} |
|
|
|
} |