Skip to content
This repository has been archived by the owner on Sep 12, 2021. It is now read-only.

Commit

Permalink
Fix misleading error message when no repository is in use
Browse files Browse the repository at this point in the history
If an unrecognized command was entered while there was no repository
in use, an exception occured and its message was forwarded in response.

With this change the usual 'Unrecgnized command: ...' message is shown
as in other cases too.

See issue #62
  • Loading branch information
rherrmann committed Jan 20, 2016
1 parent d92455f commit fd63e05
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,19 @@ public void testEnterUnrecognizedCommandWithGitPrefix() {
.containsLines( line( "repo", "git foo" ), "Unrecognized command: foo", line( "repo" ) );
}

@Test
public void testEnterUnrecognizedCommandWhileNoRepositoryInUse() {
console.open( configurer.createConfigurer() );

console.enterCommandLine( "foo" );

assertThat( console )
.hasProcessedCommandLine()
.caretIsAtEnd()
.containsLines( line( "no repository", "foo" ), "Unrecognized command: foo", line( "no repository" ) );

}

@Test
public void testType() {
console.open( configurer.createConfigurer( "repo" ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,45 @@ public class GitCommandInterpreterPDETest {
@Rule public final RunInThreadRule runInThreadRule = new RunInThreadRule();
@Rule public final GitConsoleHelper configurer = new GitConsoleHelper();

private GitCommandInterpreter interpreter;
private CompositeRepositoryProvider repositoryProvider;
@Before
public void setUp() {
File gitDirectory = configurer.createRepositories( "repo" )[ 0 ];
repositoryProvider = createWithSingleChildProvider( gitDirectory );
}

@Test
public void testIsRecognizedForKnownCommand() {
GitCommandInterpreter interpreter = createInterpreter();

boolean recognized = interpreter.isRecognized( "status" );

assertThat( recognized ).isTrue();
}

@Test
public void testIsRecognizedForKnownCommandWithInvalidArguments() {
GitCommandInterpreter interpreter = createInterpreter();

boolean recognized = interpreter.isRecognized( "status", "invalid", "argument" );

assertThat( recognized ).isTrue();
}

@Test
public void testIsRecognizedForUnknownCommand() {
GitCommandInterpreter interpreter = createInterpreter();

boolean recognized = interpreter.isRecognized( "unknown" );

assertThat( recognized ).isFalse();
}

@Test
public void testIsRecognizedForUnknownCommandWhileNoRepositoryInUse() {
repositoryProvider.setCurrentRepositoryLocation( null );
GitCommandInterpreter interpreter = createInterpreter();

boolean recognized = interpreter.isRecognized( "unknown" );

assertThat( recognized ).isFalse();
Expand All @@ -48,20 +69,26 @@ public void testIsRecognizedForUnknownCommand() {
@Test
@RunInThread
public void testIsRecognizedFromBackgroundThread() {
GitCommandInterpreter interpreter = createInterpreter();

boolean recognized = interpreter.isRecognized( "status" );

assertThat( recognized ).isTrue();
}

@Test
public void testExecuteForKnownCommand() {
GitCommandInterpreter interpreter = createInterpreter();

String executionResult = interpreter.execute( "status" );

assertThat( executionResult ).isNull();
}

@Test
public void testExecuteForKnownCommandWithInvalidArguments() {
GitCommandInterpreter interpreter = createInterpreter();

String executionResult = interpreter.execute( "status", "invalid", "argument" );

assertThat( executionResult ).isNull();
Expand All @@ -70,15 +97,17 @@ public void testExecuteForKnownCommandWithInvalidArguments() {
@Test
@RunInThread
public void testExecuteFromBackgroundThread() {
GitCommandInterpreter interpreter = createInterpreter();

String executionResult = interpreter.execute( "status" );

assertThat( executionResult ).isNull();
}

@Before
public void setUp() {
File gitDirectory = configurer.createRepositories( "repo" )[ 0 ];
CompositeRepositoryProvider repositoryProvider = createWithSingleChildProvider( gitDirectory );
interpreter = new GitCommandInterpreter( mock( ConsoleOutput.class ), repositoryProvider );
private GitCommandInterpreter createInterpreter() {
ConsoleOutput consoleOutput = mock( ConsoleOutput.class );
File currentRepositoryLocation = repositoryProvider.getCurrentRepositoryLocation();
CommandExecutor commandExecutor = new CommandExecutor( consoleOutput, currentRepositoryLocation );
return new GitCommandInterpreter( commandExecutor, new CommandLineParser() );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public String execute( String... commandLine ) {

private String[] resolveAlias( String[] commandLine ) {
String[] result = commandLine.clone();
if( result.length >= 1 ) {
if( result.length >= 1 && commandExecutor.getRepositoryLocation() != null ) {
AliasConfig aliasConfig = new AliasConfig( commandExecutor.getRepositoryLocation() );
String command = aliasConfig.getCommand( commandLine[ 0 ] );
if( command != null ) {
Expand Down

0 comments on commit fd63e05

Please sign in to comment.