Search in sources :

Example 1 with ConfigFileHasChangedException

use of com.thoughtworks.go.config.exceptions.ConfigFileHasChangedException in project gocd by gocd.

the class ConfigRepository method getMergedConfig.

String getMergedConfig(String branchName, RevCommit newCommit) throws GitAPIException, IOException {
    MergeResult result = null;
    try {
        checkout(branchName);
        result = git.merge().include(newCommit).call();
    } catch (GitAPIException e) {
        LOGGER.info("[CONFIG_MERGE] Merging commit {} by user {} to branch {} at revision {} failed", newCommit.getId().getName(), newCommit.getAuthorIdent().getName(), branchName, getCurrentRevCommit().getId().getName());
        throw e;
    }
    if (!result.getMergeStatus().isSuccessful()) {
        LOGGER.info("[CONFIG_MERGE] Merging commit {} by user {} to branch {} at revision {} failed as config file has changed", newCommit.getId().getName(), newCommit.getAuthorIdent().getName(), branchName, getCurrentRevCommit().getId().getName());
        throw new ConfigFileHasChangedException();
    }
    LOGGER.info("[CONFIG_MERGE] Successfully merged commit {} by user {} to branch {}. Merge commit revision is {}", newCommit.getId().getName(), newCommit.getAuthorIdent().getName(), branchName, getCurrentRevCommit().getId().getName());
    return FileUtils.readFileToString(new File(workingDir, CRUISE_CONFIG_XML), UTF_8);
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) ConfigFileHasChangedException(com.thoughtworks.go.config.exceptions.ConfigFileHasChangedException) File(java.io.File)

Example 2 with ConfigFileHasChangedException

use of com.thoughtworks.go.config.exceptions.ConfigFileHasChangedException in project gocd by gocd.

the class GoConfigServiceTest method configShouldContainOldMD5_WhenConfigMergeFailed.

@Test
public void configShouldContainOldMD5_WhenConfigMergeFailed() {
    when(goConfigDao.loadForEditing()).thenReturn(new BasicCruiseConfig());
    when(goConfigDao.updateConfig(org.mockito.Matchers.<UpdateConfigCommand>any())).thenThrow(new ConfigFileHasChangedException());
    ConfigUpdateResponse configUpdateResponse = goConfigService.updateConfigFromUI(mock(UpdateConfigFromUI.class), "old-md5", new Username(new CaseInsensitiveString("user")), new HttpLocalizedOperationResult());
    assertThat(configUpdateResponse.wasMerged(), is(false));
    assertThat(configUpdateResponse.getCruiseConfig().getMd5(), is("old-md5"));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) ConfigFileHasChangedException(com.thoughtworks.go.config.exceptions.ConfigFileHasChangedException) ConfigUpdateResponse(com.thoughtworks.go.config.update.ConfigUpdateResponse) UpdateConfigFromUI(com.thoughtworks.go.config.update.UpdateConfigFromUI) Test(org.junit.Test)

Example 3 with ConfigFileHasChangedException

use of com.thoughtworks.go.config.exceptions.ConfigFileHasChangedException in project gocd by gocd.

the class GoConfigServiceTest method shouldReturnNotMergedInConfigUpdateResponse_WhenConfigUpdateFailed.

@Test
public void shouldReturnNotMergedInConfigUpdateResponse_WhenConfigUpdateFailed() throws Exception {
    when(goConfigDao.updateConfig(org.mockito.Matchers.<UpdateConfigCommand>any())).thenThrow(new ConfigFileHasChangedException());
    expectLoadForEditing(cruiseConfig);
    ConfigUpdateResponse configUpdateResponse = goConfigService.updateConfigFromUI(mock(UpdateConfigFromUI.class), "md5", new Username(new CaseInsensitiveString("user")), new HttpLocalizedOperationResult());
    assertThat(configUpdateResponse.wasMerged(), is(false));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) ConfigFileHasChangedException(com.thoughtworks.go.config.exceptions.ConfigFileHasChangedException) ConfigUpdateResponse(com.thoughtworks.go.config.update.ConfigUpdateResponse) UpdateConfigFromUI(com.thoughtworks.go.config.update.UpdateConfigFromUI) Test(org.junit.Test)

Aggregations

ConfigFileHasChangedException (com.thoughtworks.go.config.exceptions.ConfigFileHasChangedException)3 ConfigUpdateResponse (com.thoughtworks.go.config.update.ConfigUpdateResponse)2 UpdateConfigFromUI (com.thoughtworks.go.config.update.UpdateConfigFromUI)2 Username (com.thoughtworks.go.server.domain.Username)2 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)2 Test (org.junit.Test)2 File (java.io.File)1 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)1