@ -1,5 +1,5 @@
/ *
/ *
* Copyright ( C ) 2012 , 2013 François Rey < eclipse . org_ @_francois_._rey_._name >
* Copyright ( C ) 2012 , 2015 François Rey < eclipse . org_ @_francois_._rey_._name >
* and other copyright owners as documented in the project ' s IP log .
* and other copyright owners as documented in the project ' s IP log .
*
*
* This program and the accompanying materials are made available
* This program and the accompanying materials are made available
@ -43,17 +43,144 @@
package org.eclipse.jgit.pgm ;
package org.eclipse.jgit.pgm ;
import java.io.IOException ;
import org.eclipse.jgit.api.Git ;
import org.eclipse.jgit.api.Git ;
import org.eclipse.jgit.api.errors.GitAPIException ;
import org.eclipse.jgit.lib.CLIRepositoryTestCase ;
import org.eclipse.jgit.lib.CLIRepositoryTestCase ;
import org.eclipse.jgit.lib.Constants ;
import org.eclipse.jgit.lib.Constants ;
import org.eclipse.jgit.revwalk.RevCommit ;
import org.eclipse.jgit.revwalk.RevCommit ;
import org.junit.Test ;
import org.junit.Test ;
public class StatusTest extends CLIRepositoryTestCase {
public class StatusTest extends CLIRepositoryTestCase {
@Test
public void testStatusDefault ( ) throws Exception {
executeTest ( "git status" , false , true ) ;
}
@Test
public void testStatusU ( ) throws Exception {
executeTest ( "git status -u" , false , true ) ;
}
@Test
public void testStatusUno ( ) throws Exception {
executeTest ( "git status -uno" , false , false ) ;
}
@Test
public void testStatusUall ( ) throws Exception {
executeTest ( "git status -uall" , false , true ) ;
}
@Test
public void testStatusUntrackedFiles ( ) throws Exception {
executeTest ( "git status --untracked-files" , false , true ) ;
}
@Test
public void testStatusUntrackedFilesNo ( ) throws Exception {
executeTest ( "git status --untracked-files=no" , false , false ) ;
}
@Test
public void testStatusUntrackedFilesAll ( ) throws Exception {
executeTest ( "git status --untracked-files=all" , false , true ) ;
}
@Test
public void testStatusPorcelain ( ) throws Exception {
executeTest ( "git status --porcelain" , true , true ) ;
}
@Test
public void testStatusPorcelainU ( ) throws Exception {
executeTest ( "git status --porcelain -u" , true , true ) ;
}
@Test
public void testStatusPorcelainUno ( ) throws Exception {
executeTest ( "git status --porcelain -uno" , true , false ) ;
}
@Test
@Test
public void testStatus ( ) throws Exception {
public void testStatusPorcelainUall ( ) throws Exception {
executeTest ( "git status --porcelain -uall" , true , true ) ;
}
@Test
public void testStatusPorcelainUntrackedFiles ( ) throws Exception {
executeTest ( "git status --porcelain --untracked-files" , true , true ) ;
}
@Test
public void testStatusPorcelainUntrackedFilesNo ( ) throws Exception {
executeTest ( "git status --porcelain --untracked-files=no" , true , false ) ;
}
@Test
public void testStatusPorcelainUntrackedFilesAll ( ) throws Exception {
executeTest ( "git status --porcelain --untracked-files=all" , true , true ) ;
}
/ * *
* Executes the test sequence .
*
* @param command
* full git command and parameters to be used
* @param porcelain
* indicates that porcelain format is expected in the output
* @param untrackedFiles
* indicates that untracked files are expected in the output
*
* @throws Exception
* if error during test execution
* /
private void executeTest ( String command , boolean porcelain ,
boolean untrackedFiles ) throws Exception {
Git git = new Git ( db ) ;
Git git = new Git ( db ) ;
// Write all files
// Write all files
writeAllFiles ( ) ;
// Test untracked
assertUntrackedFiles ( command , porcelain , untrackedFiles ) ;
// Add to index
addFilesToIndex ( git ) ;
// Test staged count
assertStagedFiles ( command , porcelain , untrackedFiles ) ;
// Commit
makeInitialCommit ( git ) ;
assertAfterInitialCommit ( command , porcelain , untrackedFiles ) ;
// Make some changes and stage them
makeSomeChangesAndStageThem ( git ) ;
// Test staged/not-staged status
assertStagedStatus ( command , porcelain , untrackedFiles ) ;
// Create unmerged file
createUnmergedFile ( git ) ;
// Commit pending changes
commitPendingChanges ( git ) ;
assertUntracked ( command , porcelain , untrackedFiles , "master" ) ;
// Checkout new branch
checkoutTestBranch ( git ) ;
// Test branch status
assertUntracked ( command , porcelain , untrackedFiles , "test" ) ;
// Commit change and checkout master again
RevCommit testBranch = commitChangesInTestBranch ( git ) ;
assertUntracked ( command , porcelain , untrackedFiles , "test" ) ;
checkoutMasterBranch ( git ) ;
// Change the same file and commit
changeUnmergedFileAndCommit ( git ) ;
assertUntracked ( command , porcelain , untrackedFiles , "master" ) ;
// Merge test branch into master
mergeTestBranchInMaster ( git , testBranch ) ;
// Test unmerged status
assertUntrackedAndUnmerged ( command , porcelain , untrackedFiles , "master" ) ;
// Test detached head
detachHead ( git ) ;
assertUntrackedAndUnmerged ( command , porcelain , untrackedFiles , null ) ;
}
private void writeAllFiles ( ) throws IOException {
writeTrashFile ( "tracked" , "tracked" ) ;
writeTrashFile ( "tracked" , "tracked" ) ;
writeTrashFile ( "stagedNew" , "stagedNew" ) ;
writeTrashFile ( "stagedNew" , "stagedNew" ) ;
writeTrashFile ( "stagedModified" , "stagedModified" ) ;
writeTrashFile ( "stagedModified" , "stagedModified" ) ;
@ -61,55 +188,22 @@ public class StatusTest extends CLIRepositoryTestCase {
writeTrashFile ( "trackedModified" , "trackedModified" ) ;
writeTrashFile ( "trackedModified" , "trackedModified" ) ;
writeTrashFile ( "trackedDeleted" , "trackedDeleted" ) ;
writeTrashFile ( "trackedDeleted" , "trackedDeleted" ) ;
writeTrashFile ( "untracked" , "untracked" ) ;
writeTrashFile ( "untracked" , "untracked" ) ;
// Test untracked
}
assertArrayOfLinesEquals ( new String [ ] { // git status output
"On branch master" , //
private void addFilesToIndex ( Git git ) throws GitAPIException {
"Untracked files:" , //
"" , //
"\tstagedDeleted" , //
"\tstagedModified" , //
"\tstagedNew" , //
"\ttracked" , //
"\ttrackedDeleted" , //
"\ttrackedModified" , //
"\tuntracked" , //
"" //
} , execute ( "git status" ) ) ; //
// Add to index
git . add ( ) . addFilepattern ( "tracked" ) . call ( ) ;
git . add ( ) . addFilepattern ( "tracked" ) . call ( ) ;
git . add ( ) . addFilepattern ( "stagedModified" ) . call ( ) ;
git . add ( ) . addFilepattern ( "stagedModified" ) . call ( ) ;
git . add ( ) . addFilepattern ( "stagedDeleted" ) . call ( ) ;
git . add ( ) . addFilepattern ( "stagedDeleted" ) . call ( ) ;
git . add ( ) . addFilepattern ( "trackedModified" ) . call ( ) ;
git . add ( ) . addFilepattern ( "trackedModified" ) . call ( ) ;
git . add ( ) . addFilepattern ( "trackedDeleted" ) . call ( ) ;
git . add ( ) . addFilepattern ( "trackedDeleted" ) . call ( ) ;
// Test staged count
}
assertArrayOfLinesEquals ( new String [ ] { // git status output
"On branch master" , //
private void makeInitialCommit ( Git git ) throws GitAPIException {
"Changes to be committed:" , //
git . commit ( ) . setMessage ( "initial commit" ) . call ( ) ;
"" , //
}
"\tnew file: stagedDeleted" , //
"\tnew file: stagedModified" , //
private void makeSomeChangesAndStageThem ( Git git ) throws IOException ,
"\tnew file: tracked" , //
GitAPIException {
"\tnew file: trackedDeleted" , //
"\tnew file: trackedModified" , //
"" , //
"Untracked files:" , //
"" , //
"\tstagedNew" , //
"\tuntracked" , //
"" //
} , execute ( "git status" ) ) ; //
// Commit
git . commit ( ) . setMessage ( "initial commit" )
. call ( ) ;
assertArrayOfLinesEquals ( new String [ ] { // git status output
"On branch master" , //
"Untracked files:" , //
"" , //
"\tstagedNew" , //
"\tuntracked" , //
"" //
} , execute ( "git status" ) ) ; //
// Make some changes and stage them
writeTrashFile ( "stagedModified" , "stagedModified modified" ) ;
writeTrashFile ( "stagedModified" , "stagedModified modified" ) ;
deleteTrashFile ( "stagedDeleted" ) ;
deleteTrashFile ( "stagedDeleted" ) ;
writeTrashFile ( "trackedModified" , "trackedModified modified" ) ;
writeTrashFile ( "trackedModified" , "trackedModified modified" ) ;
@ -117,116 +211,60 @@ public class StatusTest extends CLIRepositoryTestCase {
git . add ( ) . addFilepattern ( "stagedModified" ) . call ( ) ;
git . add ( ) . addFilepattern ( "stagedModified" ) . call ( ) ;
git . rm ( ) . addFilepattern ( "stagedDeleted" ) . call ( ) ;
git . rm ( ) . addFilepattern ( "stagedDeleted" ) . call ( ) ;
git . add ( ) . addFilepattern ( "stagedNew" ) . call ( ) ;
git . add ( ) . addFilepattern ( "stagedNew" ) . call ( ) ;
// Test staged/not-staged status
}
assertArrayOfLinesEquals ( new String [ ] { // git status output
"On branch master" , //
private void createUnmergedFile ( Git git ) throws IOException ,
"Changes to be committed:" , //
GitAPIException {
"" , //
"\tdeleted: stagedDeleted" , //
"\tmodified: stagedModified" , //
"\tnew file: stagedNew" , //
"" , //
"Changes not staged for commit:" , //
"" , //
"\tdeleted: trackedDeleted" , //
"\tmodified: trackedModified" , //
"" , //
"Untracked files:" , //
"" , //
"\tuntracked" , //
"" //
} , execute ( "git status" ) ) ; //
// Create unmerged file
writeTrashFile ( "unmerged" , "unmerged" ) ;
writeTrashFile ( "unmerged" , "unmerged" ) ;
git . add ( ) . addFilepattern ( "unmerged" ) . call ( ) ;
git . add ( ) . addFilepattern ( "unmerged" ) . call ( ) ;
// Commit pending changes
}
private void commitPendingChanges ( Git git ) throws GitAPIException {
git . add ( ) . addFilepattern ( "trackedModified" ) . call ( ) ;
git . add ( ) . addFilepattern ( "trackedModified" ) . call ( ) ;
git . rm ( ) . addFilepattern ( "trackedDeleted" ) . call ( ) ;
git . rm ( ) . addFilepattern ( "trackedDeleted" ) . call ( ) ;
git . commit ( ) . setMessage ( "commit before branching" ) . call ( ) ;
git . commit ( ) . setMessage ( "commit before branching" ) . call ( ) ;
assertArrayOfLinesEquals ( new String [ ] { // git status output
}
"On branch master" , //
"Untracked files:" , //
private void checkoutTestBranch ( Git git ) throws GitAPIException {
"" , //
"\tuntracked" , //
"" //
} , execute ( "git status" ) ) ; //
// Checkout new branch
git . checkout ( ) . setCreateBranch ( true ) . setName ( "test" ) . call ( ) ;
git . checkout ( ) . setCreateBranch ( true ) . setName ( "test" ) . call ( ) ;
// Test branch status
}
assertArrayOfLinesEquals ( new String [ ] { // git status output
"On branch test" , //
private RevCommit commitChangesInTestBranch ( Git git ) throws IOException ,
"Untracked files:" , //
GitAPIException {
"" , //
"\tuntracked" , //
"" //
} , execute ( "git status" ) ) ; //
// Commit change and checkout master again
writeTrashFile ( "unmerged" , "changed in test branch" ) ;
writeTrashFile ( "unmerged" , "changed in test branch" ) ;
git . add ( ) . addFilepattern ( "unmerged" ) . call ( ) ;
git . add ( ) . addFilepattern ( "unmerged" ) . call ( ) ;
RevCommit testBranch = git . commit ( )
return git . commit ( )
. setMessage ( "changed unmerged in test branch" ) . call ( ) ;
. setMessage ( "changed unmerged in test branch" ) . call ( ) ;
assertArrayOfLinesEquals ( new String [ ] { // git status output
}
"On branch test" , //
"Untracked files:" , //
private void checkoutMasterBranch ( Git git ) throws GitAPIException {
"" , //
"\tuntracked" , //
"" //
} , execute ( "git status" ) ) ; //
git . checkout ( ) . setName ( "master" ) . call ( ) ;
git . checkout ( ) . setName ( "master" ) . call ( ) ;
// Change the same file and commit
}
private void changeUnmergedFileAndCommit ( Git git ) throws IOException ,
GitAPIException {
writeTrashFile ( "unmerged" , "changed in master branch" ) ;
writeTrashFile ( "unmerged" , "changed in master branch" ) ;
git . add ( ) . addFilepattern ( "unmerged" ) . call ( ) ;
git . add ( ) . addFilepattern ( "unmerged" ) . call ( ) ;
git . commit ( ) . setMessage ( "changed unmerged in master branch" ) . call ( ) ;
git . commit ( ) . setMessage ( "changed unmerged in master branch" ) . call ( ) ;
assertArrayOfLinesEquals ( new String [ ] { // git status output
}
"On branch master" , //
"Untracked files:" , //
private void mergeTestBranchInMaster ( Git git , RevCommit aCommit )
"" , //
throws GitAPIException {
"\tuntracked" , //
git . merge ( ) . include ( aCommit . getId ( ) ) . call ( ) ;
"" //
}
} , execute ( "git status" ) ) ; //
// Merge test branch into master
private void detachHead ( Git git ) throws IOException , GitAPIException {
git . merge ( ) . include ( testBranch . getId ( ) ) . call ( ) ;
// Test unmerged status
assertArrayOfLinesEquals ( new String [ ] { // git status output
"On branch master" , //
"Unmerged paths:" , //
"" , //
"\tboth modified: unmerged" , //
"" , //
"Untracked files:" , //
"" , //
"\tuntracked" , //
"" //
} , execute ( "git status" ) ) ; //
// Test detached head
String commitId = db . getRef ( Constants . MASTER ) . getObjectId ( ) . name ( ) ;
String commitId = db . getRef ( Constants . MASTER ) . getObjectId ( ) . name ( ) ;
git . checkout ( ) . setName ( commitId ) . call ( ) ;
git . checkout ( ) . setName ( commitId ) . call ( ) ;
assertArrayOfLinesEquals ( new String [ ] { // git status output
"Not currently on any branch." , //
"Unmerged paths:" , //
"" , //
"\tboth modified: unmerged" , //
"" , //
"Untracked files:" , //
"" , //
"\tuntracked" , //
"" //
} , execute ( "git status" ) ) ; //
}
}
@Test
private void assertUntrackedFiles ( String command , boolean porcelain ,
public void testStatusPorcelain ( ) throws Exception {
boolean untrackedFiles ) throws Exception {
Git git = new Git ( db ) ;
String [ ] output = new String [ 0 ] ;
// Write all files
writeTrashFile ( "tracked" , "tracked" ) ;
if ( porcelain ) {
writeTrashFile ( "stagedNew" , "stagedNew" ) ;
if ( untrackedFiles ) {
writeTrashFile ( "stagedModified" , "stagedModified" ) ;
output = new String [ ] { //
writeTrashFile ( "stagedDeleted" , "stagedDeleted" ) ;
writeTrashFile ( "trackedModified" , "trackedModified" ) ;
writeTrashFile ( "trackedDeleted" , "trackedDeleted" ) ;
writeTrashFile ( "untracked" , "untracked" ) ;
// Test untracked
assertArrayOfLinesEquals ( new String [ ] { // git status output
"?? stagedDeleted" , //
"?? stagedDeleted" , //
"?? stagedModified" , //
"?? stagedModified" , //
"?? stagedNew" , //
"?? stagedNew" , //
@ -235,15 +273,45 @@ public class StatusTest extends CLIRepositoryTestCase {
"?? trackedModified" , //
"?? trackedModified" , //
"?? untracked" , //
"?? untracked" , //
"" //
"" //
} , execute ( "git status --porcelain" ) ) ; //
} ;
// Add to index
} else {
git . add ( ) . addFilepattern ( "tracked" ) . call ( ) ;
output = new String [ ] { //
git . add ( ) . addFilepattern ( "stagedModified" ) . call ( ) ;
"" //
git . add ( ) . addFilepattern ( "stagedDeleted" ) . call ( ) ;
} ;
git . add ( ) . addFilepattern ( "trackedModified" ) . call ( ) ;
}
git . add ( ) . addFilepattern ( "trackedDeleted" ) . call ( ) ;
} else {
// Test staged count
if ( untrackedFiles ) {
assertArrayOfLinesEquals ( new String [ ] { // git status output
output = new String [ ] { //
"On branch master" , //
"Untracked files:" , //
"" , //
"\tstagedDeleted" , //
"\tstagedModified" , //
"\tstagedNew" , //
"\ttracked" , //
"\ttrackedDeleted" , //
"\ttrackedModified" , //
"\tuntracked" , //
"" //
} ;
} else {
output = new String [ ] { //
"On branch master" , //
"" //
} ;
}
}
assertArrayOfLinesEquals ( output , execute ( command ) ) ;
}
private void assertStagedFiles ( String command , boolean porcelain ,
boolean untrackedFiles ) throws Exception {
String [ ] output = new String [ 0 ] ;
if ( porcelain ) {
if ( untrackedFiles ) {
output = new String [ ] { //
"A stagedDeleted" , //
"A stagedDeleted" , //
"A stagedModified" , //
"A stagedModified" , //
"A tracked" , //
"A tracked" , //
@ -252,24 +320,97 @@ public class StatusTest extends CLIRepositoryTestCase {
"?? stagedNew" , //
"?? stagedNew" , //
"?? untracked" , //
"?? untracked" , //
"" //
"" //
} , execute ( "git status --porcelain" ) ) ; //
} ;
// Commit
} else {
git . commit ( ) . setMessage ( "initial commit" ) . call ( ) ;
output = new String [ ] { //
assertArrayOfLinesEquals ( new String [ ] { // git status output
"A stagedDeleted" , //
"A stagedModified" , //
"A tracked" , //
"A trackedDeleted" , //
"A trackedModified" , //
"" //
} ;
}
} else {
if ( untrackedFiles ) {
output = new String [ ] { //
"On branch master" , //
"Changes to be committed:" , //
"" , //
"\tnew file: stagedDeleted" , //
"\tnew file: stagedModified" , //
"\tnew file: tracked" , //
"\tnew file: trackedDeleted" , //
"\tnew file: trackedModified" , //
"" , //
"Untracked files:" , //
"" , //
"\tstagedNew" , //
"\tuntracked" , //
"" //
} ;
} else {
output = new String [ ] { //
"On branch master" , //
"Changes to be committed:" , //
"" , //
"\tnew file: stagedDeleted" , //
"\tnew file: stagedModified" , //
"\tnew file: tracked" , //
"\tnew file: trackedDeleted" , //
"\tnew file: trackedModified" , //
"" //
} ;
}
}
assertArrayOfLinesEquals ( output , execute ( command ) ) ;
}
private void assertAfterInitialCommit ( String command , boolean porcelain ,
boolean untrackedFiles ) throws Exception {
String [ ] output = new String [ 0 ] ;
if ( porcelain ) {
if ( untrackedFiles ) {
output = new String [ ] { //
"?? stagedNew" , //
"?? stagedNew" , //
"?? untracked" , //
"?? untracked" , //
"" //
"" //
} , execute ( "git status --porcelain" ) ) ; //
} ;
// Make some changes and stage them
} else {
writeTrashFile ( "stagedModified" , "stagedModified modified" ) ;
output = new String [ ] { //
deleteTrashFile ( "stagedDeleted" ) ;
"" //
writeTrashFile ( "trackedModified" , "trackedModified modified" ) ;
} ;
deleteTrashFile ( "trackedDeleted" ) ;
}
git . add ( ) . addFilepattern ( "stagedModified" ) . call ( ) ;
} else {
git . rm ( ) . addFilepattern ( "stagedDeleted" ) . call ( ) ;
if ( untrackedFiles ) {
git . add ( ) . addFilepattern ( "stagedNew" ) . call ( ) ;
output = new String [ ] { //
// Test staged/not-staged status
"On branch master" , //
assertArrayOfLinesEquals ( new String [ ] { // git status output
"Untracked files:" , //
"" , //
"\tstagedNew" , //
"\tuntracked" , //
"" //
} ;
} else {
output = new String [ ] { //
"On branch master" , //
"" //
} ;
}
}
assertArrayOfLinesEquals ( output , execute ( command ) ) ;
}
private void assertStagedStatus ( String command , boolean porcelain ,
boolean untrackedFiles ) throws Exception {
String [ ] output = new String [ 0 ] ;
if ( porcelain ) {
if ( untrackedFiles ) {
output = new String [ ] { //
"D stagedDeleted" , //
"D stagedDeleted" , //
"M stagedModified" , //
"M stagedModified" , //
"A stagedNew" , //
"A stagedNew" , //
@ -277,58 +418,139 @@ public class StatusTest extends CLIRepositoryTestCase {
" M trackedModified" , //
" M trackedModified" , //
"?? untracked" , //
"?? untracked" , //
"" //
"" //
} , execute ( "git status --porcelain" ) ) ; //
} ;
// Create unmerged file
} else {
writeTrashFile ( "unmerged" , "unmerged" ) ;
output = new String [ ] { //
git . add ( ) . addFilepattern ( "unmerged" ) . call ( ) ;
"D stagedDeleted" , //
// Commit pending changes
"M stagedModified" , //
git . add ( ) . addFilepattern ( "trackedModified" ) . call ( ) ;
"A stagedNew" , //
git . rm ( ) . addFilepattern ( "trackedDeleted" ) . call ( ) ;
" D trackedDeleted" , //
git . commit ( ) . setMessage ( "commit before branching" ) . call ( ) ;
" M trackedModified" , //
assertArrayOfLinesEquals ( new String [ ] { // git status output
"?? untracked" , //
"" //
"" //
} , execute ( "git status --porcelain" ) ) ; //
} ;
// Checkout new branch
}
git . checkout ( ) . setCreateBranch ( true ) . setName ( "test" ) . call ( ) ;
} else {
// Test branch status
if ( untrackedFiles ) {
assertArrayOfLinesEquals ( new String [ ] { // git status output
output = new String [ ] { //
"?? untracked" , //
"On branch master" , //
"Changes to be committed:" , //
"" , //
"\tdeleted: stagedDeleted" , //
"\tmodified: stagedModified" , //
"\tnew file: stagedNew" , //
"" , //
"Changes not staged for commit:" , //
"" , //
"\tdeleted: trackedDeleted" , //
"\tmodified: trackedModified" , //
"" , //
"Untracked files:" , //
"" , //
"\tuntracked" , //
"" //
"" //
} , execute ( "git status --porcelain" ) ) ; //
} ;
// Commit change and checkout master again
} else {
writeTrashFile ( "unmerged" , "changed in test branch" ) ;
output = new String [ ] { //
git . add ( ) . addFilepattern ( "unmerged" ) . call ( ) ;
"On branch master" , //
RevCommit testBranch = git . commit ( )
"Changes to be committed:" , //
. setMessage ( "changed unmerged in test branch" ) . call ( ) ;
"" , //
assertArrayOfLinesEquals ( new String [ ] { // git status output
"\tdeleted: stagedDeleted" , //
"\tmodified: stagedModified" , //
"\tnew file: stagedNew" , //
"" , //
"Changes not staged for commit:" , //
"" , //
"\tdeleted: trackedDeleted" , //
"\tmodified: trackedModified" , //
"" , //
} ;
}
}
assertArrayOfLinesEquals ( output , execute ( command ) ) ;
}
private void assertUntracked ( String command ,
boolean porcelain ,
boolean untrackedFiles , String branch ) throws Exception {
String [ ] output = new String [ 0 ] ;
String branchHeader = "On branch " + branch ;
if ( porcelain ) {
if ( untrackedFiles ) {
output = new String [ ] { //
"?? untracked" , //
"?? untracked" , //
"" //
"" //
} , execute ( "git status --porcelain" ) ) ; //
} ;
git . checkout ( ) . setName ( "master" ) . call ( ) ;
} else {
// Change the same file and commit
output = new String [ ] { //
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 ( ) ;
} else {
// Test unmerged status
if ( untrackedFiles ) {
assertArrayOfLinesEquals ( new String [ ] { // git status output
output = new String [ ] { //
branchHeader , //
"Untracked files:" , //
"" , //
"\tuntracked" , //
"" //
} ;
} else {
output = new String [ ] { //
branchHeader , //
"" //
} ;
}
}
assertArrayOfLinesEquals ( output , execute ( command ) ) ;
}
private void assertUntrackedAndUnmerged ( String command , boolean porcelain ,
boolean untrackedFiles , String branch ) throws Exception {
String [ ] output = new String [ 0 ] ;
String branchHeader = ( branch = = null ) //
? "Not currently on any branch." //
: "On branch " + branch ;
if ( porcelain ) {
if ( untrackedFiles ) {
output = new String [ ] { //
"UU unmerged" , //
"UU unmerged" , //
"?? untracked" , //
"?? untracked" , //
"" //
"" //
} , execute ( "git status --porcelain" ) ) ; //
} ;
// Test detached head
} else {
String commitId = db . getRef ( Constants . MASTER ) . getObjectId ( ) . name ( ) ;
output = new String [ ] { //
git . checkout ( ) . setName ( commitId ) . call ( ) ;
assertArrayOfLinesEquals ( new String [ ] { // git status output
"UU unmerged" , //
"UU unmerged" , //
"?? untracked" , //
"" //
"" //
} , execute ( "git status --porcelain" ) ) ; //
} ;
}
} else {
if ( untrackedFiles ) {
output = new String [ ] { //
branchHeader , //
"Unmerged paths:" , //
"" , //
"\tboth modified: unmerged" , //
"" , //
"Untracked files:" , //
"" , //
"\tuntracked" , //
"" //
} ;
} else {
output = new String [ ] { //
branchHeader , //
"Unmerged paths:" , //
"" , //
"\tboth modified: unmerged" , //
"" //
} ;
}
}
assertArrayOfLinesEquals ( output , execute ( command ) ) ;
}
}
}
}