summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.pgm.test/tst/org/eclipse
diff options
context:
space:
mode:
authorKaloyan Raev <kaloyan.r@zend.com>2013-10-10 23:08:14 +0300
committerMatthias Sohn <matthias.sohn@sap.com>2013-12-04 11:13:27 +0100
commit7026658ac8915bf1e0534132f7c5d4d02473490b (patch)
treee7be9ef5f27b179ac537d909223f9c33232faac1 /org.eclipse.jgit.pgm.test/tst/org/eclipse
parentf4dae204a6a2a1a85e8a90a5e89187f3415099e3 (diff)
downloadjgit-7026658ac8915bf1e0534132f7c5d4d02473490b.tar.gz
jgit-7026658ac8915bf1e0534132f7c5d4d02473490b.zip
CLI status should support --porcelain
Add support for the machine-readable output format along with the existing default long format. Bug: 419968 Change-Id: I37fe5121b4c9dbae1106b1d18e9fdc134070a9dd Signed-off-by: Kaloyan Raev <kaloyan.r@zend.com>
Diffstat (limited to 'org.eclipse.jgit.pgm.test/tst/org/eclipse')
-rw-r--r--org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/StatusTest.java118
1 files changed, 118 insertions, 0 deletions
diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/StatusTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/StatusTest.java
index 73ae598a8c..acc2be6b43 100644
--- a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/StatusTest.java
+++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/StatusTest.java
@@ -213,4 +213,122 @@ public class StatusTest extends CLIRepositoryTestCase {
"" //
}, execute("git status")); //
}
+
+ @Test
+ public void testStatusPorcelain() throws Exception {
+ Git git = new Git(db);
+ // Write all files
+ writeTrashFile("tracked", "tracked");
+ writeTrashFile("stagedNew", "stagedNew");
+ writeTrashFile("stagedModified", "stagedModified");
+ writeTrashFile("stagedDeleted", "stagedDeleted");
+ writeTrashFile("trackedModified", "trackedModified");
+ writeTrashFile("trackedDeleted", "trackedDeleted");
+ writeTrashFile("untracked", "untracked");
+ // Test untracked
+ assertArrayOfLinesEquals(new String[] { // git status output
+ "?? stagedDeleted", //
+ "?? stagedModified", //
+ "?? stagedNew", //
+ "?? tracked", //
+ "?? trackedDeleted", //
+ "?? trackedModified", //
+ "?? untracked", //
+ "" //
+ }, execute("git status --porcelain")); //
+ // Add to index
+ git.add().addFilepattern("tracked").call();
+ git.add().addFilepattern("stagedModified").call();
+ git.add().addFilepattern("stagedDeleted").call();
+ git.add().addFilepattern("trackedModified").call();
+ git.add().addFilepattern("trackedDeleted").call();
+ // Test staged count
+ assertArrayOfLinesEquals(new String[] { // git status output
+ "A stagedDeleted", //
+ "A stagedModified", //
+ "A tracked", //
+ "A trackedDeleted", //
+ "A trackedModified", //
+ "?? stagedNew", //
+ "?? untracked", //
+ "" //
+ }, execute("git status --porcelain")); //
+ // Commit
+ git.commit().setMessage("initial commit").call();
+ assertArrayOfLinesEquals(new String[] { // git status output
+ "?? stagedNew", //
+ "?? untracked", //
+ "" //
+ }, execute("git status --porcelain")); //
+ // Make some changes and stage them
+ writeTrashFile("stagedModified", "stagedModified modified");
+ deleteTrashFile("stagedDeleted");
+ writeTrashFile("trackedModified", "trackedModified modified");
+ deleteTrashFile("trackedDeleted");
+ git.add().addFilepattern("stagedModified").call();
+ git.rm().addFilepattern("stagedDeleted").call();
+ git.add().addFilepattern("stagedNew").call();
+ // Test staged/not-staged status
+ assertArrayOfLinesEquals(new String[] { // git status output
+ "D stagedDeleted", //
+ "M stagedModified", //
+ "A stagedNew", //
+ " D trackedDeleted", //
+ " M trackedModified", //
+ "?? untracked", //
+ "" //
+ }, execute("git status --porcelain")); //
+ // Create unmerged file
+ writeTrashFile("unmerged", "unmerged");
+ git.add().addFilepattern("unmerged").call();
+ // Commit pending changes
+ git.add().addFilepattern("trackedModified").call();
+ git.rm().addFilepattern("trackedDeleted").call();
+ git.commit().setMessage("commit before branching").call();
+ assertArrayOfLinesEquals(new String[] { // git status output
+ "?? untracked", //
+ "" //
+ }, execute("git status --porcelain")); //
+ // Checkout new branch
+ git.checkout().setCreateBranch(true).setName("test").call();
+ // Test branch status
+ assertArrayOfLinesEquals(new String[] { // git status output
+ "?? untracked", //
+ "" //
+ }, execute("git status --porcelain")); //
+ // Commit change and checkout master again
+ writeTrashFile("unmerged", "changed in test branch");
+ git.add().addFilepattern("unmerged").call();
+ RevCommit testBranch = git.commit()
+ .setMessage("changed unmerged in test branch").call();
+ assertArrayOfLinesEquals(new String[] { // git status output
+ "?? untracked", //
+ "" //
+ }, execute("git status --porcelain")); //
+ git.checkout().setName("master").call();
+ // Change the same file and commit
+ writeTrashFile("unmerged", "changed in master branch");
+ git.add().addFilepattern("unmerged").call();
+ git.commit().setMessage("changed unmerged in master branch").call();
+ assertArrayOfLinesEquals(new String[] { // git status output
+ "?? untracked", //
+ "" //
+ }, execute("git status --porcelain")); //
+ // Merge test branch into master
+ git.merge().include(testBranch.getId()).call();
+ // Test unmerged status
+ assertArrayOfLinesEquals(new String[] { // git status output
+ "UU unmerged", //
+ "?? untracked", //
+ "" //
+ }, execute("git status --porcelain")); //
+ // Test detached head
+ String commitId = db.getRef(Constants.MASTER).getObjectId().name();
+ git.checkout().setName(commitId).call();
+ assertArrayOfLinesEquals(new String[] { // git status output
+ "UU unmerged", //
+ "?? untracked", //
+ "" //
+ }, execute("git status --porcelain")); //
+ }
}