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);
}
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"));
}
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));
}
Aggregations