use of jetbrains.buildServer.ssh.VcsRootSshKeyManager in project teamcity-git by JetBrains.
the class CollectChangesTest method fetch_should_not_fail_if_remote_repository_does_not_have_some_branches.
@Test
@TestFor(issues = "http://youtrack.jetbrains.com/issue/TW-29798#comment=27-537697")
public void fetch_should_not_fail_if_remote_repository_does_not_have_some_branches() throws Exception {
VcsRoot root = vcsRoot().withFetchUrl(myRepo).withBranch("master").withReportTags(true).build();
// setup fetcher with a counter
ServerPluginConfig config = myConfig.build();
VcsRootSshKeyManager manager = new EmptyVcsRootSshKeyManager();
FetchCommand fetchCommand = new FetchCommandImpl(config, new TransportFactoryImpl(config, manager), new FetcherProperties(config), manager);
FetchCommandCountDecorator fetchCounter = new FetchCommandCountDecorator(fetchCommand);
GitVcsSupport git = gitSupport().withPluginConfig(myConfig).withFetchCommand(fetchCounter).build();
RepositoryStateData state = git.getCurrentState(root);
// has a single branch
RepositoryStateData s1 = createVersionState("refs/heads/master", map("refs/heads/master", state.getBranchRevisions().get("refs/heads/master")));
Map<String, String> branches = new HashMap<String, String>(state.getBranchRevisions());
// unknown branch that points to a commit that exists in remote repo
branches.put("refs/heads/unknown.branch", branches.get(state.getDefaultBranchName()));
// has many branches, some of them don't exist in remote repository
RepositoryStateData s2 = createVersionState("refs/heads/master", branches);
// no failure if 'fromState' contains non-existing branch
git.getCollectChangesPolicy().collectChanges(root, s2, s1, CheckoutRules.DEFAULT);
assertEquals(fetchCounter.getFetchCount(), 1);
FileUtil.delete(config.getCachesDir());
fetchCounter.resetFetchCounter();
try {
git.getCollectChangesPolicy().collectChanges(root, s1, s2, CheckoutRules.DEFAULT);
fail("Changes collection was expected to fail because 'toState' contains non-existing branch");
} catch (VcsException e) {
// expected
}
}
use of jetbrains.buildServer.ssh.VcsRootSshKeyManager in project teamcity-git by JetBrains.
the class CollectChangesTest method ignore_missing_branch.
@TestFor(issues = "TW-38899")
@Test(dataProvider = "doFetchInSeparateProcess", dataProviderClass = FetchOptionsDataProvider.class)
public void ignore_missing_branch(boolean fetchInSeparateProcess) throws Exception {
myConfig.setSeparateProcessForFetch(fetchInSeparateProcess);
myConfig.setIgnoreMissingRemoteRef(true);
myConfig.withFetcherProperties(PluginConfigImpl.IGNORE_MISSING_REMOTE_REF, "true");
File repo = copyRepository(myTempFiles, dataFile("repo_for_fetch.2.personal"), "repo.git");
ServerPluginConfig config = myConfig.build();
VcsRootSshKeyManager manager = new EmptyVcsRootSshKeyManager();
AtomicBoolean updateRepo = new AtomicBoolean(false);
// wrapper for fetch command which will remove ref in remote repository just before fetch
FetchCommand fetchCommand = new FetchCommandImpl(config, new TransportFactoryImpl(config, manager), new FetcherProperties(config), manager) {
@Override
public void fetch(@NotNull Repository db, @NotNull URIish fetchURI, @NotNull FetchSettings settings) throws IOException, VcsException {
if (updateRepo.get()) {
FileUtil.delete(repo);
copyRepository(dataFile("repo_for_fetch.3"), repo);
}
super.fetch(db, fetchURI, settings);
}
};
GitVcsSupport git = gitSupport().withPluginConfig(myConfig).withFetchCommand(fetchCommand).build();
VcsRoot root = vcsRoot().withFetchUrl(repo).build();
RepositoryStateData s0 = createVersionState("refs/heads/master", map("refs/heads/master", "add81050184d3c818560bdd8839f50024c188586", "refs/heads/personal", "add81050184d3c818560bdd8839f50024c188586"));
RepositoryStateData s1 = createVersionState("refs/heads/master", map("refs/heads/master", "add81050184d3c818560bdd8839f50024c188586", "refs/heads/personal", "d47dda159b27b9a8c4cee4ce98e4435eb5b17168"));
// init repo on server:
git.getCollectChangesPolicy().collectChanges(root, s0, s1, CheckoutRules.DEFAULT);
RepositoryStateData s2 = createVersionState("refs/heads/master", map("refs/heads/master", "bba7fbcc200b4968e6abd2f7d475dc15306cafc6", "refs/heads/personal", "d47dda159b27b9a8c4cee4ce98e4435eb5b17168"));
// refs/heads/personal ref disappears from remote repo:
updateRepo.set(true);
// changes collecting doesn't fail
git.getCollectChangesPolicy().collectChanges(root, s1, s2, CheckoutRules.DEFAULT);
}
use of jetbrains.buildServer.ssh.VcsRootSshKeyManager in project teamcity-git by JetBrains.
the class CollectChangesTest method do_not_do_fetch_per_branch.
@TestFor(issues = "TW-29798")
public void do_not_do_fetch_per_branch() throws Exception {
VcsRoot root = vcsRoot().withFetchUrl(myRepo).withBranch("master").withReportTags(true).build();
// setup fetcher with counter
ServerPluginConfig config = myConfig.build();
VcsRootSshKeyManager manager = new EmptyVcsRootSshKeyManager();
FetchCommand fetchCommand = new FetchCommandImpl(config, new TransportFactoryImpl(config, manager), new FetcherProperties(config), manager);
FetchCommandCountDecorator fetchCounter = new FetchCommandCountDecorator(fetchCommand);
GitVcsSupport git = gitSupport().withPluginConfig(myConfig).withFetchCommand(fetchCounter).build();
RepositoryStateData state = git.getCurrentState(root);
// has a single branch
RepositoryStateData s1 = createVersionState("refs/heads/master", map("refs/heads/master", state.getBranchRevisions().get("refs/heads/master")));
// has many branches
RepositoryStateData s2 = createVersionState("refs/heads/master", state.getBranchRevisions());
git.getCollectChangesPolicy().collectChanges(root, s1, s2, CheckoutRules.DEFAULT);
assertEquals(fetchCounter.getFetchCount(), 1);
FileUtil.delete(config.getCachesDir());
fetchCounter.resetFetchCounter();
git.getCollectChangesPolicy().collectChanges(root, s2, s1, CheckoutRules.DEFAULT);
assertEquals(fetchCounter.getFetchCount(), 1);
}
use of jetbrains.buildServer.ssh.VcsRootSshKeyManager in project teamcity-git by JetBrains.
the class GitPatchProcess method main.
public static void main(String... args) throws Exception {
Map<String, String> properties = VcsUtil.stringToProperties(GitServerUtil.readInput());
GitPatchProcessSettings settings = new GitPatchProcessSettings(properties);
GitServerUtil.configureInternalProperties(settings.getInternalProperties());
GitServerUtil.configureStreamFileThreshold(Integer.MAX_VALUE);
GitServerUtil.configureExternalProcessLogger(settings.isDebugEnabled());
GitServerUtil.setupMemoryMappedIndexReading();
JSchConfigInitializer.initJSchConfig(JSch.class);
PluginConfigImpl config = new PluginConfigImpl(new ConstantCachePaths(settings.getGitCachesDir()));
RepositoryManager repositoryManager = new RepositoryManagerImpl(config, new MirrorManagerImpl(config, new HashCalculatorImpl(), new RemoteRepositoryUrlInvestigatorImpl()));
GitMapFullPath mapFullPath = new GitMapFullPath(config, new RevisionsCache(config));
VcsRootSshKeyManager sshKeyManager = new ConstantSshKeyManager(settings.getKeyBytes());
TransportFactory transportFactory = new TransportFactoryImpl(config, sshKeyManager, settings.getGitTrustStoreProvider());
FetcherProperties fetcherProperties = new FetcherProperties(config);
FetchCommand fetchCommand = new FetchCommandImpl(config, transportFactory, fetcherProperties, sshKeyManager, settings.getGitTrustStoreProvider());
GitRepoOperations repoOperations = new GitRepoOperationsImpl(config, transportFactory, sshKeyManager, fetchCommand);
CommitLoader commitLoader = new CommitLoaderImpl(repositoryManager, repoOperations, mapFullPath, config);
OperationContext context = new OperationContext(commitLoader, repositoryManager, settings.getRoot(), "build patch", GitProgress.NO_OP, config, null);
OutputStream fos = new BufferedOutputStream(new FileOutputStream(settings.getPatchFile()));
try {
PatchBuilderImpl patchBuilder = new PatchBuilderImpl(fos);
new GitPatchBuilder(context, patchBuilder, settings.getFromRevision(), settings.getToRevision(), settings.getCheckoutRules(), settings.isVerboseTreeWalkLog(), new PrintFile(), transportFactory).buildPatch();
patchBuilder.close();
} catch (Throwable t) {
if (settings.isDebugEnabled() || isImportant(t)) {
System.err.println(t.getMessage());
t.printStackTrace(System.err);
} else {
String msg = t.getMessage();
boolean printStackTrace = false;
if (t instanceof SubmoduleFetchException) {
Throwable cause = t.getCause();
printStackTrace = cause != null && isImportant(cause);
}
System.err.println(msg);
if (printStackTrace)
t.printStackTrace(System.err);
}
System.exit(1);
} finally {
fos.close();
}
}
use of jetbrains.buildServer.ssh.VcsRootSshKeyManager in project teamcity-git by JetBrains.
the class SshAuthenticationTest method do_ssh_test.
private void do_ssh_test(boolean nativeOperationsEnabled, boolean useSshAskPass, @NotNull String urlFormat, @NotNull String sshdConfig, @Nullable TeamCitySshKey tcKey, @Nullable String publicKey, @NotNull VcsRootConfigurator builder, boolean ignoreKnownHosts) throws Exception {
if (!nativeOperationsEnabled) {
JSchConfigInitializer.initJSchConfig(JSch.class);
}
final File pub_key = publicKey == null ? null : dataFile(publicKey);
ssh_test(pub_key, sshdConfig, container -> {
setInternalProperty("teamcity.git.nativeOperationsEnabled", String.valueOf(nativeOperationsEnabled));
setInternalProperty("teamcity.git.useSshAskPas", String.valueOf(useSshAskPass));
setInternalProperty("teamcity.git.debugNativeGit", "true");
final ServerPaths serverPaths = new ServerPaths(myTempFiles.createTempDir().getAbsolutePath());
final ServerPluginConfig config = new PluginConfigBuilder(serverPaths).build();
final VcsRootSshKeyManager keyManager = r -> tcKey;
final TransportFactoryImpl transportFactory = new TransportFactoryImpl(config, keyManager);
final GitRepoOperationsImpl repoOperations = new GitRepoOperationsImpl(config, transportFactory, keyManager, new FetchCommandImpl(config, transportFactory, new FetcherProperties(config), keyManager));
final MirrorManagerImpl mirrorManager = new MirrorManagerImpl(config, new HashCalculatorImpl(), new RemoteRepositoryUrlInvestigatorImpl());
final RepositoryManagerImpl repositoryManager = new RepositoryManagerImpl(config, mirrorManager);
final String repoUrl = String.format(urlFormat, container.getContainerIpAddress(), container.getMappedPort(22));
final GitVcsRoot gitRoot = new GitVcsRoot(mirrorManager, builder.config(VcsRootBuilder.vcsRoot().withFetchUrl(repoUrl).withIgnoreKnownHosts(ignoreKnownHosts)).build(), new URIishHelperImpl());
JSch.setLogger(JSchLoggers.STD_DEBUG_JSCH_LOGGER);
// here we test some git operations
final URIish fetchUrl = new URIish(repoUrl);
final Repository db = repositoryManager.openRepository(fetchUrl);
final Map<String, Ref> refs = repoOperations.lsRemoteCommand(repoUrl).lsRemote(db, gitRoot, new FetchSettings(gitRoot.getAuthSettings()));
assertContains(refs.keySet(), "refs/pull/1");
final StringBuilder progress = new StringBuilder();
final List<RefSpec> refSpecs = refs.keySet().stream().map(r -> new RefSpec().setSourceDestination(r, r).setForceUpdate(true)).collect(Collectors.toList());
repoOperations.fetchCommand(repoUrl).fetch(db, fetchUrl, new FetchSettings(gitRoot.getAuthSettings(), new GitProgress() {
@Override
public void reportProgress(@NotNull final String p) {
progress.append(p).append("\n");
}
@Override
public void reportProgress(final float p, @NotNull final String stage) {
if (p < 0) {
progress.append(stage).append("\n");
} else {
int percents = (int) Math.floor(p * 100);
progress.append(stage).append(" ").append(percents).append("%");
}
}
}, refSpecs));
if (nativeOperationsEnabled) {
assertContains(progress.toString(), "* [new ref] refs/pull/1 -> refs/pull/1");
} else {
assertContains(progress.toString(), "update ref remote name: refs/pull/1, local name: refs/pull/1, old object id: 0000000000000000000000000000000000000000, new object id: b896070465af79121c9a4eb5300ecff29453c164, result: NEW");
}
final GitVcsSupport vcsSupport = GitSupportBuilder.gitSupport().withServerPaths(serverPaths).withPluginConfig(config).withTransportFactory(transportFactory).build();
repoOperations.tagCommand(vcsSupport, repoUrl).tag(vcsSupport.createContext(gitRoot.getOriginalRoot(), "tag"), "test_tag", "b896070465af79121c9a4eb5300ecff29453c164");
assertContains(repoOperations.lsRemoteCommand(repoUrl).lsRemote(db, gitRoot, new FetchSettings(gitRoot.getAuthSettings())).keySet(), "refs/tags/test_tag");
});
}
Aggregations