use of jetbrains.buildServer.buildTriggers.vcs.git.command.impl.GitRepoOperationsImpl in project teamcity-git by JetBrains.
the class GitMergeSupportTest method setUp.
@BeforeMethod
public void setUp() throws Exception {
super.setUp();
myPaths = new ServerPaths(myTempFiles.createTempDir().getAbsolutePath());
GitSupportBuilder builder = gitSupport().withServerPaths(myPaths);
myGit = builder.build();
myRepoOperations = new GitRepoOperationsImpl(builder.getPluginConfig(), builder.getTransportFactory(), r -> null, (a, b, c) -> {
});
myMergeSupport = new GitMergeSupport(myGit, builder.getCommitLoader(), builder.getRepositoryManager(), builder.getPluginConfig(), myRepoOperations);
myRoot = vcsRoot().withFetchUrl(getRemoteRepositoryDir("merge")).build();
}
use of jetbrains.buildServer.buildTriggers.vcs.git.command.impl.GitRepoOperationsImpl 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.buildTriggers.vcs.git.command.impl.GitRepoOperationsImpl 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");
});
}
use of jetbrains.buildServer.buildTriggers.vcs.git.command.impl.GitRepoOperationsImpl in project teamcity-git by JetBrains.
the class GitSupportBuilder method build.
@NotNull
public GitVcsSupport build() {
if (myPluginConfigBuilder == null && myServerPaths == null && myPluginConfig == null)
throw new IllegalStateException("Plugin config or server paths should be set");
if (myPluginConfig == null)
myPluginConfig = myPluginConfigBuilder != null ? myPluginConfigBuilder.build() : new PluginConfigImpl(myServerPaths);
if (myTransportFactory == null)
myTransportFactory = new TransportFactoryImpl(myPluginConfig, myVcsRootSSHKeyManager);
Mockery context = new Mockery();
if (myFetchCommand == null) {
if (myBeforeFetchHook == null) {
myFetchCommand = new FetchCommandImpl(myPluginConfig, myTransportFactory, new FetcherProperties(myPluginConfig), myVcsRootSSHKeyManager);
} else {
final FetchCommand originalCommand = new FetchCommandImpl(myPluginConfig, myTransportFactory, new FetcherProperties(myPluginConfig), myVcsRootSSHKeyManager);
myFetchCommand = (db, fetchURI, settings) -> {
myBeforeFetchHook.run();
originalCommand.fetch(db, fetchURI, settings);
};
}
}
MirrorManager mirrorManager = new MirrorManagerImpl(myPluginConfig, new HashCalculatorImpl(), new RemoteRepositoryUrlInvestigatorImpl());
myRepositoryManager = new RepositoryManagerImpl(myPluginConfig, mirrorManager);
final ResetCacheRegister resetCacheManager;
if (myResetCacheManager == null) {
context.setImposteriser(ClassImposteriser.INSTANCE);
resetCacheManager = context.mock(ResetCacheRegister.class);
context.checking(new Expectations() {
{
allowing(resetCacheManager).registerHandler(with(any(ResetCacheHandler.class)));
}
});
} else {
resetCacheManager = myResetCacheManager;
}
RevisionsCache revisionsCache = new RevisionsCache(myPluginConfig);
myMapFullPath = new GitMapFullPath(myPluginConfig, revisionsCache);
final GitRepoOperationsImpl gitRepoOperations = new GitRepoOperationsImpl(myPluginConfig, myTransportFactory, myVcsRootSSHKeyManager, myFetchCommand);
myCommitLoader = new CommitLoaderImpl(myRepositoryManager, gitRepoOperations, myMapFullPath, myPluginConfig);
GitResetCacheHandler resetCacheHandler = new GitResetCacheHandler(myRepositoryManager, new GcErrors());
ResetRevisionsCacheHandler resetRevisionsCacheHandler = new ResetRevisionsCacheHandler(revisionsCache);
TokenRefresher tokenRefresher = new TokenRefresher() {
@Nullable
@Override
public OAuthToken getRefreshableToken(@NotNull String vcsRootExtId, @NotNull String tokenFullId) {
return null;
}
@Nullable
@Override
public OAuthToken getRefreshableToken(@NotNull SProject project, @NotNull String tokenFullId) {
return null;
}
};
GitVcsSupport git = new GitVcsSupport(gitRepoOperations, myPluginConfig, resetCacheManager, myTransportFactory, myRepositoryManager, myMapFullPath, myCommitLoader, myVcsRootSSHKeyManager, new MockVcsOperationProgressProvider(), resetCacheHandler, resetRevisionsCacheHandler, tokenRefresher, myTestConnectionSupport);
git.addExtensions(myExtensions);
git.setExtensionHolder(myExtensionHolder);
return git;
}
use of jetbrains.buildServer.buildTriggers.vcs.git.command.impl.GitRepoOperationsImpl in project teamcity-git by JetBrains.
the class GitCommitSupportTest method setUp.
@BeforeMethod
@Override
public void setUp() throws Exception {
super.setUp();
myPaths = new ServerPaths(myTempFiles.createTempDir().getAbsolutePath());
GitSupportBuilder builder = gitSupport().withServerPaths(myPaths);
myGit = builder.build();
myCommitSupport = new GitCommitSupport(myGit, builder.getCommitLoader(), builder.getRepositoryManager(), new GitRepoOperationsImpl(builder.getPluginConfig(), builder.getTransportFactory(), r -> null, (a, b, c) -> {
}));
myRoot = vcsRoot().withFetchUrl(getRemoteRepositoryDir("merge")).build();
}
Aggregations